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 (backport #42230) #42271

Merged
merged 2 commits into from
Mar 8, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Mar 7, 2024

This is an automatic backport of pull request #42230 done by Mergify.
Cherry-pick of b36f084 has failed:

On branch mergify/bp/branch-2.5/pr-42230
Your branch is up to date with 'origin/branch-2.5'.

You are currently cherry-picking commit b36f0840cc.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/tree/DictMappingRewriter.java
	modified:   fe/fe-core/src/test/java/com/starrocks/sql/plan/LowCardinalityTest.java

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   test/sql/test_low_cardinality/R/test_low_cardinality
	deleted by us:   test/sql/test_low_cardinality/T/test_low_cardinality

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally


Mergify commands and options

More conditions and actions can be found in the documentation.

You can also trigger Mergify actions by commenting on this pull request:

  • @Mergifyio refresh will re-evaluate the rules
  • @Mergifyio rebase will rebase this PR on its base branch
  • @Mergifyio update will merge the base branch into this PR
  • @Mergifyio backport <destination> will backport this PR on <destination> branch

Additionally, on Mergify dashboard you can:

  • look at your merge queues
  • generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.com

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

(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 mergify bot added the conflicts label Mar 7, 2024
Copy link
Contributor Author

mergify bot commented Mar 7, 2024

Cherry-pick of b36f084 has failed:

On branch mergify/bp/branch-2.5/pr-42230
Your branch is up to date with 'origin/branch-2.5'.

You are currently cherry-picking commit b36f0840cc.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   fe/fe-core/src/main/java/com/starrocks/sql/optimizer/rule/tree/DictMappingRewriter.java
	modified:   fe/fe-core/src/test/java/com/starrocks/sql/plan/LowCardinalityTest.java

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   test/sql/test_low_cardinality/R/test_low_cardinality
	deleted by us:   test/sql/test_low_cardinality/T/test_low_cardinality

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@wanpengfei-git wanpengfei-git enabled auto-merge (squash) March 7, 2024 10:00
@mergify mergify bot closed this Mar 7, 2024
auto-merge was automatically disabled March 7, 2024 10:01

Pull request was closed

Copy link
Contributor Author

mergify bot commented Mar 7, 2024

@mergify[bot]: Backport conflict, please reslove the conflict and resubmit the pr

@mergify mergify bot deleted the mergify/bp/branch-2.5/pr-42230 branch March 7, 2024 10:03
@packy92 packy92 restored the mergify/bp/branch-2.5/pr-42230 branch March 7, 2024 14:22
@packy92 packy92 reopened this Mar 7, 2024
@wanpengfei-git wanpengfei-git enabled auto-merge (squash) March 7, 2024 14:23
Signed-off-by: packy92 <[email protected]>
Copy link

sonarcloud bot commented Mar 7, 2024

@wanpengfei-git wanpengfei-git merged commit e694b64 into branch-2.5 Mar 8, 2024
25 of 26 checks passed
@wanpengfei-git wanpengfei-git deleted the mergify/bp/branch-2.5/pr-42230 branch March 8, 2024 01:27
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.

2 participants