Skip to content

Commit

Permalink
[core] Check bucket-key cannot be nested types (#3949)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuzifu666 authored Aug 13, 2024
1 parent ab14a13 commit 65df3f9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
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;

Expand Down Expand Up @@ -564,6 +568,29 @@ private static void validateBucket(TableSchema schema, CoreOptions options) {
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());
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

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 {
Expand Down Expand Up @@ -230,6 +231,16 @@ public void testComplexType() {
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))");
Expand Down

0 comments on commit 65df3f9

Please sign in to comment.