Skip to content

Conversation

@snuyanzin
Copy link
Contributor

@snuyanzin snuyanzin commented Nov 20, 2025

What is the purpose of the change

So far there are lots of code duplications in terms of unparse method in parser
The PR is addressing this

Brief change log

More code reuse in parser (especially for unparse)

Verifying this change

Existing parser/planner 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? ( no)
  • If yes, how is the feature documented? (not applicable)

SqlIdentifier catalogName;
SqlNodeList propertyList = SqlNodeList.EMPTY;
SqlNode comment = null;
SqlCharStringLiteral comment = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

so far there were different approaches for comments
the PR aligns them

super.unparseAlterOperation(writer, leftPrec, rightPrec);
writer.keyword("ADD");
// unparse table schema and distribution
unparseSchemaAndDistribution(writer, leftPrec, rightPrec);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

distribution will be moved out of schema in following PR

@flinkbot
Copy link
Collaborator

flinkbot commented Nov 20, 2025

CI report:

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


public String[] fullDatabaseName() {
return databaseName.names.toArray(new String[0]);
protected String getScope() {
Copy link
Contributor Author

@snuyanzin snuyanzin Nov 20, 2025

Choose a reason for hiding this comment

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

scope is used by Calcite's SqlCreate/SqlAlter in unparse

+ "c1"
+ commentClause
+ " WITH (\n"
+ "\nWITH (\n"
Copy link
Contributor Author

@snuyanzin snuyanzin Nov 20, 2025

Choose a reason for hiding this comment

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

It also aligns behavior for WITH (always put on a new line)
However as a note: it doesn't impact SHOW CREATE output since for SHOW CREATE there is separate logic in ShowCreateUtil

return operands;
}

@Override
Copy link
Contributor

@davidradl davidradl Nov 21, 2025

Choose a reason for hiding this comment

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

We should remove the @Override as well as the method. This occurs else where also

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why?

it is related to unparseAlterOperation which is also overriden here
for more details have a look at https://github.com/apache/calcite/blob/49fa3edbb98e3f01fccc028c517e8abf78c1f49f/core/src/main/java/org/apache/calcite/sql/SqlAlter.java#L51

public SqlAlterModel(SqlParserPos pos, SqlIdentifier modelName, boolean ifModelExists) {
super(pos);
this.modelName = requireNonNull(modelName, "modelName should not be null");
super(OPERATOR, pos, "MODEL", modelName);
Copy link
Contributor

Choose a reason for hiding this comment

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

I am curious about what the scope "MODEL" does. It only seems to be there for ALTERs and not for CREATEs.

Copy link
Contributor Author

@snuyanzin snuyanzin Nov 21, 2025

Choose a reason for hiding this comment

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

Calcite will know that it should unparse as ALTER MODEL ...

for more details take a look at https://github.com/apache/calcite/blob/49fa3edbb98e3f01fccc028c517e8abf78c1f49f/core/src/main/java/org/apache/calcite/sql/SqlAlter.java

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.

Awesome refactoring @snuyanzin. I left some comments to make the cut between parser and converters cleaner.

@Nullable SqlNodeList bucketColumns,
@Nullable SqlNumericLiteral bucketCount) {
super(pos);
SqlNumericLiteral bucketCount) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not nullable anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, it should be for bucketColumns as it is always initialized in parser

SqlNodeList bucketColumns = SqlNodeList.EMPTY;

fixed

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.

LGTM

@snuyanzin snuyanzin merged commit d0c9ed9 into apache:master Nov 21, 2025
@github-actions github-actions bot added the community-reviewed PR has been reviewed by the community. label Nov 21, 2025
@snuyanzin snuyanzin deleted the flink38702 branch November 25, 2025 17:58
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