use of org.apache.calcite.rel.RelDistribution.Type.HASH_DISTRIBUTED in project ignite-3 by apache.
the class AbstractIgniteJoin method passThroughDistribution.
/**
* {@inheritDoc}
*/
@Override
public Pair<RelTraitSet, List<RelTraitSet>> passThroughDistribution(RelTraitSet nodeTraits, List<RelTraitSet> inputTraits) {
// Tere are several rules:
// 1) any join is possible on broadcast or single distribution
// 2) hash distributed join is possible when join keys equal to source distribution keys
// 3) hash and broadcast distributed tables can be joined when join keys equal to hash
// distributed table distribution keys and:
// 3.1) it's a left join and a hash distributed table is at left
// 3.2) it's a right join and a hash distributed table is at right
// 3.3) it's an inner join, this case a hash distributed table may be at any side
RelTraitSet left = inputTraits.get(0);
RelTraitSet right = inputTraits.get(1);
IgniteDistribution distribution = TraitUtils.distribution(nodeTraits);
RelDistribution.Type distrType = distribution.getType();
switch(distrType) {
case BROADCAST_DISTRIBUTED:
case SINGLETON:
return Pair.of(nodeTraits, Commons.transform(inputTraits, t -> t.replace(distribution)));
case HASH_DISTRIBUTED:
case RANDOM_DISTRIBUTED:
// It's impossible to get random or hash distribution from a cross join.
if (nullOrEmpty(joinInfo.pairs())) {
break;
}
// We cannot provide random distribution without unique constrain on join keys,
// so, we require hash distribution (wich satisfies random distribution) instead.
DistributionFunction function = distrType == HASH_DISTRIBUTED ? distribution.function() : DistributionFunction.hash();
IgniteDistribution outDistr = hash(joinInfo.leftKeys, function);
if (distrType != HASH_DISTRIBUTED || outDistr.satisfies(distribution)) {
return Pair.of(nodeTraits.replace(outDistr), List.of(left.replace(outDistr), right.replace(hash(joinInfo.rightKeys, function))));
}
break;
default:
}
return Pair.of(nodeTraits.replace(single()), Commons.transform(inputTraits, t -> t.replace(single())));
}
Aggregations