wuchong commented on a change in pull request #15949:
URL: https://github.com/apache/flink/pull/15949#discussion_r636124299
##########
File path:
flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/operations/SqlToOperationConverter.java
##########
@@ -494,6 +498,18 @@ private Operation convertAlterTableOptions(
}
}
+ private Operation convertAlterTableReset(
+ ObjectIdentifier tableIdentifier,
+ CatalogTable oldTable,
+ SqlAlterTableReset alterTableReset) {
+ oldTable.getOptions();
+ Map<String, String> newOptions = new HashMap<>(oldTable.getOptions());
+ // reset table option keys
+
OperationConverterUtils.extractTableOptionKeys(alterTableReset.getPropertyKeyList())
Review comment:
It seems this util is only used for `SqlAlterTableReset`, could we move
the method to `SqlAlterTableReset`? So that we can easily get reset keys by
`Set<String> alterTableReset.getResetKeys()`.
##########
File path:
flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/operations/SqlToOperationConverter.java
##########
@@ -494,6 +498,18 @@ private Operation convertAlterTableOptions(
}
}
+ private Operation convertAlterTableReset(
+ ObjectIdentifier tableIdentifier,
+ CatalogTable oldTable,
+ SqlAlterTableReset alterTableReset) {
+ oldTable.getOptions();
Review comment:
It seems this is useles, remove it?
##########
File path:
flink-table/flink-table-planner-blink/src/test/java/org/apache/flink/table/planner/operations/SqlToOperationConverterTest.java
##########
@@ -1161,35 +1150,24 @@ public void testAlterTable() throws Exception {
parse(
"alter table cat1.db1.tb1 set ('k1' = 'v1', 'K2' =
'V2')",
SqlDialect.DEFAULT);
- assert operation instanceof AlterTableOptionsOperation;
- final AlterTableOptionsOperation alterTableOptionsOperation =
- (AlterTableOptionsOperation) operation;
- assertEquals(expectedIdentifier,
alterTableOptionsOperation.getTableIdentifier());
- assertEquals(2,
alterTableOptionsOperation.getCatalogTable().getOptions().size());
- Map<String, String> options = new HashMap<>();
- options.put("k1", "v1");
- options.put("K2", "V2");
- assertEquals(options,
alterTableOptionsOperation.getCatalogTable().getOptions());
+ Map<String, String> expectedOptions = new HashMap<>();
+ expectedOptions.put("k", "v");
+ expectedOptions.put("k1", "v1");
+ expectedOptions.put("K2", "V2");
+
+ assertAlterTableOptions(operation, expectedIdentifier,
expectedOptions);
+
+ // test alter table reset
+ operation = parse("alter table cat1.db1.tb1 reset ()",
SqlDialect.DEFAULT);
Review comment:
Should we allow empty reset keys? I think it's meaningless to provide
this feature. We can throw a useful exception to tell users reset keys
shouldn't be empty, instead of executing it silently.
We may have allow empty key-values for `ALTER TABLE ... SET...`. I think we
still have chance to change that.
##########
File path:
flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/api/TableEnvironmentTest.scala
##########
@@ -166,6 +166,98 @@ class TableEnvironmentTest {
TableTestUtil.replaceStreamNodeId(actual))
}
+ @Test
+ def testAlterTableResetInvalidOptionKey(): Unit = {
+ // prepare DDL with invalid table option key
+ val statementWithTypo =
+ """
+ |CREATE TABLE MyTable (
+ | a bigint,
+ | b int,
+ | c varchar
+ |) WITH (
+ | 'connector' = 'datagen',
+ | 'invalid-key' = 'invalid-value'
+ |)
+ """.stripMargin
+ tableEnv.executeSql(statementWithTypo)
+ try {
+ tableEnv.executeSql("explain plan for select * from MyTable where a >
10")
+ fail("Expected an exception")
+ } catch {
+ case t: Throwable =>
+ assertThat(t,
+ containsMessage("Unable to create a source for reading table " +
+ "'default_catalog.default_database.MyTable'.\n\n" +
+ "Table options are:\n\n'connector'='datagen'\n" +
+ "'invalid-key'='invalid-value'" ))
+ }
+ // remove invalid key by RESET
+ val alterTableResetStatement = "ALTER TABLE MyTable RESET ('invalid-key')"
+ val tableResult = tableEnv.executeSql(alterTableResetStatement)
+ assertEquals(ResultKind.SUCCESS, tableResult.getResultKind)
+ assertEquals(
+ Map.apply("connector" -> "datagen").asJava,
Review comment:
nit: Can simplify to `Map("connector" -> "datagen").asJava`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]