From 23a1633f8074bb244583f5899ac5a6f14c1f9ae8 Mon Sep 17 00:00:00 2001 From: Askwang <135721692+Askwang@users.noreply.github.com> Date: Thu, 31 Oct 2024 14:34:23 +0800 Subject: [PATCH 1/4] timestamp type --- .../java/org/apache/paimon/CoreOptions.java | 4 +- .../apache/paimon/io/RecordLevelExpire.java | 55 +++++++++-- .../RecordLevelExpireWithTimestampTest.java | 99 +++++++++++++++++++ 3 files changed, 149 insertions(+), 9 deletions(-) create mode 100644 paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireWithTimestampTest.java diff --git a/paimon-common/src/main/java/org/apache/paimon/CoreOptions.java b/paimon-common/src/main/java/org/apache/paimon/CoreOptions.java index 39eda336b033..2a224ab4b285 100644 --- a/paimon-common/src/main/java/org/apache/paimon/CoreOptions.java +++ b/paimon-common/src/main/java/org/apache/paimon/CoreOptions.java @@ -2922,7 +2922,9 @@ public enum TimeFieldType implements DescribedEnum { SECONDS_LONG("seconds-long", "Timestamps in seconds with BIGINT field type."), - MILLIS_LONG("millis-long", "Timestamps in milliseconds with BIGINT field type."); + MILLIS_LONG("millis-long", "Timestamps in milliseconds with BIGINT field type."), + + TIMESTAMP("timestamp", "Timestamp field type."); private final String value; private final String description; diff --git a/paimon-core/src/main/java/org/apache/paimon/io/RecordLevelExpire.java b/paimon-core/src/main/java/org/apache/paimon/io/RecordLevelExpire.java index 6a5a1f49b1ef..24ab8e298423 100644 --- a/paimon-core/src/main/java/org/apache/paimon/io/RecordLevelExpire.java +++ b/paimon-core/src/main/java/org/apache/paimon/io/RecordLevelExpire.java @@ -20,11 +20,14 @@ import org.apache.paimon.CoreOptions; import org.apache.paimon.KeyValue; +import org.apache.paimon.data.Timestamp; import org.apache.paimon.reader.RecordReader; import org.apache.paimon.types.BigIntType; import org.apache.paimon.types.DataField; import org.apache.paimon.types.IntType; +import org.apache.paimon.types.LocalZonedTimestampType; import org.apache.paimon.types.RowType; +import org.apache.paimon.types.TimestampType; import javax.annotation.Nullable; @@ -38,6 +41,7 @@ public class RecordLevelExpire { private final int timeFieldIndex; private final int expireTime; private final CoreOptions.TimeFieldType timeFieldType; + private final DataField rawDataField; @Nullable public static RecordLevelExpire create(CoreOptions options, RowType rowType) { @@ -62,12 +66,7 @@ public static RecordLevelExpire create(CoreOptions options, RowType rowType) { CoreOptions.TimeFieldType timeFieldType = options.recordLevelTimeFieldType(); DataField field = rowType.getField(timeFieldName); - if (!((timeFieldType == CoreOptions.TimeFieldType.SECONDS_INT - && field.type() instanceof IntType) - || (timeFieldType == CoreOptions.TimeFieldType.SECONDS_LONG - && field.type() instanceof BigIntType) - || (timeFieldType == CoreOptions.TimeFieldType.MILLIS_LONG - && field.type() instanceof BigIntType))) { + if (!isValidateFieldType(timeFieldType, field)) { throw new IllegalArgumentException( String.format( "The record level time field type should be one of SECONDS_INT,SECONDS_LONG or MILLIS_LONG, " @@ -75,14 +74,31 @@ public static RecordLevelExpire create(CoreOptions options, RowType rowType) { timeFieldType, field.type())); } - return new RecordLevelExpire(fieldIndex, (int) expireTime.getSeconds(), timeFieldType); + return new RecordLevelExpire( + fieldIndex, (int) expireTime.getSeconds(), timeFieldType, field); + } + + private static boolean isValidateFieldType( + CoreOptions.TimeFieldType timeFieldType, DataField field) { + return ((timeFieldType == CoreOptions.TimeFieldType.SECONDS_INT + && field.type() instanceof IntType) + || (timeFieldType == CoreOptions.TimeFieldType.SECONDS_LONG + && field.type() instanceof BigIntType) + || (timeFieldType == CoreOptions.TimeFieldType.MILLIS_LONG + && field.type() instanceof BigIntType) + || (timeFieldType == CoreOptions.TimeFieldType.TIMESTAMP + && field.type() instanceof TimestampType)); } private RecordLevelExpire( - int timeFieldIndex, int expireTime, CoreOptions.TimeFieldType timeFieldType) { + int timeFieldIndex, + int expireTime, + CoreOptions.TimeFieldType timeFieldType, + DataField rawDataField) { this.timeFieldIndex = timeFieldIndex; this.expireTime = expireTime; this.timeFieldType = timeFieldType; + this.rawDataField = rawDataField; } public FileReaderFactory wrap(FileReaderFactory readerFactory) { @@ -107,6 +123,29 @@ private RecordReader wrap(RecordReader reader) { case MILLIS_LONG: recordTime = (int) (kv.value().getLong(timeFieldIndex) / 1000); break; + case TIMESTAMP: + Timestamp timestamp; + if (rawDataField.type() instanceof TimestampType) { + TimestampType timestampType = (TimestampType) rawDataField.type(); + timestamp = + kv.value() + .getTimestamp( + timeFieldIndex, + timestampType.getPrecision()); + } else if (rawDataField.type() instanceof LocalZonedTimestampType) { + LocalZonedTimestampType timestampType = + (LocalZonedTimestampType) rawDataField.type(); + timestamp = + kv.value() + .getTimestamp( + timeFieldIndex, + timestampType.getPrecision()); + } else { + throw new UnsupportedOperationException( + "Unsupported timestamp type: " + rawDataField.type()); + } + recordTime = (int) (timestamp.getMillisecond() / 1000); + break; default: String msg = String.format( diff --git a/paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireWithTimestampTest.java b/paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireWithTimestampTest.java new file mode 100644 index 000000000000..0a64b33df19f --- /dev/null +++ b/paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireWithTimestampTest.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.paimon.table; + +import org.apache.paimon.CoreOptions; +import org.apache.paimon.catalog.Catalog; +import org.apache.paimon.catalog.CatalogContext; +import org.apache.paimon.catalog.CatalogFactory; +import org.apache.paimon.catalog.Identifier; +import org.apache.paimon.catalog.PrimaryKeyTableTestBase; +import org.apache.paimon.data.GenericRow; +import org.apache.paimon.data.Timestamp; +import org.apache.paimon.fs.Path; +import org.apache.paimon.options.Options; +import org.apache.paimon.schema.Schema; +import org.apache.paimon.types.DataTypes; +import org.apache.paimon.utils.TraceableFileIO; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.time.Duration; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +class RecordLevelExpireWithTimestampTest extends PrimaryKeyTableTestBase { + + @Override + @BeforeEach + public void beforeEachBase() throws Exception { + CatalogContext context = + CatalogContext.create( + new Path(TraceableFileIO.SCHEME + "://" + tempPath.toString())); + Catalog catalog = CatalogFactory.createCatalog(context); + Identifier identifier = new Identifier("default", "T"); + catalog.createDatabase(identifier.getDatabaseName(), true); + Schema schema = + Schema.newBuilder() + .column("pt", DataTypes.INT()) + .column("pk", DataTypes.INT()) + .column("col1", DataTypes.TIMESTAMP()) + .partitionKeys("pt") + .primaryKey("pk", "pt") + .options(tableOptions().toMap()) + .build(); + catalog.createTable(identifier, schema, true); + table = (FileStoreTable) catalog.getTable(identifier); + commitUser = UUID.randomUUID().toString(); + } + + @Override + protected Options tableOptions() { + Options options = new Options(); + options.set(CoreOptions.BUCKET, 1); + options.set(CoreOptions.RECORD_LEVEL_EXPIRE_TIME, Duration.ofSeconds(1)); + options.set(CoreOptions.RECORD_LEVEL_TIME_FIELD, "col1"); + options.set(CoreOptions.RECORD_LEVEL_TIME_FIELD_TYPE, CoreOptions.TimeFieldType.TIMESTAMP); + return options; + } + + @Test + public void test() throws Exception { + long millis = System.currentTimeMillis(); + Timestamp timestamp1 = Timestamp.fromEpochMillis(millis - 60 * 1000); + Timestamp timestamp2 = Timestamp.fromEpochMillis(millis); + Timestamp timestamp3 = Timestamp.fromEpochMillis(millis + 60 * 1000); + + // create at least two files in one bucket + writeCommit(GenericRow.of(1, 1, timestamp1), GenericRow.of(1, 2, timestamp2)); + writeCommit(GenericRow.of(1, 3, timestamp3)); + + // no compaction, can be queried + assertThat(query(new int[] {0, 1})) + .containsExactlyInAnyOrder( + GenericRow.of(1, 1), GenericRow.of(1, 2), GenericRow.of(1, 3)); + Thread.sleep(2000); + + // compact, expired + compact(1); + assertThat(query(new int[] {0, 1})).containsExactlyInAnyOrder(GenericRow.of(1, 3)); + } +} From 58cbfa52275d692ff6038c49f813156ba7f85c7b Mon Sep 17 00:00:00 2001 From: Askwang <135721692+Askwang@users.noreply.github.com> Date: Thu, 31 Oct 2024 18:13:29 +0800 Subject: [PATCH 2/4] doc --- docs/layouts/shortcodes/generated/core_configuration.html | 2 +- paimon-common/src/main/java/org/apache/paimon/CoreOptions.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/layouts/shortcodes/generated/core_configuration.html b/docs/layouts/shortcodes/generated/core_configuration.html index 84ba86124f8b..6b28ed29cae2 100644 --- a/docs/layouts/shortcodes/generated/core_configuration.html +++ b/docs/layouts/shortcodes/generated/core_configuration.html @@ -627,7 +627,7 @@
record-level.time-field-type
seconds-int

Enum

- Time field type for record level expire, it can be seconds-int,seconds-long or millis-long.

Possible values:
  • "seconds-int": Timestamps in seconds with INT field type.
  • "seconds-long": Timestamps in seconds with BIGINT field type.
  • "millis-long": Timestamps in milliseconds with BIGINT field type.
+ Time field type for record level expire, it can be seconds-int,seconds-long or millis-long.

Possible values:
  • "seconds-int": Timestamps in seconds with INT field type.
  • "seconds-long": Timestamps in seconds with BIGINT field type.
  • "millis-long": Timestamps in milliseconds with BIGINT field type.
  • "timestamp": Timestamp field type.
rowkind.field
diff --git a/paimon-common/src/main/java/org/apache/paimon/CoreOptions.java b/paimon-common/src/main/java/org/apache/paimon/CoreOptions.java index 2a224ab4b285..43d4bcd5984f 100644 --- a/paimon-common/src/main/java/org/apache/paimon/CoreOptions.java +++ b/paimon-common/src/main/java/org/apache/paimon/CoreOptions.java @@ -1351,7 +1351,7 @@ public class CoreOptions implements Serializable { .enumType(TimeFieldType.class) .defaultValue(TimeFieldType.SECONDS_INT) .withDescription( - "Time field type for record level expire, it can be seconds-int,seconds-long or millis-long."); + "Time field type for record level expire, it can be seconds-int,seconds-long, millis-long or timestamp."); public static final ConfigOption FIELDS_DEFAULT_AGG_FUNC = key(FIELDS_PREFIX + "." + DEFAULT_AGG_FUNCTION) From f39c983bfe6e44674870595094269e78d55c7dc2 Mon Sep 17 00:00:00 2001 From: Askwang <135721692+Askwang@users.noreply.github.com> Date: Thu, 31 Oct 2024 22:50:35 +0800 Subject: [PATCH 3/4] fix comments --- .../generated/core_configuration.html | 2 +- .../apache/paimon/io/RecordLevelExpire.java | 14 ++-- ...ecordLevelExpireWithTimestampBaseTest.java | 66 +++++++++++++++++++ ...RecordLevelExpireWithTimestampLTZTest.java | 58 ++++++++++++++++ .../RecordLevelExpireWithTimestampTest.java | 43 +----------- 5 files changed, 135 insertions(+), 48 deletions(-) create mode 100644 paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireWithTimestampBaseTest.java create mode 100644 paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireWithTimestampLTZTest.java diff --git a/docs/layouts/shortcodes/generated/core_configuration.html b/docs/layouts/shortcodes/generated/core_configuration.html index 6b28ed29cae2..bd30b6794dc7 100644 --- a/docs/layouts/shortcodes/generated/core_configuration.html +++ b/docs/layouts/shortcodes/generated/core_configuration.html @@ -627,7 +627,7 @@
record-level.time-field-type
seconds-int

Enum

- Time field type for record level expire, it can be seconds-int,seconds-long or millis-long.

Possible values:
  • "seconds-int": Timestamps in seconds with INT field type.
  • "seconds-long": Timestamps in seconds with BIGINT field type.
  • "millis-long": Timestamps in milliseconds with BIGINT field type.
  • "timestamp": Timestamp field type.
+ Time field type for record level expire, it can be seconds-int,seconds-long, millis-long or timestamp.

Possible values:
  • "seconds-int": Timestamps in seconds with INT field type.
  • "seconds-long": Timestamps in seconds with BIGINT field type.
  • "millis-long": Timestamps in milliseconds with BIGINT field type.
  • "timestamp": Timestamp field type.
rowkind.field
diff --git a/paimon-core/src/main/java/org/apache/paimon/io/RecordLevelExpire.java b/paimon-core/src/main/java/org/apache/paimon/io/RecordLevelExpire.java index 24ab8e298423..e548ae44c422 100644 --- a/paimon-core/src/main/java/org/apache/paimon/io/RecordLevelExpire.java +++ b/paimon-core/src/main/java/org/apache/paimon/io/RecordLevelExpire.java @@ -24,6 +24,7 @@ import org.apache.paimon.reader.RecordReader; import org.apache.paimon.types.BigIntType; import org.apache.paimon.types.DataField; +import org.apache.paimon.types.DataType; import org.apache.paimon.types.IntType; import org.apache.paimon.types.LocalZonedTimestampType; import org.apache.paimon.types.RowType; @@ -69,7 +70,7 @@ public static RecordLevelExpire create(CoreOptions options, RowType rowType) { if (!isValidateFieldType(timeFieldType, field)) { throw new IllegalArgumentException( String.format( - "The record level time field type should be one of SECONDS_INT,SECONDS_LONG or MILLIS_LONG, " + "The record level time field type should be one of SECONDS_INT, SECONDS_LONG, MILLIS_LONG or TIMESTAMP, " + "but time field type is %s, field type is %s.", timeFieldType, field.type())); } @@ -80,14 +81,17 @@ public static RecordLevelExpire create(CoreOptions options, RowType rowType) { private static boolean isValidateFieldType( CoreOptions.TimeFieldType timeFieldType, DataField field) { + DataType dataType = field.type(); return ((timeFieldType == CoreOptions.TimeFieldType.SECONDS_INT - && field.type() instanceof IntType) + && dataType instanceof IntType) || (timeFieldType == CoreOptions.TimeFieldType.SECONDS_LONG - && field.type() instanceof BigIntType) + && dataType instanceof BigIntType) || (timeFieldType == CoreOptions.TimeFieldType.MILLIS_LONG - && field.type() instanceof BigIntType) + && dataType instanceof BigIntType) || (timeFieldType == CoreOptions.TimeFieldType.TIMESTAMP - && field.type() instanceof TimestampType)); + && dataType instanceof TimestampType) + || (timeFieldType == CoreOptions.TimeFieldType.TIMESTAMP + && dataType instanceof LocalZonedTimestampType)); } private RecordLevelExpire( diff --git a/paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireWithTimestampBaseTest.java b/paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireWithTimestampBaseTest.java new file mode 100644 index 000000000000..dcc8d246da06 --- /dev/null +++ b/paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireWithTimestampBaseTest.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.paimon.table; + +import org.apache.paimon.CoreOptions; +import org.apache.paimon.catalog.PrimaryKeyTableTestBase; +import org.apache.paimon.data.GenericRow; +import org.apache.paimon.data.Timestamp; +import org.apache.paimon.options.Options; + +import org.junit.jupiter.api.Test; + +import java.time.Duration; + +import static org.assertj.core.api.Assertions.assertThat; + +abstract class RecordLevelExpireWithTimestampBaseTest extends PrimaryKeyTableTestBase { + + @Override + protected Options tableOptions() { + Options options = new Options(); + options.set(CoreOptions.BUCKET, 1); + options.set(CoreOptions.RECORD_LEVEL_EXPIRE_TIME, Duration.ofSeconds(1)); + options.set(CoreOptions.RECORD_LEVEL_TIME_FIELD, "col1"); + options.set(CoreOptions.RECORD_LEVEL_TIME_FIELD_TYPE, CoreOptions.TimeFieldType.TIMESTAMP); + return options; + } + + @Test + public void testTimestampTypeExpire() throws Exception { + long millis = System.currentTimeMillis(); + Timestamp timestamp1 = Timestamp.fromEpochMillis(millis - 60 * 1000); + Timestamp timestamp2 = Timestamp.fromEpochMillis(millis); + Timestamp timestamp3 = Timestamp.fromEpochMillis(millis + 60 * 1000); + + // create at least two files in one bucket + writeCommit(GenericRow.of(1, 1, timestamp1), GenericRow.of(1, 2, timestamp2)); + writeCommit(GenericRow.of(1, 3, timestamp3)); + + // no compaction, can be queried + assertThat(query(new int[] {0, 1})) + .containsExactlyInAnyOrder( + GenericRow.of(1, 1), GenericRow.of(1, 2), GenericRow.of(1, 3)); + Thread.sleep(2000); + + // compact, expired + compact(1); + assertThat(query(new int[] {0, 1})).containsExactlyInAnyOrder(GenericRow.of(1, 3)); + } +} diff --git a/paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireWithTimestampLTZTest.java b/paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireWithTimestampLTZTest.java new file mode 100644 index 000000000000..af834af276c4 --- /dev/null +++ b/paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireWithTimestampLTZTest.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.paimon.table; + +import org.apache.paimon.catalog.Catalog; +import org.apache.paimon.catalog.CatalogContext; +import org.apache.paimon.catalog.CatalogFactory; +import org.apache.paimon.catalog.Identifier; +import org.apache.paimon.fs.Path; +import org.apache.paimon.schema.Schema; +import org.apache.paimon.types.DataTypes; +import org.apache.paimon.utils.TraceableFileIO; + +import org.junit.jupiter.api.BeforeEach; + +import java.util.UUID; + +class RecordLevelExpireWithTimestampLTZTest extends RecordLevelExpireWithTimestampBaseTest { + + @Override + @BeforeEach + public void beforeEachBase() throws Exception { + CatalogContext context = + CatalogContext.create( + new Path(TraceableFileIO.SCHEME + "://" + tempPath.toString())); + Catalog catalog = CatalogFactory.createCatalog(context); + Identifier identifier = new Identifier("default", "T"); + catalog.createDatabase(identifier.getDatabaseName(), true); + Schema schema = + Schema.newBuilder() + .column("pt", DataTypes.INT()) + .column("pk", DataTypes.INT()) + .column("col1", DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE()) + .partitionKeys("pt") + .primaryKey("pk", "pt") + .options(tableOptions().toMap()) + .build(); + catalog.createTable(identifier, schema, true); + table = (FileStoreTable) catalog.getTable(identifier); + commitUser = UUID.randomUUID().toString(); + } +} diff --git a/paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireWithTimestampTest.java b/paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireWithTimestampTest.java index 0a64b33df19f..3c4add8914f8 100644 --- a/paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireWithTimestampTest.java +++ b/paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireWithTimestampTest.java @@ -18,29 +18,20 @@ package org.apache.paimon.table; -import org.apache.paimon.CoreOptions; import org.apache.paimon.catalog.Catalog; import org.apache.paimon.catalog.CatalogContext; import org.apache.paimon.catalog.CatalogFactory; import org.apache.paimon.catalog.Identifier; -import org.apache.paimon.catalog.PrimaryKeyTableTestBase; -import org.apache.paimon.data.GenericRow; -import org.apache.paimon.data.Timestamp; import org.apache.paimon.fs.Path; -import org.apache.paimon.options.Options; import org.apache.paimon.schema.Schema; import org.apache.paimon.types.DataTypes; import org.apache.paimon.utils.TraceableFileIO; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import java.time.Duration; import java.util.UUID; -import static org.assertj.core.api.Assertions.assertThat; - -class RecordLevelExpireWithTimestampTest extends PrimaryKeyTableTestBase { +class RecordLevelExpireWithTimestampTest extends RecordLevelExpireWithTimestampBaseTest { @Override @BeforeEach @@ -64,36 +55,4 @@ public void beforeEachBase() throws Exception { table = (FileStoreTable) catalog.getTable(identifier); commitUser = UUID.randomUUID().toString(); } - - @Override - protected Options tableOptions() { - Options options = new Options(); - options.set(CoreOptions.BUCKET, 1); - options.set(CoreOptions.RECORD_LEVEL_EXPIRE_TIME, Duration.ofSeconds(1)); - options.set(CoreOptions.RECORD_LEVEL_TIME_FIELD, "col1"); - options.set(CoreOptions.RECORD_LEVEL_TIME_FIELD_TYPE, CoreOptions.TimeFieldType.TIMESTAMP); - return options; - } - - @Test - public void test() throws Exception { - long millis = System.currentTimeMillis(); - Timestamp timestamp1 = Timestamp.fromEpochMillis(millis - 60 * 1000); - Timestamp timestamp2 = Timestamp.fromEpochMillis(millis); - Timestamp timestamp3 = Timestamp.fromEpochMillis(millis + 60 * 1000); - - // create at least two files in one bucket - writeCommit(GenericRow.of(1, 1, timestamp1), GenericRow.of(1, 2, timestamp2)); - writeCommit(GenericRow.of(1, 3, timestamp3)); - - // no compaction, can be queried - assertThat(query(new int[] {0, 1})) - .containsExactlyInAnyOrder( - GenericRow.of(1, 1), GenericRow.of(1, 2), GenericRow.of(1, 3)); - Thread.sleep(2000); - - // compact, expired - compact(1); - assertThat(query(new int[] {0, 1})).containsExactlyInAnyOrder(GenericRow.of(1, 3)); - } } From e3262d445d8a403ab2459edec7934de826c7f558 Mon Sep 17 00:00:00 2001 From: Askwang <135721692+Askwang@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:50:34 +0800 Subject: [PATCH 4/4] add detail log --- .../main/java/org/apache/paimon/io/RecordLevelExpire.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/paimon-core/src/main/java/org/apache/paimon/io/RecordLevelExpire.java b/paimon-core/src/main/java/org/apache/paimon/io/RecordLevelExpire.java index e548ae44c422..6083ad92a148 100644 --- a/paimon-core/src/main/java/org/apache/paimon/io/RecordLevelExpire.java +++ b/paimon-core/src/main/java/org/apache/paimon/io/RecordLevelExpire.java @@ -71,8 +71,10 @@ public static RecordLevelExpire create(CoreOptions options, RowType rowType) { throw new IllegalArgumentException( String.format( "The record level time field type should be one of SECONDS_INT, SECONDS_LONG, MILLIS_LONG or TIMESTAMP, " - + "but time field type is %s, field type is %s.", - timeFieldType, field.type())); + + "but time field type is %s, field type is %s. You can specify the type through the config '%s'.", + timeFieldType, + field.type(), + CoreOptions.RECORD_LEVEL_TIME_FIELD_TYPE.key())); } return new RecordLevelExpire(