Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.paimon.CoreOptions.MergeEngine;
import org.apache.paimon.TableType;
import org.apache.paimon.factories.FactoryUtil;
import org.apache.paimon.fileindex.FileIndexOptions;
import org.apache.paimon.format.FileFormat;
import org.apache.paimon.mergetree.compact.aggregate.FieldAggregator;
import org.apache.paimon.mergetree.compact.aggregate.factory.FieldAggregatorFactory;
Expand Down Expand Up @@ -274,6 +275,8 @@ public static void validateTableSchema(TableSchema schema) {

validateMergeFunctionFactory(schema);

validateFileIndex(schema);

validateRowTracking(schema, options);

validateIncrementalClustering(schema, options);
Expand Down Expand Up @@ -532,6 +535,50 @@ private static void validateMergeFunction(TableSchema schema) {
createMergeFunctionFactory(schema);
}

private static void validateFileIndex(TableSchema schema) {
CoreOptions options = new CoreOptions(schema.options());
FileIndexOptions fileIndexOptions = options.indexColumnsOptions();
if (fileIndexOptions.isEmpty()) {
return;
}

Map<String, DataField> fieldMap = new HashMap<>();
for (DataField field : schema.fields()) {
fieldMap.put(field.name(), field);
}

for (Map.Entry<FileIndexOptions.Column, Map<String, Options>> entry :
fileIndexOptions.entrySet()) {
FileIndexOptions.Column column = entry.getKey();
String columnName = column.getColumnName();
checkArgument(
fieldMap.containsKey(columnName),
"Column '%s' specified in 'file-index.<index-type>.columns' "
+ "does not exist in table schema. Existing columns: %s.",
columnName,
schema.fieldNames());

DataField field = fieldMap.get(columnName);
if (column.isNestedColumn()) {
checkArgument(
field.type().getTypeRoot() == DataTypeRoot.MAP,
"Column '%s' is configured as nested column in "
+ "'file-index.<index-type>.columns' but is not a map type. "
+ "Only map type supports nested column.",
columnName);
DataType keyType = ((MapType) field.type()).getKeyType();
DataTypeRoot keyRoot = keyType.getTypeRoot();
checkArgument(
keyRoot == DataTypeRoot.CHAR || keyRoot == DataTypeRoot.VARCHAR,
"Column '%s' is configured as nested column in "
+ "'file-index.<index-type>.columns', but its map key type is %s. "
+ "Only CHAR/VARCHAR/STRING is supported.",
columnName,
keyType);
}
}
}

private static void validateForDeletionVectors(CoreOptions options) {
checkArgument(
options.changelogProducer() == ChangelogProducer.NONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,79 @@ void testRowTrackingWithPkTable() {
"")))
.hasMessageContaining("primary-key");
}

@Test
public void testFileIndexColumns() {
List<String> keys =
Arrays.asList(
"file-index.bloom-filter.columns",
"file-index.bitmap.columns",
"file-index.bsi.columns",
"file-index.range-bitmap.columns");

for (String key : keys) {
// valid: all referenced columns exist
Map<String, String> okOptions = new HashMap<>();
okOptions.put(key, "f0,f3");
assertThatCode(() -> validateTableSchemaExec(okOptions))
.as("valid key=%s", key)
.doesNotThrowAnyException();

// invalid: references a non-existent column
Map<String, String> badOptions = new HashMap<>();
badOptions.put(key, "f0,not_exist");
assertThatThrownBy(() -> validateTableSchemaExec(badOptions))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining(
"Column 'not_exist' specified in 'file-index.<index-type>.columns' does not exist in table schema.");
}
}

@Test
public void testFileIndexNestedColumn() {
List<String> keys =
Arrays.asList(
"file-index.bloom-filter.columns",
"file-index.bitmap.columns",
"file-index.bsi.columns",
"file-index.range-bitmap.columns");

for (String key : keys) {
// valid: nested syntax on a map column with string key
Map<String, String> okOptions = new HashMap<>();
okOptions.put(key, "m[k]");
assertThatCode(() -> validateTableSchemaWithMapField(okOptions))
.doesNotThrowAnyException();

// invalid: nested syntax on a non-map column
Map<String, String> nonMapOptions = new HashMap<>();
nonMapOptions.put(key, "f3[k]");
assertThatThrownBy(() -> validateTableSchemaWithMapField(nonMapOptions))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining(
"Column 'f3' is configured as nested column in 'file-index.<index-type>.columns' but is not a map type.");

// invalid: nested syntax on a map column with non-string key
Map<String, String> nonStringKeyOptions = new HashMap<>();
nonStringKeyOptions.put(key, "mi[k]");
assertThatThrownBy(() -> validateTableSchemaWithMapField(nonStringKeyOptions))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining(
"Column 'mi' is configured as nested column in 'file-index.<index-type>.columns', but its map key type is INT. Only CHAR/VARCHAR/STRING is supported.");
}
}

private void validateTableSchemaWithMapField(Map<String, String> options) {
List<DataField> fields =
Arrays.asList(
new DataField(0, "f0", DataTypes.INT()),
new DataField(1, "f1", DataTypes.INT()),
new DataField(2, "f2", DataTypes.INT()),
new DataField(3, "f3", DataTypes.STRING()),
new DataField(4, "m", DataTypes.MAP(DataTypes.STRING(), DataTypes.INT())),
new DataField(5, "mi", DataTypes.MAP(DataTypes.INT(), DataTypes.INT())));
options.put(BUCKET.key(), String.valueOf(-1));
validateTableSchema(
new TableSchema(1, fields, 10, emptyList(), singletonList("f1"), options, ""));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void testPartitionFilter(boolean isNamedArgument) throws Exception {
Assertions.assertThat(count.get()).isEqualTo(6);

tEnv.getConfig().set(TableConfigOptions.TABLE_DML_SYNC, true);
sql("ALTER TABLE T SET ('file-index.bloom-filter.columns'='order_id,v')");
sql("ALTER TABLE T SET ('file-index.bloom-filter.columns'='k,v')");
if (isNamedArgument) {
sql("CALL sys.rewrite_file_index(`table` => 'default.T', partitions => 'dt=20221208')");
} else {
Expand Down