Skip to content

Commit 4e69d37

Browse files
authored
[core] Should prevent users from specifying partition columns as blob field (#6753)
1 parent 2064abe commit 4e69d37

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

paimon-core/src/main/java/org/apache/paimon/schema/SchemaValidation.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
import static org.apache.paimon.table.SpecialFields.KEY_FIELD_PREFIX;
7979
import static org.apache.paimon.table.SpecialFields.SYSTEM_FIELD_NAMES;
8080
import static org.apache.paimon.types.DataTypeRoot.ARRAY;
81-
import static org.apache.paimon.types.DataTypeRoot.BLOB;
8281
import static org.apache.paimon.types.DataTypeRoot.MAP;
8382
import static org.apache.paimon.types.DataTypeRoot.MULTISET;
8483
import static org.apache.paimon.types.DataTypeRoot.ROW;
@@ -650,16 +649,21 @@ private static void validateRowTracking(TableSchema schema, CoreOptions options)
650649
"Data evolution config must disabled with deletion-vectors.enabled");
651650
}
652651

653-
if (schema.fields().stream().map(DataField::type).anyMatch(t -> t.is(BLOB))) {
652+
List<String> blobNames =
653+
BlobType.splitBlob(schema.logicalRowType()).getRight().getFieldNames();
654+
if (!blobNames.isEmpty()) {
654655
checkArgument(
655656
options.dataEvolutionEnabled(),
656657
"Data evolution config must enabled for table with BLOB type column.");
657658
checkArgument(
658-
BlobType.splitBlob(schema.logicalRowType()).getRight().getFieldCount() == 1,
659+
blobNames.size() == 1,
659660
"Table with BLOB type column only support one BLOB column.");
660661
checkArgument(
661662
schema.fields().size() > 1,
662663
"Table with BLOB type column must have other normal columns.");
664+
checkArgument(
665+
!schema.partitionKeys().contains(blobNames.get(0)),
666+
"The BLOB type column can not be part of partition keys.");
663667
}
664668
}
665669

paimon-core/src/test/java/org/apache/paimon/schema/SchemaValidationTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ private void validateTableSchemaExec(Map<String, String> options) {
5656
new TableSchema(1, fields, 10, partitionKeys, primaryKeys, options, ""));
5757
}
5858

59+
private void validateBlobSchema(Map<String, String> options, List<String> partitions) {
60+
List<DataField> fields =
61+
Arrays.asList(
62+
new DataField(0, "f0", DataTypes.INT()),
63+
new DataField(1, "f1", DataTypes.INT()),
64+
new DataField(2, "f2", DataTypes.BLOB()),
65+
new DataField(3, "f3", DataTypes.STRING()));
66+
options.put(BUCKET.key(), String.valueOf(-1));
67+
validateTableSchema(
68+
new TableSchema(1, fields, 10, partitions, Collections.emptyList(), options, ""));
69+
}
70+
5971
@Test
6072
public void testOnlyTimestampMillis() {
6173
Map<String, String> options = new HashMap<>();
@@ -122,4 +134,21 @@ public void testRecordLevelTimeField() {
122134
.hasMessageContaining(
123135
"The record level time field type should be one of INT, BIGINT, or TIMESTAMP, but field type is STRING.");
124136
}
137+
138+
@Test
139+
public void testBlobTableSchema() {
140+
Map<String, String> options = new HashMap<>();
141+
142+
// 1. must set row-tracking = true and data-evolution = true
143+
options.put(CoreOptions.ROW_TRACKING_ENABLED.key(), "true");
144+
assertThatThrownBy(() -> validateBlobSchema(options, Collections.emptyList()))
145+
.hasMessage("Data evolution config must enabled for table with BLOB type column.");
146+
147+
// 2. blob column cannot be part of partition keys
148+
options.clear();
149+
options.put(CoreOptions.ROW_TRACKING_ENABLED.key(), "true");
150+
options.put(CoreOptions.DATA_EVOLUTION_ENABLED.key(), "true");
151+
assertThatThrownBy(() -> validateBlobSchema(options, Collections.singletonList("f2")))
152+
.hasMessage("The BLOB type column can not be part of partition keys.");
153+
}
125154
}

0 commit comments

Comments
 (0)