Skip to content

Conversation

@snuyanzin
Copy link
Contributor

@snuyanzin snuyanzin commented Jan 4, 2026

What is the purpose of the change

The PR implements ALTER MATERIALIZED TABLE ... DROP part of FLIP-550 like

-- drop a column (only drop of non persisted is allowed)
ALTER MATERIALIZED TABLE MyTable DROP col1;
 
-- drop several columns
ALTER MATERIALIZED TABLE MyTable DROP (col1, col2, col3);
 
-- drop a primary key
ALTER MATERIALIZED TABLE MyTable DROP PRIMARY KEY;

-- drop a constraint by name
ALTER MATERIALIZED TABLE MyTable DROP CONSTRAINT constraint_name;

-- drop a watermark
ALTER MATERIALIZED TABLE MyTable DROP WATERMARK;

Besides that it also refactors a bit SqlNodeToOperationConversion by extraction of function and analyze table functionality into dedicated converters.

Verifying this change

There are new tests for failed and success cases, also existing tests

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? (will be done in a separate PR)

Comment on lines 269 to 319
@@ -315,182 +264,56 @@
} else if (validated instanceof SqlCompileAndExecutePlan) {
return Optional.of(
converter.convertCompileAndExecutePlan((SqlCompileAndExecutePlan) validated));
} else if (validated instanceof SqlAnalyzeTable) {
return Optional.of(converter.convertAnalyzeTable((SqlAnalyzeTable) validated));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

all of these moved into separate converter classes
it allowed to make this class less than 1k lines

@flinkbot
Copy link
Collaborator

flinkbot commented Jan 4, 2026

CI report:

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

if (!identifier.isSimple()) {
throw new UnsupportedOperationException(
String.format(
"%sAlter nested row type %s is not supported yet.",
Copy link
Contributor

@davidradl davidradl Jan 5, 2026

Choose a reason for hiding this comment

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

nit: from what I can see the exMsgPrefix comes from the TableKind enum. So would read something like
MATERIALIZED TABLEAlter nested row ....

I wonder if it would read better as Alter %s nested row ...

Copy link
Contributor Author

@snuyanzin snuyanzin Jan 5, 2026

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok thanks - my bad. I saw

this.exMsgPrefix = String.format(ERROR_TEMPLATE, tableKindStr.toUpperCase(Locale.ROOT));
assuming it was picking it up from there. Strange it uses this name of variable in such different ways.

if (oldTable.getResolvedSchema().getWatermarkSpecs().isEmpty()) {
throw new ValidationException(
String.format(
"%sThe current %s does not define any watermark strategy.",
Copy link
Contributor

Choose a reason for hiding this comment

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

similar comment . It will read strangely without a space before the first The

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as mentioned above, there always will be \n

.isInstanceOf(ValidationException.class)
.hasMessageContaining(
"The base table does not define a primary key constraint named 'ct2'. Available constraint name: ['ct1'].");
"The current table does not define a primary key constraint named 'ct2'. Available constraint name: ['ct1'].");
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest including the the message prefix in these tests - so we can see it reads well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added
ideally it should be parameterized and refactored, however this PR is already large, so probably in a separate one

}
|
<DROP> <DISTRIBUTION> {
<DROP>
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this rationalisation of the grammar. Can we update the docs to match it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to submit a separate PR for docs which should cover FLIP-550 (CREATE, ALTER, DROP)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

assertThatThrownBy(() -> parse("alter table tb1 drop primary key"))
.isInstanceOf(ValidationException.class)
.hasMessageContaining("The base table does not define any primary key.");
.hasMessageContaining("The current table does not define any primary key.");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Following same approach as suggested at #27302 (comment)

@github-actions github-actions bot added the community-reviewed PR has been reviewed by the community. label Jan 5, 2026
Copy link
Contributor

@twalthr twalthr left a comment

Choose a reason for hiding this comment

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

Thanks for all these massive refactorings. Very valuable!

UnresolvedIdentifier unresolvedIdentifier =
UnresolvedIdentifier.of(sqlDropFunction.getFullName());
if (sqlDropFunction.isSystemFunction()) {
return new DropTempSystemFunctionOperation(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Interesting that we don't check for isTemporary here. I hope the parser catches this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

looks like there is nothing in parser for that...
Test shows it fails in FunctionCatalog where there is a validation

public boolean dropTemporarySystemFunction(String name, boolean ignoreIfNotExist) {
final String normalizedName = FunctionIdentifier.normalizeName(name);
final CatalogFunction function = tempSystemFunctions.remove(normalizedName);
if (function == null && !ignoreIfNotExist) {
throw new ValidationException(
String.format(
"Could not drop temporary system function. A function named '%s' doesn't exist.",
name));
}
unregisterFunctionJarResources(function);
return function != null;

throw new UnsupportedOperationException(
String.format(
"%sAltering the nested row type `%s` is not supported yet.",
exMsgPrefix, String.join("`.`", identifier.names)));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally quoting requires dialect which could be derived with help of planner.
In order to not make it complicated continue without this since this is only a message for Exception

@snuyanzin
Copy link
Contributor Author

@flinkbot run azure

@snuyanzin snuyanzin closed this in 9215bcd Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-reviewed PR has been reviewed by the community.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants