Skip to content

Conversation

@zhaorui9303
Copy link

@zhaorui9303 zhaorui9303 commented Dec 26, 2025

Why I'm doing:

Support the array join syntax of Clickhouse, eg: select id, c1 from t1 array join array_col as c1

What I'm doing:

Convert ARRAY JOIN to UNNSET + LATERAL JOIN
eg: ARRAY JOIN array_col To JOIN LATERAL UNNEST(array_col)
LEFT ARRAY JOIN array_col To LEFT JOIN LATERAL UNNEST(array_col)
Fixes #issue

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
    • This pr needs auto generate documentation
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 4.0
    • 3.5
    • 3.4
    • 3.3

Note

Introduces ClickHouse-style ARRAY JOIN syntax by rewriting it to LATERAL UNNEST, with left join support and correctness checks.

  • Parser/AST: Extend grammar with arrayJoinClause; in AstBuilder, transform ARRAY JOIN ... (and LEFT ARRAY JOIN ...) into JOIN LATERAL UNNEST(...), set aliases, output column names, and join type
  • Analyzer: In QueryAnalyzer, propagate isLeftJoin and new isArrayJoin to TableFunction; keep lateral join constraints for unnest
  • FE/BE plumbing: Add is_array_join to TTableFunction (Thrift) and FE TableFunction; add _is_array_join_mode to BE TableFunctionState with getters/setters
  • Execution: In MultiUnnest, validate all arrays have equal length when in array-join mode, error if mismatched; preserve left-join null filling
  • Tests: Add SQL tests for ARRAY JOIN and LEFT ARRAY JOIN on arrays

Written by Cursor Bugbot for commit 966a927. This will update automatically on new commits. Configure here.

@zhaorui9303 zhaorui9303 requested review from a team as code owners December 26, 2025 09:19
@CLAassistant
Copy link

CLAassistant commented Dec 26, 2025

CLA assistant check
All committers have signed the CLA.

@alvin-celerdata
Copy link
Contributor

@cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no bugs!

@alvin-celerdata
Copy link
Contributor

@cursor review

@sonarqubecloud
Copy link

private boolean isLeftJoin = false;

private boolean isArrayJoin = false;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy constructor omits isArrayJoin flag

The TableFunction copy constructor does not copy the new isArrayJoin field (nor the pre-existing isLeftJoin field). When copy() is called on a TableFunction that has isArrayJoin set to true, the copied function will have isArrayJoin as false (the default value), losing the flag. While the current ARRAY JOIN implementation doesn't call copy() on the function after setting this flag, future code modifications could trigger this bug, causing the array size validation in the backend to be silently skipped.

Fix in Cursor Fix in Web

@github-actions
Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions
Copy link

[FE Incremental Coverage Report]

fail : 7 / 9 (77.78%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/sql/ast/TableFunctionRelation.java 2 4 50.00% [84, 85]
🔵 com/starrocks/sql/analyzer/QueryAnalyzer.java 1 1 100.00% []
🔵 com/starrocks/catalog/TableFunction.java 4 4 100.00% []

@github-actions
Copy link

[BE Incremental Coverage Report]

fail : 0 / 7 (00.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 src/exprs/table_function/table_function.h 0 1 00.00% [48]
🔵 src/exprs/table_function/multi_unnest.h 0 6 00.00% [55, 60, 71, 75, 76, 78]

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants