Skip to content

[CALCITE-7933] Correlated subqueries with lambdas that capture columns are incorrectly compiled - #5409

Open
mihaibudiu wants to merge 1 commit into
apache:mainfrom
mihaibudiu:issue7933
Open

mihaibudiu wants to merge 1 commit into
apache:mainfrom
mihaibudiu:issue7933

Conversation

@mihaibudiu

@mihaibudiu mihaibudiu commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Jira Link

CALCITE-7933

Changes Proposed

This commit contains multiple small changes and fixes related to lambdas:

SqlToRelConverter:

  • Allow a lambda in a sub-query to read a column of the enclosing query.
  • A lambda in an aggregate gave wrong results or an out-of-bounds error; now it should work correctly.

CorrelateProjectExtractor:

  • does not move an expression that reads a parameter out of the lambda (the actual issue subject)

EnumUtils:

  • In the generated Java code the parameters of the generated code are final. Before, Janino rejected the generated code.

Validator:

  • Reject lambda which have subquries in the body. This is in line with all major SQL dialects which support lambdas.
  • Reject lambdas which invoke an aggregate function, GROUPING, or a windowed aggregate.
  • Reject a lambda in the ORDER BY clause which attempts to read columns (this used to crash; support can be added later if desired)
  • SqlLambdaScope.isParameter checks the first name of a compound identifier, such as r.f0. Before, it failed with an AssertionError.

…s are incorrectly compiled

This commit contains multiple small changes and fixes related to lambdas:

SqlToRelConverter:
- Allow a lambda in a sub-query to read a column of the enclosing query.
- A lambda in an aggregate gave wrong results or an out-of-bounds
  error; now it should work correctly.

CorrelateProjectExtractor:
- does not move an expression that reads a parameter out of the lambda.

EnumUtils:
- In the generated Java code the parameters of the generated code are final.
Before, Janino rejected the generated code.

Validator:
- Reject lambda which have subquries in the body. This is in line
  with all major SQL dialects which support lambdas.
- Reject lambdas which invoke an aggregate function, GROUPING, or a
  windowed aggregate.
- Reject a lambda in the ORDER BY clause which attempts to read
  columns (this used to crash; support can be added later if desired)
- SqlLambdaScope.isParameter checks the first name of a compound
  identifier, such as r.f0. Before, it failed with an AssertionError.

Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
@mihaibudiu

Copy link
Copy Markdown
Contributor Author

I have validated all quidem queries with DuckDB and Spark (Spark rejects two queries)

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.

1 participant