Skip to content

Conversation

@dssysolyatin
Copy link
Contributor

No description provided.

@dssysolyatin
Copy link
Contributor Author

dssysolyatin commented Nov 19, 2025

saw a useful comment from Julian on one of previous task:

It might be helpful for SqlUnparserTest to unparse everything before and after cloning. Could you enable that in this PR? Then you might not need a specific test case.

It would be good to add this to the current PR. Then we don't need such tests, I hope

@dssysolyatin dssysolyatin marked this pull request as draft November 19, 2025 12:35
@xiedeyantu
Copy link
Member

So, is your PR intended to accomplish what Julian mentioned?

@dssysolyatin dssysolyatin changed the title [CALCITE-7301] Support unparse special syntax when operator is LAMBDA [CALCITE-7301] Support unparse special syntax when operator is LAMBDA/MERGE/UNPIVOT Nov 19, 2025
@dssysolyatin
Copy link
Contributor Author

dssysolyatin commented Nov 19, 2025

I added a test, but many operators in server package (ServerUnParserTest test) don’t have createCall. I’ll look into that next week.

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 UNPIVOT

@dssysolyatin dssysolyatin force-pushed the bug/CALCITE-7301 branch 3 times, most recently from fd224da to 4d0fe65 Compare November 23, 2025 21:02
Copy link
Contributor Author

@dssysolyatin dssysolyatin left a 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));
Copy link
Contributor Author

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),
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 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>]
Copy link
Contributor Author

@dssysolyatin dssysolyatin Nov 23, 2025

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.

@dssysolyatin dssysolyatin marked this pull request as ready for review November 23, 2025 21:52
@sonarqubecloud
Copy link

Copy link
Contributor

@mihaibudiu mihaibudiu left a 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));
Copy link
Contributor

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.
Copy link
Contributor

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.

public class SqlAttributeDefinition extends SqlCall {
private static final SqlSpecialOperator OPERATOR =
new SqlSpecialOperator("ATTRIBUTE_DEF", SqlKind.ATTRIBUTE_DEF);
private static final SqlOperator OPERATOR =
Copy link
Contributor

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 =
Copy link
Contributor

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?

Copy link
Contributor Author

@dssysolyatin dssysolyatin Nov 24, 2025

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

Copy link
Contributor

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

Copy link
Member

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.

@mihaibudiu
Copy link
Contributor

What is the status of this PR?

@dssysolyatin
Copy link
Contributor Author

I will most likely come back to this PR at the end of next week

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