-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[CALCITE-7342] Quidem test support for TopDownGeneralDecorrelator #4704
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
5f02045
f28845d
47ba12a
3a809cd
7365ac2
9633b5a
ecf7fa6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,7 @@ | |
| import org.apache.calcite.sql2rel.RelDecorrelator; | ||
| import org.apache.calcite.sql2rel.RelFieldTrimmer; | ||
| import org.apache.calcite.sql2rel.SqlToRelConverter; | ||
| import org.apache.calcite.sql2rel.TopDownGeneralDecorrelator; | ||
| import org.apache.calcite.util.Util; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
|
|
@@ -259,7 +260,26 @@ public static Program subQuery(RelMetadataProvider metadataProvider) { | |
| CoreRules.PROJECT_SUB_QUERY_TO_CORRELATE, | ||
| CoreRules.JOIN_SUB_QUERY_TO_CORRELATE, | ||
| CoreRules.PROJECT_OVER_SUM_TO_SUM0_RULE)); | ||
| return of(builder.build(), true, metadataProvider); | ||
| final Program oldProgram = of(builder.build(), true, metadataProvider); | ||
|
|
||
| final HepProgramBuilder newBuilder = HepProgram.builder(); | ||
| newBuilder.addRuleCollection( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do these cover all subquery cases?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only found this one instance of logic for handling subqueries; there's nothing else. I'm also a bit confused about why it handles SUM, but since this is code from 2024, I've decided to keep it here for now, we can see CALCITE-6020. |
||
| ImmutableList.of(CoreRules.FILTER_SUB_QUERY_TO_MARK_CORRELATE, | ||
| CoreRules.PROJECT_SUB_QUERY_TO_MARK_CORRELATE, | ||
| CoreRules.JOIN_SUB_QUERY_TO_CORRELATE, | ||
| CoreRules.PROJECT_OVER_SUM_TO_SUM0_RULE)); | ||
| final Program newProgram = of(newBuilder.build(), true, metadataProvider); | ||
|
|
||
| return (planner, rel, requiredOutputTraits, materializations, lattices) -> { | ||
| final CalciteConnectionConfig config = | ||
| planner.getContext().maybeUnwrap(CalciteConnectionConfig.class) | ||
| .orElse(CalciteConnectionConfig.DEFAULT); | ||
| final Program program = config.topDownGeneralDecorrelationEnabled() | ||
| ? newProgram | ||
| : oldProgram; | ||
| return program.run(planner, rel, requiredOutputTraits, materializations, | ||
| lattices); | ||
| }; | ||
| } | ||
|
|
||
| public static Program measure(RelMetadataProvider metadataProvider) { | ||
|
|
@@ -425,6 +445,9 @@ private static class DecorrelateProgram implements Program { | |
| if (config.forceDecorrelate()) { | ||
| final RelBuilder relBuilder = | ||
| RelFactories.LOGICAL_BUILDER.create(rel.getCluster(), null); | ||
| if (config.topDownGeneralDecorrelationEnabled()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we also need to adapt the Program of removing subquery. When using the new decorrelator, We recommend using
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! I will fix it later.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After replacing these two rules, |
||
| return TopDownGeneralDecorrelator.decorrelateQuery(rel, relBuilder); | ||
| } | ||
| return RelDecorrelator.decorrelateQuery(rel, relBuilder); | ||
| } | ||
| return rel; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this change related to this issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm not entirely sure why; I made some adjustments based on the error message. I will revert the changes to RelDistribution later.