Skip to content

[FLINK-39663][table] Support ALTER MATERIALIZED TABLE ... RESET (...) conversion#28165

Merged
snuyanzin merged 4 commits into
apache:masterfrom
raminqaf:FLINK-39663
May 18, 2026
Merged

[FLINK-39663][table] Support ALTER MATERIALIZED TABLE ... RESET (...) conversion#28165
snuyanzin merged 4 commits into
apache:masterfrom
raminqaf:FLINK-39663

Conversation

@raminqaf
Copy link
Copy Markdown
Contributor

What is the purpose of the change

The parser already accepted ALTER MATERIALIZED TABLE t RESET ('k'), but the planner had no converter registered for SqlAlterMaterializedTableReset. As a result, the statement was rejected at plan time with TableException: Unsupported query.

Add SqlAlterMaterializedTableResetConverter and register it in SqlNodeConverters#registerMaterializedTableConverters. The converter emits an AlterMaterializedTableChangeOperation with one TableChange.reset(key) per key. Merging is handled by MaterializedTableChangeHandler.resetTableOption, which is a no-op for keys not currently set. Empty key lists and resetting the connector key are rejected, matching the non-materialized-table RESET path.

Planner-level tests cover success (with order-preserving summary string), empty key list, the connector key, unknown table, and applying RESET to a regular table. A gateway IT test exercises the end-to-end flow in FULL refresh mode where the change is applied directly to the catalog. The user-facing docs are updated for the new RESET clause.

Brief change log

  • Add SqlAlterMaterializedTableResetConverter
  • register the new converter in SqlNodeConverters#registerMaterializedTableConverters
  • Planner-level tests

Verifying this change

  • Added test in planner-level under SqlMaterializedTableNodeToOperationConverterTest.java
  • Added IT cases in MaterializedTableStatementITCase.java

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): (no)
  • The serializers: (no)
  • The runtime per-record code paths (performance sensitive): (no)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no)
  • The S3 file system connector: (no)

Documentation

  • Does this pull request introduce a new feature? (yes)
  • If yes, how is the feature documented? (docs)

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Opus 4.7

… conversion

The parser already accepted `ALTER MATERIALIZED TABLE t RESET ('k')`, but the planner had no converter registered for `SqlAlterMaterializedTableReset`. As a result, the statement was rejected at plan time with `TableException: Unsupported query`.

Add `SqlAlterMaterializedTableResetConverter` and register it in `SqlNodeConverters#registerMaterializedTableConverters`. The converter emits an `AlterMaterializedTableChangeOperation` with one `TableChange.reset(key)` per key. Merging is handled by `MaterializedTableChangeHandler.resetTableOption`, which is a no-op for keys not currently set. Empty key lists and resetting the `connector` key are rejected, matching the non-materialized-table RESET path.

Planner-level tests cover success (with order-preserving summary string), empty key list, the `connector` key, unknown table, and applying RESET to a regular table. A gateway IT test exercises the end-to-end flow in FULL refresh mode where the change is applied directly to the catalog. The user-facing docs are updated for the new RESET clause.
@flinkbot
Copy link
Copy Markdown
Collaborator

flinkbot commented May 15, 2026

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

Comment on lines +58 to +66
final SqlNodeList propertyKeyList = sqlAlterTable.getPropertyKeyList();
if (propertyKeyList.getList().isEmpty()) {
throw new ValidationException(
EX_MSG_PREFIX + "ALTER MATERIALIZED TABLE RESET does not support empty key.");
}
final Set<String> resetKeys = new LinkedHashSet<>(propertyKeyList.size());
for (SqlNode key : propertyKeyList) {
resetKeys.add(SqlParseUtils.extractString((SqlLiteral) key));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use SqlParseUtils.extractList instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice one thanks!

}

@Test
void testAlterMaterializedTableResetWithEmptyKey() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we parameterized similar tests or probably just use already existing parameterized tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Addressed!

final List<String> resetKeys =
SqlParseUtils.extractList(
propertyKeyList, key -> SqlParseUtils.extractString((SqlLiteral) key));
if (resetKeys.contains(FactoryUtil.CONNECTOR.key())) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do we hard fail if there is connector option and do not fail hard if there is unknown option?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

@snuyanzin snuyanzin May 15, 2026

Choose a reason for hiding this comment

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

what happen if there are 5 valid options and 5 unknown options?
will user be able to see which are reset and which are unknown?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we introduce a hard fail for non-exiting option we should consider to do the same for Tables too

Comment on lines +55 to +62
final SqlNodeList propertyKeyList = sqlAlterTable.getPropertyKeyList();
if (propertyKeyList.getList().isEmpty()) {
throw new ValidationException(
EX_MSG_PREFIX + "ALTER MATERIALIZED TABLE RESET does not support empty key.");
}
final List<String> resetKeys =
SqlParseUtils.extractList(
propertyKeyList, key -> SqlParseUtils.extractString((SqlLiteral) key));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess first we can extract, then check if it is empty in order to avoid working with SqlNodeList here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed

throw new ValidationException(
EX_MSG_PREFIX + "ALTER MATERIALIZED TABLE RESET does not support empty key.");
}
final List<String> resetKeys =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we use Set?

  1. later anyway there is contains check
  2. will eliminate duplicates

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed

Spell out the behavior for unknown keys (silently ignored), duplicate keys (de-duplicated), the empty key list (rejected), and the reserved `connector` key (rejected). Add corresponding examples.
@snuyanzin snuyanzin merged commit f1d3622 into apache:master May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants