Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-36609][pipeline-connector][paimon] add partition columns to primary keys. #3641

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -164,14 +164,18 @@ private void applyCreateTable(CreateTableEvent event) throws SchemaEvolveExcepti
LogicalTypeConversion.toDataType(
DataTypeUtils.toFlinkDataType(column.getType())
.getLogicalType())));
builder.primaryKey(schema.primaryKeys().toArray(new String[0]));
List<String> partitionKeys = new ArrayList<>();
List<String> primaryKeys = schema.primaryKeys();
if (partitionMaps.containsKey(event.tableId())) {
builder.partitionKeys(partitionMaps.get(event.tableId()));
partitionKeys.addAll(partitionMaps.get(event.tableId()));
} else if (schema.partitionKeys() != null && !schema.partitionKeys().isEmpty()) {
builder.partitionKeys(schema.partitionKeys());
partitionKeys.addAll(schema.partitionKeys());
}
builder.options(tableOptions);
builder.options(schema.options());
primaryKeys.addAll(partitionKeys);
builder.partitionKeys(partitionKeys)
.primaryKey(primaryKeys)
.options(tableOptions)
.options(schema.options());
catalog.createTable(
new Identifier(event.tableId().getSchemaName(), event.tableId().getTableName()),
builder.build(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,35 @@ public void testApplySchemaChange(String metastore)
new DataField(2, "newcol3", DataTypes.STRING())));
Assertions.assertEquals(
tableSchema, catalog.getTable(Identifier.fromString("test.table1")).rowType());

// Create table with partition column.
createTableEvent =
new CreateTableEvent(
TableId.parse("test.table_with_partition"),
org.apache.flink.cdc.common.schema.Schema.newBuilder()
.physicalColumn(
"col1",
org.apache.flink.cdc.common.types.DataTypes.STRING()
.notNull())
.physicalColumn(
"col2", org.apache.flink.cdc.common.types.DataTypes.INT())
.physicalColumn(
"dt",
org.apache.flink.cdc.common.types.DataTypes.INT().notNull())
.primaryKey("col1")
.partitionKey("dt")
.build());
metadataApplier.applySchemaChange(createTableEvent);
tableSchema =
new RowType(
Arrays.asList(
new DataField(0, "col1", DataTypes.STRING().notNull()),
new DataField(1, "col2", DataTypes.INT()),
new DataField(2, "dt", DataTypes.INT().notNull())));
Table tableWithPartition =
catalog.getTable(Identifier.fromString("test.table_with_partition"));
Assertions.assertEquals(tableSchema, tableWithPartition.rowType());
Assertions.assertEquals(Arrays.asList("col1", "dt"), tableWithPartition.primaryKeys());
}

@ParameterizedTest
Expand Down
Loading