Skip to content

Conversation

@murphyatwork
Copy link
Contributor

@murphyatwork murphyatwork commented Dec 10, 2025

Why I'm doing:

What I'm doing:

SELECT * FROM extend_predicate 
WHERE any_match(x -> get_json_double(x, '$.longitude') > 0, CAST(c2 AS ARRAY<JSON>))

The lambda function was rewritten into a wrong expresison.

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 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

Skip rewriting JSON functions when the JSON argument is a lambda variable not attached to a table; add a test for any_match scenario and tighten precondition checks.

  • Optimizer (JSON path rewrite)
    • Avoid rewriting supported JSON functions when the JSON argument is a ColumnRefOperator not attached to a table (e.g., lambda variables), by checking columnRefFactory.getTableAndColumn(...).
    • Strengthen safety with Preconditions.checkState in createColumnAccessExpression instead of silently returning the original column.
  • Tests
    • Add lambda case to ensure get_json_double inside any_match is not rewritten (JsonPathRewriteTest case [22]).

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

Signed-off-by: Murphy <mofei@starrocks.com>
Copilot AI review requested due to automatic review settings December 10, 2025 07:42
@murphyatwork murphyatwork requested a review from a team as a code owner December 10, 2025 07:42
@github-actions github-actions bot added the 4.0 label Dec 10, 2025
@mergify
Copy link
Contributor

mergify bot commented Dec 10, 2025

🧪 CI Insights

Here's what we observed from your CI run for 3887d72.

🟢 All jobs passed!

But CI Insights is watching 👀

@sonarqubecloud
Copy link

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where JSON v2 rewrite incorrectly attempted to rewrite JSON function calls within lambda expressions. The issue occurred when get_json_double was called on a lambda argument (e.g., x in any_match(x -> get_json_double(x, '$.longitude') > 0, ...)). Lambda arguments are ColumnRefOperator instances but are not attached to tables, causing the rewrite rule to fail or produce incorrect expressions.

Key Changes:

  • Added early exit check in JsonPathRewriteRule to skip rewriting when the JSON column is not attached to a table
  • Converted defensive null check in createColumnAccessExpression to a Preconditions.checkState assertion
  • Added test case to verify lambda functions with JSON operations are not incorrectly rewritten

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/tree/JsonPathRewriteRule.java Added check to prevent rewriting JSON functions on lambda arguments; converted null check to precondition assertion
fe/fe-core/src/test/java/com/starrocks/sql/plan/JsonPathRewriteTest.java Added test case [22] verifying lambda functions with JSON operations are not rewritten

@murphyatwork murphyatwork enabled auto-merge (squash) December 10, 2025 07:58
@github-actions
Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions
Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions
Copy link

[FE Incremental Coverage Report]

pass : 5 / 5 (100.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/sql/optimizer/rule/tree/JsonPathRewriteRule.java 5 5 100.00% []

@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!


@murphyatwork murphyatwork merged commit 07cb74c into StarRocks:main Dec 15, 2025
81 of 85 checks passed
@github-actions
Copy link

@Mergifyio backport branch-4.0

@github-actions github-actions bot removed the 4.0 label Dec 15, 2025
@mergify
Copy link
Contributor

mergify bot commented Dec 15, 2025

backport branch-4.0

✅ Backports have been created

Details

mergify bot pushed a commit that referenced this pull request Dec 15, 2025
wanpengfei-git pushed a commit that referenced this pull request Dec 15, 2025
Co-authored-by: Murphy <96611012+murphyatwork@users.noreply.github.com>
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