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 65df3f9dc [core] Check bucket-key cannot be nested types (#3949)
65df3f9dc is described below
commit 65df3f9dc97cd4d471e66fd88b0951b7c591e235
Author: xuzifu666 <[email protected]>
AuthorDate: Tue Aug 13 17:00:27 2024 +0800
[core] Check bucket-key cannot be nested types (#3949)
---
.../org/apache/paimon/schema/SchemaValidation.java | 27 ++++++++++++++++++++++
.../apache/paimon/flink/AppendOnlyTableITCase.java | 11 +++++++++
2 files changed, 38 insertions(+)
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 b2c3ed765..b3a2bf11c 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
@@ -69,6 +69,10 @@ import static
org.apache.paimon.CoreOptions.STREAMING_READ_OVERWRITE;
import static
org.apache.paimon.mergetree.compact.PartialUpdateMergeFunction.SEQUENCE_GROUP;
import static org.apache.paimon.schema.SystemColumns.KEY_FIELD_PREFIX;
import static org.apache.paimon.schema.SystemColumns.SYSTEM_FIELD_NAMES;
+import static org.apache.paimon.types.DataTypeRoot.ARRAY;
+import static org.apache.paimon.types.DataTypeRoot.MAP;
+import static org.apache.paimon.types.DataTypeRoot.MULTISET;
+import static org.apache.paimon.types.DataTypeRoot.ROW;
import static org.apache.paimon.utils.Preconditions.checkArgument;
import static org.apache.paimon.utils.Preconditions.checkState;
@@ -564,6 +568,29 @@ public class SchemaValidation {
throw new RuntimeException(
"You should define a 'bucket-key' for bucketed append
mode.");
}
+
+ if (!schema.bucketKeys().isEmpty()) {
+ List<String> bucketKeys = schema.bucketKeys();
+ List<String> nestedFields =
+ schema.fields().stream()
+ .filter(
+ dataField ->
+
bucketKeys.contains(dataField.name())
+ &&
(dataField.type().getTypeRoot() == ARRAY
+ ||
dataField.type().getTypeRoot()
+ ==
MULTISET
+ ||
dataField.type().getTypeRoot()
+ == MAP
+ ||
dataField.type().getTypeRoot()
+ ==
ROW))
+ .map(dataField -> dataField.name())
+ .collect(Collectors.toList());
+ if (nestedFields.size() > 0) {
+ throw new RuntimeException(
+ "nested type can not in bucket-key, in your table
these key are "
+ + nestedFields.toString());
+ }
+ }
}
}
}
diff --git
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/AppendOnlyTableITCase.java
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/AppendOnlyTableITCase.java
index 9a5b9d901..8820ba1cd 100644
---
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/AppendOnlyTableITCase.java
+++
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/AppendOnlyTableITCase.java
@@ -35,6 +35,7 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/** Test case for append-only managed table. */
public class AppendOnlyTableITCase extends CatalogITCaseBase {
@@ -230,6 +231,16 @@ public class AppendOnlyTableITCase extends
CatalogITCaseBase {
assertThat(batchSql("SELECT * FROM
complex_table")).containsExactly(Row.of(1, null));
}
+ @Test
+ public void testNestedTypeDDL() {
+ assertThrows(
+ RuntimeException.class,
+ () ->
+ batchSql(
+ "CREATE TABLE IF NOT EXISTS nested_table (id
INT, data MAP<INT, INT>) WITH ('bucket' = '1', 'bucket-key'='id,data')"),
+ "nested type can not in bucket-key, in your table these key
are [data]");
+ }
+
@Test
public void testTimestampLzType() {
sql("CREATE TABLE t_table (id INT, data TIMESTAMP_LTZ(3))");