Skip to content

[CALCITE-7550] SqlUpdate and SqlDelete unparse EXISTS subqueries without parentheses#4969

Open
zzwqqq wants to merge 1 commit into
apache:mainfrom
zzwqqq:fix_unparse_where_sqlupdate_sqldelete
Open

[CALCITE-7550] SqlUpdate and SqlDelete unparse EXISTS subqueries without parentheses#4969
zzwqqq wants to merge 1 commit into
apache:mainfrom
zzwqqq:fix_unparse_where_sqlupdate_sqldelete

Conversation

@zzwqqq
Copy link
Copy Markdown
Contributor

@zzwqqq zzwqqq commented May 26, 2026

Jira Link

CALCITE-7550

Changes Proposed

Fixes unparsing of EXISTS subqueries in UPDATE and DELETE statements.

SqlUpdate and SqlDelete were unparsing the WHERE condition directly, which could produce invalid SQL such as WHERE EXISTS SELECT ....

This change moves the existing WHERE unparsing logic from SqlSelectOperator into SqlUtil.unparseWhereClause and reuses it for SELECT, UPDATE, and DELETE, so DML statements use the same WHERE_LIST frame behavior as queries.

Adds regression tests for UPDATE and DELETE with EXISTS predicates.

@sonarqubecloud
Copy link
Copy Markdown

@mihaibudiu mihaibudiu added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label May 26, 2026
@dssysolyatin
Copy link
Copy Markdown
Contributor

Is the same problem valid for MERGE ? I think it is possible to specify EXISTS inside ON clause

@mihaibudiu
Copy link
Copy Markdown
Contributor

@zzwqqq I hope you can answer @dssysolyatin's question before we merge this
Maybe that's the scope for a different issue, but it would be good not to lose this

@zzwqqq
Copy link
Copy Markdown
Contributor Author

zzwqqq commented Jun 5, 2026

Is the same problem valid for MERGE ? I think it is possible to specify EXISTS inside ON clause

Thanks for pointing this out. I have not checked the MERGE case in detail yet, but based on your comment there may be a similar issue.

I opened CALCITE-7585 to track this separately, since it seems related but outside the current UPDATE/DELETE fix. I will follow up there with a concrete reproduction and more details once I confirm the behavior. If the issue is valid, I will continue working on it there.

@zzwqqq
Copy link
Copy Markdown
Contributor Author

zzwqqq commented Jun 5, 2026

@zzwqqq I hope you can answer @dssysolyatin's question before we merge this Maybe that's the scope for a different issue, but it would be good not to lose this

Thanks. I opened CALCITE-7585 to track this separately. I will try to reproduce the MERGE case there and add more details once the behavior is confirmed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LGTM-will-merge-soon Overall PR looks OK. Only minor things left.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants