Skip to content

Commit

Permalink
[core] auto-create should be false when using create table sql (#2538)
Browse files Browse the repository at this point in the history
  • Loading branch information
hehuiyuan authored and JingsongLi committed Jan 15, 2024
1 parent 99c2200 commit b83b680
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -429,4 +431,15 @@ private void validateFieldNameCaseInsensitiveInSchemaChange(List<SchemaChange> c
private void validateFieldNameCaseInsensitive(List<String> fieldNames) {
validateCaseInsensitive(caseSensitive(), "Field", fieldNames);
}

private void validateAutoCreateClose(Map<String, String> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit b83b680

Please sign in to comment.