diff --git a/paimon-core/src/main/java/org/apache/paimon/schema/SchemaValidation.java b/paimon-core/src/main/java/org/apache/paimon/schema/SchemaValidation.java index b2e873ea5546..4bddcdd72d7e 100644 --- a/paimon-core/src/main/java/org/apache/paimon/schema/SchemaValidation.java +++ b/paimon-core/src/main/java/org/apache/paimon/schema/SchemaValidation.java @@ -181,16 +181,17 @@ public static void validateTableSchema(TableSchema schema) { } } - if (schema.options().containsKey(CoreOptions.RECORD_LEVEL_TIME_FIELD.key())) { - String fieldName = options.recordLevelTimeField(); + String recordLevelTimeField = options.recordLevelTimeField(); + if (recordLevelTimeField != null) { Optional field = schema.fields().stream() - .filter(dataField -> dataField.name().equals(fieldName)) + .filter(dataField -> dataField.name().equals(recordLevelTimeField)) .findFirst(); if (!field.isPresent()) { throw new IllegalArgumentException( String.format( - "Can not find time field %s for record level expire.", fieldName)); + "Can not find time field %s for record level expire.", + recordLevelTimeField)); } DataType dataType = field.get().type(); if (!(dataType instanceof IntType @@ -206,7 +207,7 @@ public static void validateTableSchema(TableSchema schema) { throw new IllegalArgumentException( String.format( "Time field %s for record-level expire should be not null.", - fieldName)); + recordLevelTimeField)); } } diff --git a/paimon-core/src/test/java/org/apache/paimon/schema/SchemaValidationTest.java b/paimon-core/src/test/java/org/apache/paimon/schema/SchemaValidationTest.java index 90c907c05da1..9dbfff200e7b 100644 --- a/paimon-core/src/test/java/org/apache/paimon/schema/SchemaValidationTest.java +++ b/paimon-core/src/test/java/org/apache/paimon/schema/SchemaValidationTest.java @@ -107,7 +107,7 @@ public void testFromSnapshotConflict() { @Test public void testRecordLevelTimeField() { - Map options = new HashMap<>(); + Map options = new HashMap<>(2); options.put(CoreOptions.RECORD_LEVEL_TIME_FIELD.key(), "f0"); options.put(CoreOptions.RECORD_LEVEL_EXPIRE_TIME.key(), "1 m"); assertThatThrownBy(() -> validateTableSchemaExec(options)) diff --git a/paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireTest.java b/paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireTest.java index b8788883ab56..08c8ac548003 100644 --- a/paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireTest.java +++ b/paimon-core/src/test/java/org/apache/paimon/table/RecordLevelExpireTest.java @@ -40,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat; class RecordLevelExpireTest extends PrimaryKeyTableTestBase { + @Override @BeforeEach public void beforeEachBase() throws Exception {