korlov42 commented on a change in pull request #9143:
URL: https://github.com/apache/ignite/pull/9143#discussion_r680949704
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteMergeJoin.java
##########
@@ -162,79 +176,297 @@ else if (isPrefix(rightCollation.getKeys(),
joinInfo.rightKeys))// preserve righ
/** {@inheritDoc} */
@Override public Pair<RelTraitSet, List<RelTraitSet>> passThroughCollation(
- RelTraitSet nodeTraits,
+ RelTraitSet required,
List<RelTraitSet> inputTraits
) {
- RelCollation collation = TraitUtils.collation(nodeTraits);
- RelTraitSet left = inputTraits.get(0), right = inputTraits.get(1);
+ // Required collation keys can be subset or superset of merge join
keys.
+ RelCollation collation = TraitUtils.collation(required);
+ int leftInputFieldCount = left.getRowType().getFieldCount();
- int rightOff = this.left.getRowType().getFieldCount();
+ List<Integer> reqKeys = RelCollations.ordinals(collation);
+ List<Integer> leftKeys = joinInfo.leftKeys.toIntegerList();
+ List<Integer> rightKeys =
+ joinInfo.rightKeys.incr(leftInputFieldCount).toIntegerList();
- Map<Integer, Integer> rightToLeft = joinInfo.pairs().stream()
- .collect(Collectors.toMap(p -> p.target, p -> p.source));
+ ImmutableBitSet reqKeySet = ImmutableBitSet.of(reqKeys);
+ ImmutableBitSet leftKeySet = ImmutableBitSet.of(joinInfo.leftKeys);
+ ImmutableBitSet rightKeySet = ImmutableBitSet.of(joinInfo.rightKeys)
+ .shift(leftInputFieldCount);
- List<Integer> collationLeftPrj = new ArrayList<>();
+ if (reqKeySet.equals(leftKeySet)) {
+ // if sort keys equal to left join keys, we can pass through all
collations directly.
+ Pair<RelTraitSet, List<RelTraitSet>> transformedCollations =
transformCollations(required, leftInputFieldCount);
- for (Integer c : collation.getKeys()) {
- collationLeftPrj.add(
- c >= rightOff ? rightToLeft.get(c - rightOff) : c
- );
+ if (transformedCollations != null)
+ return transformedCollations;
+
+ Mappings.TargetMapping mapping = buildProjectionMapping(true);
+ RelCollation rightCollation = collation.apply(mapping);
+
+ if (debugOutput)
+ System.err.println("1 " + TraitUtils.collation(required) + "
l: " +
+ TraitUtils.collation(required) + " r: " + rightCollation);
+
+ return Pair.of(
+ required, ImmutableList.of(required,
required.replace(rightCollation)));
Review comment:
you can't just pass required traits for every input
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]