-
Notifications
You must be signed in to change notification settings - Fork 13.8k
[FLINK-38702][table] Make unparse more reusable in parser
#27256
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
Conversation
| SqlIdentifier catalogName; | ||
| SqlNodeList propertyList = SqlNodeList.EMPTY; | ||
| SqlNode comment = null; | ||
| SqlCharStringLiteral comment = null; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
|
|
||
| public String[] fullDatabaseName() { | ||
| return databaseName.names.toArray(new String[0]); | ||
| protected String getScope() { |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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
8d5bc55 to
1f62493
Compare
| return operands; | ||
| } | ||
|
|
||
| @Override |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
twalthr
left a comment
There was a problem hiding this 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.
...e/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterCatalogComment.java
Outdated
Show resolved
Hide resolved
...ble/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterCatalogReset.java
Outdated
Show resolved
Hide resolved
...able/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlAlterModelRename.java
Outdated
Show resolved
Hide resolved
| @Nullable SqlNodeList bucketColumns, | ||
| @Nullable SqlNumericLiteral bucketCount) { | ||
| super(pos); | ||
| SqlNumericLiteral bucketCount) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not nullable anymore?
There was a problem hiding this comment.
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
flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/ddl/SqlDropObject.java
Outdated
Show resolved
Hide resolved
...er/src/main/java/org/apache/flink/table/planner/operations/SqlNodeToOperationConversion.java
Outdated
Show resolved
Hide resolved
...er/src/main/java/org/apache/flink/table/planner/operations/SqlNodeToOperationConversion.java
Outdated
Show resolved
Hide resolved
twalthr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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:
@Public(Evolving): ( no)Documentation