diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/TableProperty.java b/fe/fe-core/src/main/java/com/starrocks/catalog/TableProperty.java index e6371c87d034f..2f1796fa4c879 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/TableProperty.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/TableProperty.java @@ -48,6 +48,7 @@ import com.starrocks.catalog.constraint.UniqueConstraint; import com.starrocks.common.Config; import com.starrocks.common.FeConstants; +import com.starrocks.common.Pair; import com.starrocks.common.io.Text; import com.starrocks.common.io.Writable; import com.starrocks.common.util.PropertyAnalyzer; @@ -376,6 +377,13 @@ public TableProperty buildPartitionTTL() { if (properties.containsKey(PropertyAnalyzer.PROPERTIES_PARTITION_TTL_NUMBER)) { partitionTTLNumber = Integer.parseInt(properties.get(PropertyAnalyzer.PROPERTIES_PARTITION_TTL_NUMBER)); } + + if (properties.containsKey(PropertyAnalyzer.PROPERTIES_PARTITION_TTL)) { + Pair ttlDuration = PropertyAnalyzer.analyzePartitionTTL(properties); + if (ttlDuration != null) { + partitionTTL = ttlDuration.second; + } + } return this; } diff --git a/fe/fe-core/src/test/java/com/starrocks/catalog/TablePropertyTest.java b/fe/fe-core/src/test/java/com/starrocks/catalog/TablePropertyTest.java index 26d021c4b1d08..83fa452d231d7 100644 --- a/fe/fe-core/src/test/java/com/starrocks/catalog/TablePropertyTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/catalog/TablePropertyTest.java @@ -18,10 +18,12 @@ package com.starrocks.catalog; import com.starrocks.common.util.PropertyAnalyzer; +import com.starrocks.common.util.TimeUtils; import com.starrocks.persist.OperationType; import org.junit.After; import org.junit.Assert; import org.junit.Test; +import org.threeten.extra.PeriodDuration; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -105,10 +107,13 @@ public void testPartitionTTLNumberSerialization() throws IOException { HashMap properties = new HashMap<>(); properties.put(PropertyAnalyzer.PROPERTIES_PARTITION_LIVE_NUMBER, "2"); + properties.put(PropertyAnalyzer.PROPERTIES_PARTITION_TTL, "1 day"); + PeriodDuration duration = TimeUtils.parseHumanReadablePeriodOrDuration("1 day"); TableProperty tableProperty = new TableProperty(properties); tableProperty.buildPartitionLiveNumber(); tableProperty.buildPartitionTTL(); Assert.assertEquals(2, tableProperty.getPartitionTTLNumber()); + Assert.assertEquals(duration, tableProperty.getPartitionTTL()); tableProperty.write(out); out.flush(); out.close(); @@ -117,13 +122,17 @@ public void testPartitionTTLNumberSerialization() throws IOException { DataInputStream in = new DataInputStream(new FileInputStream(file)); TableProperty newTableProperty = TableProperty.read(in); Assert.assertEquals(2, newTableProperty.getPartitionTTLNumber()); + Assert.assertEquals(duration, tableProperty.getPartitionTTL()); in.close(); // 3. Update again properties.put(PropertyAnalyzer.PROPERTIES_PARTITION_LIVE_NUMBER, "3"); + properties.put(PropertyAnalyzer.PROPERTIES_PARTITION_TTL, "2 day"); + duration = TimeUtils.parseHumanReadablePeriodOrDuration("2 day"); newTableProperty.modifyTableProperties(properties); newTableProperty.buildPartitionLiveNumber(); newTableProperty.buildPartitionTTL(); Assert.assertEquals(3, newTableProperty.getPartitionTTLNumber()); + Assert.assertEquals(duration, newTableProperty.getPartitionTTL()); } }