-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[CALCITE-7301] Add common test for SqlNode unparse after deep copy and fix operators missing createCall #4644
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
base: main
Are you sure you want to change the base?
Conversation
|
saw a useful comment from Julian on one of previous task:
It would be good to add this to the current PR. Then we don't need such tests, I hope |
9303179 to
12ac1a8
Compare
|
So, is your PR intended to accomplish what Julian mentioned? |
|
I added a test, but many operators in Also, I’m not sure if I should add the operator at the end of getOperandList, or if I can reorder them to match the constructor parameter order. The last one would be much better. One example of this is |
4d0fe65 to
659f51b
Compare
dssysolyatin
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.
Adding a common test revealed several issues (most of them were related to org.apache.calcite.sql.ddl SqlNodes). I tried to fix them in the most straightforward way
@mihaibudiu please re-review PR, it has changed quite a bit since your last approval
| ] | ||
| { | ||
| list.add(SqlDdlNodes.column(s.add(id).end(this), id, | ||
| type.withNullable(nullable), null, 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.
It was added because SqlDdlNodes.column does not expect null for ColumnStrategy.
| @SuppressWarnings("nullness") | ||
| @Override public List<SqlNode> getOperandList() { | ||
| return ImmutableNullableList.of(SqlLiteral.createBoolean(getReplace(), pos), | ||
| SqlLiteral.createSymbol(tableCollectionType, pos), |
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’m taking the most straightforward approach using SqlLiteral for boolean flag for replace and ifNotExists. Ideally, replace and ifNotExists should each have their own SqlNode implementation.
That way, we won’t need to write code like this every time:
if (ifNotExists) {
writer.keyword("IF NOT EXISTS");
}
Instead, we could just call:
ifNotExists.unparse(...)
| #### Breaking Changes | ||
| {: #breaking-1-42-0} | ||
|
|
||
| * [<a href="https://issues.apache.org/jira/browse/CALCITE-7301">CALCITE-7301</a>] |
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 is a breaking change, but I hope it should not affect anyone. All SqlNode classes inside org.apache.calcite.sql.ddl expose their operands through public fields, and none of these nodes implement setOperand. Because of that, I expect that getOperandList() is not used outside the Calcite codebase for these SqlNode types.
For SqlUnpivot, I added the SqlLiteral at the end of the operand list.
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.
@mihaibudiu I personally would prefer to include this as a breaking change, including the changes you made in your ddl related PR, which you submitted separately.
The number of arguments in the operator list has changed, and this is a runtime breaking change. Existing code may assume different behavior, for example:
if (!operandList.isEmpty) {
// show user first operand or another crazy cases
}
|
mihaibudiu
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.
These changes look useful, but I think there should be a new JIRA issue for all the DDL stuff.
Can you please break down this PR into separate pieces?
Perhaps you can do all DDL in one issue.
| { | ||
| list.add(SqlDdlNodes.column(s.add(id).end(this), id, | ||
| type.withNullable(nullable), null, null)); | ||
| type.withNullable(nullable), null, ColumnStrategy.DEFAULT)); |
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.
what is the relationship of this change with the issue that is being addressed?
| SqlParserFixture f = fixture().withDialect(PostgresqlSqlDialect.DEFAULT); | ||
| // UnparsingTesterImpl has a check where it unparses a SqlNode into a SQL string | ||
| // using the calcite dialect, and then parses it back into a SqlNode. | ||
| // But the SQL string produced by the calcite dialect for `SET` cannot always be parsed back. |
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.
does this require filing a new issue?
if so, perhaps you can add here the issue link.
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 don’t see a reason to spend time on it, as this is a very specific case.
Additionally, I think almost nobody uses this syntax. I originally introduced it while working on the implementation of the Postgres wire protocol and integrating various tools on top of it. At that time, I didn’t observe much interest in this feature outside the company I was working for
| public class SqlAttributeDefinition extends SqlCall { | ||
| private static final SqlSpecialOperator OPERATOR = | ||
| new SqlSpecialOperator("ATTRIBUTE_DEF", SqlKind.ATTRIBUTE_DEF); | ||
| private static final SqlOperator OPERATOR = |
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.
is this in scope for the current issue?
| public class SqlCheckConstraint extends SqlCall { | ||
| private static final SqlSpecialOperator OPERATOR = | ||
| new SqlSpecialOperator("CHECK", SqlKind.CHECK); | ||
| private static final SqlOperator OPERATOR = |
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 can sense some scope creep; you started with lambda and now you are doing many other things.
This is not even part of the list of operators in the JIRA issue.
why not do them in separate PRs?
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.
The main reason is that I added the common test (see SqlParserTest), and after that the unparse test for all these operators started failing. I don’t think it makes sense to create a smaller PR for this. What I can do is rename the task
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.
sure, please rename the task and then ask for a review again
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 have a small suggestion—not sure if it’s acceptable. Would it be possible to create a new JIRA to work on modifying the testing framework first, and then come back to complete the current PR? That might make things clearer.
|
What is the status of this PR? |
|
I will most likely come back to this PR at the end of next week |
659f51b to
d4a195c
Compare
d4a195c to
0cee375
Compare
|
dssysolyatin
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.
The task was renamed, and the scope became much smaller after @mihaibudiu merged the DDL PR (Thanks again for that)
But it looks like we missed two things related DDL. See
- SqlCreateView.java (wrong order of operands)
- SqlCreateTable.java (columnList can be empty if syntax like
CREATE TABLE t AS SELECTis used)
| #### Breaking Changes | ||
| {: #breaking-1-42-0} | ||
|
|
||
| * [<a href="https://issues.apache.org/jira/browse/CALCITE-7301">CALCITE-7301</a>] |
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.
@mihaibudiu I personally would prefer to include this as a breaking change, including the changes you made in your ddl related PR, which you submitted separately.
The number of arguments in the operator list has changed, and this is a runtime breaking change. Existing code may assume different behavior, for example:
if (!operandList.isEmpty) {
// show user first operand or another crazy cases
}



No description provided.