use of org.apache.calcite.rel.core.CorrelationId in project beam by apache.
the class ArrayScanColumnRefToUncollect method convert.
@Override
public RelNode convert(ResolvedNodes.ResolvedArrayScan zetaNode, List<RelNode> inputs) {
assert inputs.size() == 1;
RelNode input = inputs.get(0);
RexInputRef columnRef = (RexInputRef) getExpressionConverter().convertRexNodeFromResolvedExpr(getColumnRef(zetaNode.getArrayExpr()), zetaNode.getInputScan().getColumnList(), input.getRowType().getFieldList(), ImmutableMap.of());
CorrelationId correlationId = new CorrelationId(0);
RexNode convertedColumnRef = getCluster().getRexBuilder().makeFieldAccess(getCluster().getRexBuilder().makeCorrel(input.getRowType(), correlationId), columnRef.getIndex());
String fieldName = String.format("%s%s", zetaNode.getElementColumn().getTableName(), zetaNode.getElementColumn().getName());
RelNode projectNode = LogicalProject.create(createOneRow(getCluster()), ImmutableList.of(), Collections.singletonList(convertArrayExpr(zetaNode.getArrayExpr(), getCluster().getRexBuilder(), convertedColumnRef)), ImmutableList.of(fieldName));
boolean ordinality = (zetaNode.getArrayOffsetColumn() != null);
RelNode uncollect = ZetaSqlUnnest.create(projectNode.getTraitSet(), projectNode, ordinality);
return LogicalCorrelate.create(input, uncollect, correlationId, ImmutableBitSet.of(columnRef.getIndex()), JoinRelType.INNER);
}
use of org.apache.calcite.rel.core.CorrelationId in project ignite-3 by apache.
the class CorrelatedNestedLoopJoinRule method convert.
@Override
protected PhysicalNode convert(RelOptPlanner planner, RelMetadataQuery mq, LogicalJoin rel) {
final int leftFieldCount = rel.getLeft().getRowType().getFieldCount();
final RelOptCluster cluster = rel.getCluster();
final RexBuilder rexBuilder = cluster.getRexBuilder();
final RelBuilder relBuilder = relBuilderFactory.create(rel.getCluster(), null);
final Set<CorrelationId> correlationIds = new HashSet<>();
final ArrayList<RexNode> corrVar = new ArrayList<>();
for (int i = 0; i < batchSize; i++) {
CorrelationId correlationId = cluster.createCorrel();
correlationIds.add(correlationId);
corrVar.add(rexBuilder.makeCorrel(rel.getLeft().getRowType(), correlationId));
}
// Generate first condition
final RexNode condition = rel.getCondition().accept(new RexShuttle() {
@Override
public RexNode visitInputRef(RexInputRef input) {
int field = input.getIndex();
if (field >= leftFieldCount) {
return rexBuilder.makeInputRef(input.getType(), input.getIndex() - leftFieldCount);
}
return rexBuilder.makeFieldAccess(corrVar.get(0), field);
}
});
List<RexNode> conditionList = new ArrayList<>();
conditionList.add(condition);
// Add batchSize-1 other conditions
for (int i = 1; i < batchSize; i++) {
final int corrIndex = i;
final RexNode condition2 = condition.accept(new RexShuttle() {
@Override
public RexNode visitCorrelVariable(RexCorrelVariable variable) {
return corrVar.get(corrIndex);
}
});
conditionList.add(condition2);
}
RelTraitSet filterInTraits = rel.getRight().getTraitSet();
// Push a filter with batchSize disjunctions
relBuilder.push(rel.getRight().copy(filterInTraits, rel.getRight().getInputs())).filter(relBuilder.or(conditionList));
RelNode right = relBuilder.build();
JoinRelType joinType = rel.getJoinType();
RelTraitSet outTraits = cluster.traitSetOf(IgniteConvention.INSTANCE);
RelTraitSet leftInTraits = cluster.traitSetOf(IgniteConvention.INSTANCE);
CorrelationTrait corrTrait = CorrelationTrait.correlations(correlationIds);
RelTraitSet rightInTraits = cluster.traitSetOf(IgniteConvention.INSTANCE).replace(RewindabilityTrait.REWINDABLE).replace(corrTrait);
RelNode left = convert(rel.getLeft(), leftInTraits);
right = convert(right, rightInTraits);
return new IgniteCorrelatedNestedLoopJoin(cluster, outTraits, left, right, rel.getCondition(), correlationIds, joinType);
}
use of org.apache.calcite.rel.core.CorrelationId in project ignite-3 by apache.
the class IgniteFilter method passThroughCorrelation.
/**
* PassThroughCorrelation.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
@Override
public Pair<RelTraitSet, List<RelTraitSet>> passThroughCorrelation(RelTraitSet nodeTraits, List<RelTraitSet> inTraits) {
Set<CorrelationId> corrSet = RexUtils.extractCorrelationIds(getCondition());
CorrelationTrait correlation = TraitUtils.correlation(nodeTraits);
if (corrSet.isEmpty() || correlation.correlationIds().containsAll(corrSet)) {
return Pair.of(nodeTraits, List.of(inTraits.get(0).replace(correlation)));
}
return null;
}
use of org.apache.calcite.rel.core.CorrelationId in project ignite-3 by apache.
the class IgniteMdCumulativeCost method getCumulativeCost.
/**
* GetCumulativeCost.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
public RelOptCost getCumulativeCost(IgniteCorrelatedNestedLoopJoin rel, RelMetadataQuery mq) {
RelOptCost cost = nonCumulativeCost(rel, mq);
if (cost.isInfinite()) {
return cost;
}
RelNode left = rel.getLeft();
RelNode right = rel.getRight();
Set<CorrelationId> corIds = rel.getVariablesSet();
RelOptCost leftCost = mq.getCumulativeCost(left);
if (leftCost.isInfinite()) {
return leftCost;
}
RelOptCost rightCost = mq.getCumulativeCost(right);
if (rightCost.isInfinite()) {
return rightCost;
}
return cost.plus(leftCost).plus(rightCost.multiplyBy(left.estimateRowCount(mq) / corIds.size()));
}
use of org.apache.calcite.rel.core.CorrelationId in project ignite-3 by apache.
the class ProjectConverterRule method convert.
/**
* {@inheritDoc}
*/
@Override
protected PhysicalNode convert(RelOptPlanner planner, RelMetadataQuery mq, LogicalProject rel) {
RelOptCluster cluster = rel.getCluster();
RelTraitSet traits = cluster.traitSetOf(IgniteConvention.INSTANCE).replace(IgniteDistributions.single());
Collection<CorrelationId> corrIds = RexUtils.extractCorrelationIds(rel.getProjects());
if (!corrIds.isEmpty()) {
traits = traits.replace(CorrelationTrait.correlations(corrIds)).replace(RewindabilityTrait.REWINDABLE);
}
RelNode input = convert(rel.getInput(), traits);
return new IgniteProject(cluster, traits, input, rel.getProjects(), rel.getRowType());
}
Aggregations