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] remain unsupported operator when dict mapping rewrite #42230

Merged
merged 2 commits into from
Mar 7, 2024

Conversation

packy92
Copy link
Contributor

@packy92 packy92 commented Mar 6, 2024

Why I'm doing:

fails in Preconditions.checkState(usedColumns.cardinality() == 1);

java.lang.IllegalStateException: null
        at com.google.common.base.Preconditions.checkState(Preconditions.java:496) ~[spark-dpp-1.0.0.jar:?]
        at com.starrocks.sql.optimizer.rule.tree.DictMappingRewriter.rewriteAsDictMapping(DictMappingRewriter.java:67) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.optimizer.rule.tree.DictMappingRewriter.rewrite(DictMappingRewriter.java:46) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.optimizer.rule.tree.AddDecodeNodeForDictStringRule$DecodeVisitor.rewriteOneScalarOperatorForProjection(AddDecodeNodeForDictStringRule.java:560) ~[starrocks-fe.jar:?]
        at

What I'm doing:

For sql:

SELECT if( S_ADDRESS = 'a' , 'a' , SUBSTR(MD5(S_ADDRESS), 1, 8) END AS value FROM supplier;

When rewriting the nested function, S_ADDRESS = 'a' can apply dict with hasApplied = true, SUBSTR(MD5(S_ADDRESS), 1, 8) has unsupported func and its rewrite result is SUBSTR(MD5(dict_mapping(S_ADDRESS)), 1, 8) with hasApplied = false and disableApplied = false .
For the if function, the rewrite context is hasApplied = true and disableApplied = false , it choose the wrong rewrite branch.

for (int i = 0; i < children.size(); i++) {
                    context.reset();
                    children.set(i, children.get(i).accept(this, context));
                    hasApplied = hasApplied || context.hasAppliedOperator;
                    disableApplied = disableApplied || context.hasUnsupportedOperator;
                }
                if (!disableApplied || !hasApplied) {
                    context.hasAppliedOperator = hasApplied;
                    return operator;
                } else {
                    context.hasAppliedOperator = false;
                    return visit(operator, context);
                }

We need to propagate the hasUnsupportedOperator to the outer to ensure the scalarOperator with hasApplied child and has unsuppored child to do dict mapping process again.

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
    • 3.2
    • 3.1
    • 3.0
    • 2.5

Signed-off-by: packy92 <wangchao@starrocks.com>
Copy link

sonarcloud bot commented Mar 6, 2024

Copy link

github-actions bot commented Mar 6, 2024

[FE Incremental Coverage Report]

fail : 3 / 4 (75.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/sql/optimizer/rule/tree/DictMappingRewriter.java 3 4 75.00% [82]

Copy link

github-actions bot commented Mar 6, 2024

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@imay imay merged commit b36f084 into StarRocks:main Mar 7, 2024
46 of 48 checks passed
Copy link

github-actions bot commented Mar 7, 2024

@Mergifyio backport branch-3.2

@github-actions github-actions bot removed the 3.2 label Mar 7, 2024
Copy link

github-actions bot commented Mar 7, 2024

@Mergifyio backport branch-3.1

Copy link

github-actions bot commented Mar 7, 2024

@Mergifyio backport branch-3.0

Copy link

github-actions bot commented Mar 7, 2024

@Mergifyio backport branch-2.5

@github-actions github-actions bot removed the 2.5 label Mar 7, 2024
Copy link
Contributor

mergify bot commented Mar 7, 2024

backport branch-3.2

✅ Backports have been created

Copy link
Contributor

mergify bot commented Mar 7, 2024

backport branch-3.1

✅ Backports have been created

Copy link
Contributor

mergify bot commented Mar 7, 2024

backport branch-3.0

✅ Backports have been created

Copy link
Contributor

mergify bot commented Mar 7, 2024

backport branch-2.5

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Mar 7, 2024
(cherry picked from commit b36f084)

# Conflicts:
#	test/sql/test_low_cardinality/R/test_low_cardinality
#	test/sql/test_low_cardinality/T/test_low_cardinality
mergify bot pushed a commit that referenced this pull request Mar 7, 2024
mergify bot pushed a commit that referenced this pull request Mar 7, 2024
(cherry picked from commit b36f084)

# Conflicts:
#	test/sql/test_low_cardinality/R/test_low_cardinality
#	test/sql/test_low_cardinality/T/test_low_cardinality
mergify bot pushed a commit that referenced this pull request Mar 7, 2024
(cherry picked from commit b36f084)

# Conflicts:
#	test/sql/test_low_cardinality/R/test_low_cardinality
#	test/sql/test_low_cardinality/T/test_low_cardinality
wanpengfei-git pushed a commit that referenced this pull request Mar 7, 2024
…ort #42230) (#42268)

Signed-off-by: packy92 <wangchao@starrocks.com>
Co-authored-by: packy92 <110370499+packy92@users.noreply.github.com>
Co-authored-by: packy92 <wangchao@starrocks.com>
wanpengfei-git pushed a commit that referenced this pull request Mar 8, 2024
…ort #42230) (#42271)

Signed-off-by: packy92 <wangchao@starrocks.com>
Co-authored-by: packy92 <110370499+packy92@users.noreply.github.com>
Co-authored-by: packy92 <wangchao@starrocks.com>
wanpengfei-git pushed a commit that referenced this pull request Mar 8, 2024
…ort #42230) (#42269)

Signed-off-by: packy92 <wangchao@starrocks.com>
Co-authored-by: packy92 <110370499+packy92@users.noreply.github.com>
Co-authored-by: packy92 <wangchao@starrocks.com>
wanpengfei-git pushed a commit that referenced this pull request Mar 8, 2024
…ort #42230) (#42270)

Signed-off-by: packy92 <wangchao@starrocks.com>
Co-authored-by: packy92 <110370499+packy92@users.noreply.github.com>
Co-authored-by: packy92 <wangchao@starrocks.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.

None yet

4 participants