This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new 7e8f95a6ee [core] format table: add validate
format-table.implementation when create table (#6545)
7e8f95a6ee is described below
commit 7e8f95a6ee82e457246c550756ae38f806ce83f7
Author: jerry <[email protected]>
AuthorDate: Tue Nov 11 10:47:26 2025 +0800
[core] format table: add validate format-table.implementation when create
table (#6545)
---
.../org/apache/paimon/catalog/AbstractCatalog.java | 2 +-
.../org/apache/paimon/catalog/CatalogUtils.java | 12 +++++++++++-
.../java/org/apache/paimon/rest/RESTCatalog.java | 2 +-
.../apache/paimon/rest/MockRESTCatalogTest.java | 22 ++++++++++++++++++++++
4 files changed, 35 insertions(+), 3 deletions(-)
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 97434af299..48933b83d8 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
@@ -381,7 +381,7 @@ public abstract class AbstractCatalog implements Catalog {
throws TableAlreadyExistException, DatabaseNotExistException {
checkNotBranch(identifier, "createTable");
checkNotSystemTable(identifier, "createTable");
- validateCreateTable(schema);
+ validateCreateTable(schema, false);
validateCustomTablePath(schema.options());
// check db exists
diff --git
a/paimon-core/src/main/java/org/apache/paimon/catalog/CatalogUtils.java
b/paimon-core/src/main/java/org/apache/paimon/catalog/CatalogUtils.java
index d82016f931..f4d725814f 100644
--- a/paimon-core/src/main/java/org/apache/paimon/catalog/CatalogUtils.java
+++ b/paimon-core/src/main/java/org/apache/paimon/catalog/CatalogUtils.java
@@ -59,6 +59,7 @@ import java.util.Optional;
import java.util.function.Function;
import static org.apache.paimon.CoreOptions.AUTO_CREATE;
+import static org.apache.paimon.CoreOptions.FORMAT_TABLE_IMPLEMENTATION;
import static org.apache.paimon.CoreOptions.PARTITION_DEFAULT_NAME;
import static org.apache.paimon.CoreOptions.PARTITION_GENERATE_LEGACY_NAME;
import static org.apache.paimon.CoreOptions.PATH;
@@ -142,7 +143,7 @@ public class CatalogUtils {
}
}
- public static void validateCreateTable(Schema schema) {
+ public static void validateCreateTable(Schema schema, boolean
dataTokenEnabled) {
Options options = Options.fromMap(schema.options());
checkArgument(
!options.get(AUTO_CREATE),
@@ -156,6 +157,15 @@ public class CatalogUtils {
options.get(PRIMARY_KEY) == null,
"Cannot define %s for format table.",
PRIMARY_KEY.key());
+ if (dataTokenEnabled) {
+ checkArgument(
+ options.get(PATH) == null
+ && options.get(FORMAT_TABLE_IMPLEMENTATION)
+ !=
CoreOptions.FormatTableImplementation.ENGINE,
+ "Cannot define %s is engine for format table when data
token is enabled and not define %s.",
+ FORMAT_TABLE_IMPLEMENTATION.key(),
+ PATH.key());
+ }
}
for (DataField field : schema.fields()) {
validateDefaultValue(field.type(), field.defaultValue());
diff --git a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
index 1bf8ff2f35..12bce44149 100644
--- a/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
+++ b/paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java
@@ -446,7 +446,7 @@ public class RESTCatalog implements Catalog {
try {
checkNotBranch(identifier, "createTable");
checkNotSystemTable(identifier, "createTable");
- validateCreateTable(schema);
+ validateCreateTable(schema, dataTokenEnabled);
createExternalTablePathIfNotExist(schema);
Schema newSchema = inferSchemaIfExternalPaimonTable(schema);
api.createTable(identifier, newSchema);
diff --git
a/paimon-core/src/test/java/org/apache/paimon/rest/MockRESTCatalogTest.java
b/paimon-core/src/test/java/org/apache/paimon/rest/MockRESTCatalogTest.java
index b0e2415096..e132c38e5a 100644
--- a/paimon-core/src/test/java/org/apache/paimon/rest/MockRESTCatalogTest.java
+++ b/paimon-core/src/test/java/org/apache/paimon/rest/MockRESTCatalogTest.java
@@ -18,8 +18,10 @@
package org.apache.paimon.rest;
+import org.apache.paimon.CoreOptions;
import org.apache.paimon.PagedList;
import org.apache.paimon.Snapshot;
+import org.apache.paimon.TableType;
import org.apache.paimon.catalog.Catalog;
import org.apache.paimon.catalog.CatalogContext;
import org.apache.paimon.catalog.Identifier;
@@ -34,6 +36,8 @@ import org.apache.paimon.rest.auth.DLFTokenLoaderFactory;
import org.apache.paimon.rest.auth.RESTAuthParameter;
import org.apache.paimon.rest.exceptions.NotAuthorizedException;
import org.apache.paimon.rest.responses.ConfigResponse;
+import org.apache.paimon.schema.Schema;
+import org.apache.paimon.types.DataTypes;
import org.apache.paimon.shade.guava30.com.google.common.collect.ImmutableMap;
@@ -49,6 +53,7 @@ import java.util.Map;
import java.util.UUID;
import static org.apache.paimon.rest.RESTApi.HEADER_PREFIX;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -195,6 +200,23 @@ class MockRESTCatalogTest extends RESTCatalogTest {
checkHeader(customHeaderName, customHeaderValue);
}
+ @Test
+ void testCreateFormatTableWhenEnableDataToken() throws Exception {
+ RESTCatalog restCatalog = initCatalog(true);
+ restCatalog.createDatabase("test_db", false);
+ // Create table creates a new table when it does not exist
+ Identifier identifier = Identifier.create("test_db", "new_table");
+ Schema schema = Schema.newBuilder().column("c1",
DataTypes.INT()).build();
+ schema.options().put(CoreOptions.TYPE.key(),
TableType.FORMAT_TABLE.toString());
+ schema.options().put(CoreOptions.FORMAT_TABLE_IMPLEMENTATION.key(),
"engine");
+
+ assertThatExceptionOfType(IllegalArgumentException.class)
+ .isThrownBy(() -> restCatalog.createTable(identifier, schema,
false))
+ .withMessage(
+ "Cannot define format-table.implementation is engine
for format table when data token is enabled and not define path.");
+ catalog.dropTable(identifier, true);
+ }
+
private void checkHeader(String headerName, String headerValue) {
// Verify that the header were included in the requests
List<Map<String, String>> receivedHeaders =
restCatalogServer.getReceivedHeaders();