Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] Should use AggRewriteInfo.NOT_REWRITE other than throw exception when mv rewrite #49168

Merged
merged 1 commit into from
Aug 2, 2024

Conversation

kaijianding
Copy link
Contributor

@kaijianding kaijianding commented Jul 30, 2024

Why I'm doing:

test_pt in sql like below failed to transform to it's mv

        SELECT
            sum(gmv)
        FROM
           test_pt
        WHERE
           id IN (
                SELECT upper(id)
                FROM
                   test_pt2
                WHERE
                    pt = '2023-03-07'
                group by upper(id)
            )

What I'm doing:

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.

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.3
    • 3.2
    • 3.1
    • 3.0
    • 2.5

@kaijianding kaijianding requested a review from a team as a code owner July 30, 2024 13:49
@github-actions github-actions bot added the 3.3 label Jul 30, 2024
if (realAggregate == null) {
logMVRewrite(mvRewriteContext, "realAggregate is null");
return AggRewriteInfo.NOT_REWRITE;
}
realAggregate = replaceAggFuncArgument(remapping, origAggColRef, realAggregate, foundIndex);

ColumnRefOperator newAggColRef = queryColumnRefFactory.create(realAggregate,
Copy link

Choose a reason for hiding this comment

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

The most risky bug in this code is:
Potential null pointer exception if newAggregate is referenced when foundIndex is -1.

You can modify the code like this:

if (foundIndex == -1) {
    logMVRewrite(mvRewriteContext, "no aggregate functions found: " + newAggregate != null ? newAggregate.getChildren() : "null");
    return AggRewriteInfo.NOT_REWRITE;
}

@kaijianding kaijianding force-pushed the not_rewrite branch 3 times, most recently from 3bd6a4a to 0d730c8 Compare July 30, 2024 17:52
Copy link

sonarcloud bot commented Jul 31, 2024

Copy link

[FE Incremental Coverage Report]

fail : 6 / 15 (40.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/sql/optimizer/rule/transformation/materialization/AggregatedMaterializedViewPushDownRewriter.java 4 13 30.77% [359, 360, 384, 385, 386, 408, 409, 417, 418]
🔵 com/starrocks/sql/optimizer/rule/transformation/materialization/MaterializedViewRewriter.java 2 2 100.00% []

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link
Contributor

@LiShuMing LiShuMing left a comment

Choose a reason for hiding this comment

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

LGTM

@kangkaisen kangkaisen merged commit ba8115b into StarRocks:main Aug 2, 2024
49 of 50 checks passed
Copy link

github-actions bot commented Aug 2, 2024

@Mergifyio backport branch-3.3

@github-actions github-actions bot removed the 3.3 label Aug 2, 2024
@kaijianding kaijianding deleted the not_rewrite branch August 2, 2024 03:45
Copy link
Contributor

mergify bot commented Aug 2, 2024

backport branch-3.3

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Aug 2, 2024
…tion when mv rewrite (#49168)

Signed-off-by: kaijian.ding <[email protected]>
(cherry picked from commit ba8115b)
kangkaisen pushed a commit that referenced this pull request Aug 6, 2024
…tion when mv rewrite (backport #49168) (#49309)

Co-authored-by: kaijianding <[email protected]>
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