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

[core] Alter table set option with empty key filter #4797

Closed
wants to merge 2 commits into from
Closed
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 @@ -45,6 +45,7 @@
import org.apache.paimon.table.system.SystemTableLoader;
import org.apache.paimon.types.RowType;
import org.apache.paimon.utils.Preconditions;
import org.apache.paimon.utils.StringUtils;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -370,6 +371,7 @@ public void alterTable(
Identifier identifier, List<SchemaChange> changes, boolean ignoreIfNotExists)
throws TableNotExistException, ColumnAlreadyExistException, ColumnNotExistException {
checkNotSystemTable(identifier, "alterTable");
changes = filterNonEmptyKeyInSchemaChange(changes);

try {
getTable(identifier);
Expand Down Expand Up @@ -547,6 +549,18 @@ private void validateCustomTablePath(Map<String, String> options) {
}
}

private List<SchemaChange> filterNonEmptyKeyInSchemaChange(List<SchemaChange> changes) {
List<SchemaChange> schemaChanges = new ArrayList<>();
for (SchemaChange schemaChange : changes) {
if (schemaChange instanceof SchemaChange.SetOption
&& StringUtils.isEmpty(((SchemaChange.SetOption) schemaChange).key())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about throw a exception instead of continue?

Copy link
Member Author

@xuzifu666 xuzifu666 Dec 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, empty is a non-sense config, maybe filter directly also OK, because if alter multiple config would not be terminated. @wwj6591812

continue;
}
schemaChanges.add(schemaChange);
}
return schemaChanges;
}

// =============================== Meta in File System =====================================

protected List<String> listDatabasesInFileSystem(Path warehouse) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ protected List<String> ddl() {
return Collections.singletonList("CREATE TABLE IF NOT EXISTS T (a INT, b INT, c INT)");
}

@Test
public void testAlterOptionsWithEmptyKey() {
batchSql("ALTER TABLE T SET ('write-manifest-cache' = '1 mb')");
batchSql("ALTER TABLE T SET ('' = '2 mb')");
assertThat(
batchSql("SHOW CREATE TABLE T")
.toString()
.contains("'write-manifest-cache' = '1 mb'"))
.isTrue();
assertThat(batchSql("SHOW CREATE TABLE T").toString().contains("'' = '2 mb'")).isFalse();
}

@Test
public void testAQEWithWriteManifest() {
batchSql("ALTER TABLE T SET ('write-manifest-cache' = '1 mb')");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ abstract class DDLTestBase extends PaimonSparkTestBase {
Assertions.assertTrue(schema("name").nullable)
}
}

test("Paimon DDL: set properties with empty key test") {
spark.sql(s"""
|CREATE TABLE T (id STRING, name STRING)
|USING PAIMON
|TBLPROPERTIES ('primary-key'='id')
|""".stripMargin)

spark.sql(s"""
|alter table T
|SET TBLPROPERTIES ('' = 'b')
|""".stripMargin)

assert(!spark.sql(s"show create table T").head().getString(0).contains("'' = 'b'"))
assert(spark.sql(s"show create table T").head().getString(0).contains("'primary-key' = 'id'"))
}

test("Paimon DDL: create primary-key table with not null") {
withTable("T") {
sql("""
Expand Down
Loading