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/incubator-paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 2a8fd891e [core] Add partition type check (#2472)
2a8fd891e is described below

commit 2a8fd891eb60672a2d48081930357c77a41a35eb
Author: shidayang <[email protected]>
AuthorDate: Mon Dec 11 11:39:01 2023 +0800

    [core] Add partition type check (#2472)
---
 .../org/apache/paimon/schema/SchemaValidation.java  | 18 +++++++++++-------
 .../org/apache/paimon/schema/SchemaManagerTest.java | 21 +++++++++++++++++++++
 2 files changed, 32 insertions(+), 7 deletions(-)

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 538cff2dd..9fac38114 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
@@ -79,7 +79,8 @@ public class SchemaValidation {
      * @param schema the schema to be validated
      */
     public static void validateTableSchema(TableSchema schema) {
-        validatePrimaryKeysType(schema.fields(), schema.primaryKeys());
+        validateOnlyContainPrimitiveType(schema.fields(), 
schema.primaryKeys(), "primary key");
+        validateOnlyContainPrimitiveType(schema.fields(), 
schema.partitionKeys(), "partition");
 
         CoreOptions options = new CoreOptions(schema.options());
 
@@ -218,21 +219,24 @@ public class SchemaValidation {
         }
     }
 
-    private static void validatePrimaryKeysType(List<DataField> fields, 
List<String> primaryKeys) {
-        if (!primaryKeys.isEmpty()) {
+    private static void validateOnlyContainPrimitiveType(
+            List<DataField> fields, List<String> fieldNames, String 
errorMessageIntro) {
+        if (!fieldNames.isEmpty()) {
             Map<String, DataField> rowFields = new HashMap<>();
             for (DataField rowField : fields) {
                 rowFields.put(rowField.name(), rowField);
             }
-            for (String primaryKeyName : primaryKeys) {
-                DataField rowField = rowFields.get(primaryKeyName);
+            for (String fieldName : fieldNames) {
+                DataField rowField = rowFields.get(fieldName);
                 DataType dataType = rowField.type();
                 if (PRIMARY_KEY_UNSUPPORTED_LOGICAL_TYPES.stream()
                         .anyMatch(c -> c.isInstance(dataType))) {
                     throw new UnsupportedOperationException(
                             String.format(
-                                    "The type %s in primary key field %s is 
unsupported",
-                                    dataType.getClass().getSimpleName(), 
primaryKeyName));
+                                    "The type %s in %s field %s is 
unsupported",
+                                    dataType.getClass().getSimpleName(),
+                                    errorMessageIntro,
+                                    fieldName));
                 }
             }
         }
diff --git 
a/paimon-core/src/test/java/org/apache/paimon/schema/SchemaManagerTest.java 
b/paimon-core/src/test/java/org/apache/paimon/schema/SchemaManagerTest.java
index f40161312..9c731ffea 100644
--- a/paimon-core/src/test/java/org/apache/paimon/schema/SchemaManagerTest.java
+++ b/paimon-core/src/test/java/org/apache/paimon/schema/SchemaManagerTest.java
@@ -243,6 +243,27 @@ public class SchemaManagerTest {
         assertThat(tableSchema.options()).isEqualTo(options);
     }
 
+    @Test
+    public void testPartitionType() {
+        final RowType mapPrimaryKeyType =
+                RowType.of(
+                        new MapType(new IntType(), new BigIntType()),
+                        new BigIntType(),
+                        new VarCharType());
+        final Schema mapPartitionSchema =
+                new Schema(
+                        mapPrimaryKeyType.getFields(),
+                        partitionKeys,
+                        Collections.emptyList(),
+                        options,
+                        "");
+        assertThatThrownBy(() -> manager.createTable(mapPartitionSchema))
+                .isInstanceOf(UnsupportedOperationException.class)
+                .hasMessage(
+                        "The type %s in partition field %s is unsupported",
+                        MapType.class.getSimpleName(), "f0");
+    }
+
     @Test
     public void testChangelogTableWithFullCompaction() throws Exception {
         Map<String, String> options = new HashMap<>();

Reply via email to