Repository navigation
IGNITE-28899 Calcite. Fix litmus error during join #13389
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: master
Are you sure you want to change the base?
Changes from 2 commits
4b959cc
e6b318b
1322ea1
721c2f4
5e7216b
0e00b1b
9455947
ba1fcea
5dd9336
b3999a5
cff9d91
1e78f11
6025901
2c5c8cb
f821da4
f844134
4850afd
1cf3a54
faecb58
14780e1
cffdb81
c914121
e29bd0b
6763848
b2e2306
0e80418
f2b2705
038cf37
5a3b459
d515947
0c2c568
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 |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| import java.util.List; | ||
| import java.util.Set; | ||
| import org.apache.calcite.plan.RelOptTable; | ||
| import org.apache.calcite.plan.volcano.RelSubset; | ||
| import org.apache.calcite.rel.RelNode; | ||
| import org.apache.calcite.rel.core.Aggregate; | ||
| import org.apache.calcite.rel.core.AggregateCall; | ||
|
|
@@ -51,8 +52,10 @@ | |
| import org.apache.calcite.rex.RexSlot; | ||
| import org.apache.calcite.rex.RexVisitor; | ||
| import org.apache.calcite.rex.RexVisitorImpl; | ||
| import org.apache.calcite.util.BuiltInMethod; | ||
| import org.apache.calcite.util.ImmutableBitSet; | ||
| import org.apache.calcite.util.mapping.Mappings; | ||
| import org.apache.ignite.internal.processors.query.calcite.rel.ProjectableFilterableTableScan; | ||
| import org.apache.ignite.internal.processors.query.calcite.util.Commons; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| /** | ||
|
|
@@ -61,8 +64,9 @@ | |
| */ | ||
| public class IgniteMdColumnOrigins implements MetadataHandler<BuiltInMetadata.ColumnOrigin> { | ||
| /** */ | ||
| public static final RelMetadataProvider SOURCE = ReflectiveRelMetadataProvider.reflectiveSource( | ||
| BuiltInMethod.COLUMN_ORIGIN.method, new IgniteMdColumnOrigins()); | ||
| public static final RelMetadataProvider SOURCE = | ||
| ReflectiveRelMetadataProvider.reflectiveSource( | ||
| new IgniteMdColumnOrigins(), BuiltInMetadata.ColumnOrigin.Handler.class); | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public MetadataDef<BuiltInMetadata.ColumnOrigin> getDef() { | ||
|
|
@@ -261,27 +265,45 @@ public class IgniteMdColumnOrigins implements MetadataHandler<BuiltInMetadata.Co | |
| int iOutputColumn | ||
| ) { | ||
| if (rel.projects() != null) { | ||
| RexNode proj = rel.projects().get(iOutputColumn); | ||
| Set<RexSlot> sources = new HashSet<>(); | ||
| RexNode node = rel.projects().get(iOutputColumn); | ||
| if (node instanceof RexInputRef) { | ||
| RexInputRef inputRef = (RexInputRef)node; | ||
| iOutputColumn = inputRef.getIndex(); | ||
| } | ||
| else { | ||
| Set<RexSlot> sources = new HashSet<>(); | ||
|
|
||
| getOperands(proj, RexSlot.class, sources); | ||
| getOperands(node, RexSlot.class, sources); | ||
|
|
||
| boolean derived = sources.size() > 1; | ||
| Set<RelColumnOrigin> res = new HashSet<>(); | ||
| boolean derived = sources.size() > 1; | ||
| Set<RelColumnOrigin> res = new HashSet<>(); | ||
|
|
||
| for (RexSlot slot : sources) { | ||
| if (slot instanceof RexLocalRef) { | ||
| RelColumnOrigin slotOrigin = rel.columnOriginsByRelLocalRef(slot.getIndex()); | ||
| for (RexSlot slot : sources) { | ||
| if (slot instanceof RexLocalRef) { | ||
| RelColumnOrigin slotOrigin = rel.columnOriginsByRelLocalRef(slot.getIndex()); | ||
|
|
||
| res.add(new RelColumnOrigin(slotOrigin.getOriginTable(), slotOrigin.getOriginColumnOrdinal(), | ||
| derived)); | ||
| res.add(new RelColumnOrigin(slotOrigin.getOriginTable(), slotOrigin.getOriginColumnOrdinal(), | ||
| derived)); | ||
| } | ||
| } | ||
|
|
||
| return res; | ||
| } | ||
| } | ||
|
|
||
| ImmutableBitSet requiredColumns = rel.requiredColumns(); | ||
| RelOptTable table = rel.getTable(); | ||
|
|
||
| if (requiredColumns != null) { | ||
| Mappings.TargetMapping trimming = Commons.projectedMapping(requiredColumns, table.getRowType().getFieldCount()); | ||
|
|
||
| iOutputColumn = trimming.getSourceOpt(iOutputColumn); | ||
|
|
||
| return res; | ||
| if (iOutputColumn == -1) | ||
| return null; | ||
| } | ||
|
|
||
| return Collections.singleton(rel.columnOriginsByRelLocalRef(iOutputColumn)); | ||
|
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. What the difference with the current implementation?
Contributor
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.
|
||
| return Set.of(new RelColumnOrigin(table, iOutputColumn, false)); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -303,6 +325,12 @@ private <T> void getOperands(RexNode rn, Class<T> cls, Set<T> res) { | |
| } | ||
| } | ||
|
|
||
| /** Provides column origin for Subset relation. */ | ||
| public @Nullable Set<RelColumnOrigin> getColumnOrigins(RelSubset rel, | ||
| RelMetadataQuery mq, int outputColumn) { | ||
| return mq.getColumnOrigins(rel.stripped(), outputColumn); | ||
| } | ||
|
|
||
| /** | ||
| * Catch-all rule when none of the others apply. | ||
| * | ||
|
|
@@ -369,15 +397,15 @@ private static Set<RelColumnOrigin> getMultipleColumns(RexNode rexNode, RelNode | |
| final Set<RelColumnOrigin> set = new HashSet<>(); | ||
|
|
||
| final RexVisitor<Void> visitor = new RexVisitorImpl<Void>(true) { | ||
| @Override public Void visitInputRef(RexInputRef inputRef) { | ||
| Set<RelColumnOrigin> inputSet = mq.getColumnOrigins(input, inputRef.getIndex()); | ||
| @Override public Void visitInputRef(RexInputRef inputRef) { | ||
| Set<RelColumnOrigin> inputSet = mq.getColumnOrigins(input, inputRef.getIndex()); | ||
|
|
||
| if (inputSet != null) | ||
| set.addAll(inputSet); | ||
| if (inputSet != null) | ||
| set.addAll(inputSet); | ||
|
|
||
| return null; | ||
| } | ||
| }; | ||
| return null; | ||
| } | ||
| }; | ||
|
|
||
| rexNode.accept(visitor); | ||
|
|
||
|
|
||
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.
Looks like we can remove previous workaraund too
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.
done