diff --git a/paimon-core/src/main/java/org/apache/paimon/catalog/AbstractCatalog.java b/paimon-core/src/main/java/org/apache/paimon/catalog/AbstractCatalog.java index 516dc6376b65..33c216cbb101 100644 --- a/paimon-core/src/main/java/org/apache/paimon/catalog/AbstractCatalog.java +++ b/paimon-core/src/main/java/org/apache/paimon/catalog/AbstractCatalog.java @@ -18,6 +18,7 @@ package org.apache.paimon.catalog; +import org.apache.paimon.CoreOptions; import org.apache.paimon.annotation.VisibleForTesting; import org.apache.paimon.factories.FactoryUtil; import org.apache.paimon.fs.FileIO; @@ -178,6 +179,7 @@ public void createTable(Identifier identifier, Schema schema, boolean ignoreIfEx checkNotSystemTable(identifier, "createTable"); validateIdentifierNameCaseInsensitive(identifier); validateFieldNameCaseInsensitive(schema.rowType().getFieldNames()); + validateAutoCreateClose(schema.options()); if (!databaseExists(identifier.getDatabaseName())) { throw new DatabaseNotExistException(identifier.getDatabaseName()); @@ -429,4 +431,15 @@ private void validateFieldNameCaseInsensitiveInSchemaChange(List c private void validateFieldNameCaseInsensitive(List fieldNames) { validateCaseInsensitive(caseSensitive(), "Field", fieldNames); } + + private void validateAutoCreateClose(Map options) { + checkArgument( + !Boolean.valueOf( + options.getOrDefault( + CoreOptions.AUTO_CREATE.key(), + CoreOptions.AUTO_CREATE.defaultValue().toString())), + String.format( + "The value of %s property should be %s.", + CoreOptions.AUTO_CREATE.key(), Boolean.FALSE)); + } } diff --git a/paimon-core/src/test/java/org/apache/paimon/catalog/CatalogTestBase.java b/paimon-core/src/test/java/org/apache/paimon/catalog/CatalogTestBase.java index 1548ddcc3609..517160204526 100644 --- a/paimon-core/src/test/java/org/apache/paimon/catalog/CatalogTestBase.java +++ b/paimon-core/src/test/java/org/apache/paimon/catalog/CatalogTestBase.java @@ -18,6 +18,7 @@ package org.apache.paimon.catalog; +import org.apache.paimon.CoreOptions; import org.apache.paimon.fs.FileIO; import org.apache.paimon.fs.Path; import org.apache.paimon.options.CatalogOptions; @@ -263,6 +264,14 @@ public void testCreateTable() throws Exception { .partitionKeys("pk1", "pk2") .primaryKey("pk1", "pk2", "pk3") .build(); + + // Create table throws Exception when auto-create = true. + schema.options().put(CoreOptions.AUTO_CREATE.key(), Boolean.TRUE.toString()); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> catalog.createTable(identifier, schema, false)) + .withMessage("The value of auto-create property should be false."); + schema.options().remove(CoreOptions.AUTO_CREATE.key()); + catalog.createTable(identifier, schema, false); boolean exists = catalog.tableExists(identifier); assertThat(exists).isTrue();