Search in sources :

Example 26 with CorrelationId

use of org.apache.calcite.rel.core.CorrelationId in project ignite by apache.

the class IgniteFilter method passThroughCorrelation.

/**
 */
@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, ImmutableList.of(inTraits.get(0).replace(correlation)));
    return null;
}
Also used : CorrelationTrait(org.apache.ignite.internal.processors.query.calcite.trait.CorrelationTrait) CorrelationId(org.apache.calcite.rel.core.CorrelationId)

Example 27 with CorrelationId

use of org.apache.calcite.rel.core.CorrelationId in project ignite 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());
    Set<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());
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) IgniteProject(org.apache.ignite.internal.processors.query.calcite.rel.IgniteProject) RelNode(org.apache.calcite.rel.RelNode) RelTraitSet(org.apache.calcite.plan.RelTraitSet) CorrelationId(org.apache.calcite.rel.core.CorrelationId)

Example 28 with CorrelationId

use of org.apache.calcite.rel.core.CorrelationId in project ignite by apache.

the class CorrelateToNestedLoopRule method convert.

/**
 * {@inheritDoc}
 */
@Override
protected PhysicalNode convert(RelOptPlanner planner, RelMetadataQuery mq, LogicalCorrelate rel) {
    final RelOptCluster cluster = rel.getCluster();
    final Set<CorrelationId> correlationIds = Collections.singleton(rel.getCorrelationId());
    CorrelationTrait corrTrait = CorrelationTrait.correlations(correlationIds);
    RelTraitSet outTraits = cluster.traitSetOf(IgniteConvention.INSTANCE);
    RelTraitSet leftInTraits = cluster.traitSetOf(IgniteConvention.INSTANCE);
    RelTraitSet rightInTraits = cluster.traitSetOf(IgniteConvention.INSTANCE).replace(RewindabilityTrait.REWINDABLE).replace(corrTrait);
    RelNode left = convert(rel.getLeft(), leftInTraits);
    RelNode right = convert(rel.getRight(), rightInTraits);
    return new IgniteCorrelatedNestedLoopJoin(cluster, outTraits, left, right, cluster.getRexBuilder().makeLiteral(true), correlationIds, rel.getJoinType());
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) CorrelationTrait(org.apache.ignite.internal.processors.query.calcite.trait.CorrelationTrait) RelNode(org.apache.calcite.rel.RelNode) CorrelationId(org.apache.calcite.rel.core.CorrelationId) RelTraitSet(org.apache.calcite.plan.RelTraitSet) IgniteCorrelatedNestedLoopJoin(org.apache.ignite.internal.processors.query.calcite.rel.IgniteCorrelatedNestedLoopJoin)

Example 29 with CorrelationId

use of org.apache.calcite.rel.core.CorrelationId in project ignite by apache.

the class FilterConverterRule method convert.

/**
 * {@inheritDoc}
 */
@Override
protected PhysicalNode convert(RelOptPlanner planner, RelMetadataQuery mq, LogicalFilter rel) {
    RelOptCluster cluster = rel.getCluster();
    RelTraitSet traits = cluster.traitSetOf(IgniteConvention.INSTANCE).replace(IgniteDistributions.single());
    Set<CorrelationId> corrIds = RexUtils.extractCorrelationIds(rel.getCondition());
    if (!corrIds.isEmpty()) {
        traits = traits.replace(CorrelationTrait.correlations(corrIds)).replace(RewindabilityTrait.REWINDABLE);
    }
    return new IgniteFilter(cluster, traits, convert(rel.getInput(), traits.replace(CorrelationTrait.UNCORRELATED)), rel.getCondition());
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) IgniteFilter(org.apache.ignite.internal.processors.query.calcite.rel.IgniteFilter) RelTraitSet(org.apache.calcite.plan.RelTraitSet) CorrelationId(org.apache.calcite.rel.core.CorrelationId)

Example 30 with CorrelationId

use of org.apache.calcite.rel.core.CorrelationId in project flink by splunk.

the class HiveParserRexNodeConverter method convertColumn.

private RexNode convertColumn(ExprNodeColumnDesc col) throws SemanticException {
    // if this is co-rrelated we need to make RexCorrelVariable(with id and type)
    // id and type should be retrieved from outerRR
    InputCtx ic = getInputCtx(col);
    if (ic == null) {
        // we have correlated column, build data type from outer rr
        RelDataType rowType = HiveParserTypeConverter.getType(cluster, this.outerRR, null);
        if (this.outerNameToPos.get(col.getColumn()) == null) {
            throw new SemanticException("Invalid column name " + col.getColumn());
        }
        int pos = this.outerNameToPos.get(col.getColumn());
        CorrelationId colCorr = new CorrelationId(this.correlatedId);
        RexNode corExpr = cluster.getRexBuilder().makeCorrel(rowType, colCorr);
        return cluster.getRexBuilder().makeFieldAccess(corExpr, pos);
    }
    int pos = ic.hiveNameToPosMap.get(col.getColumn());
    return cluster.getRexBuilder().makeInputRef(ic.calciteInpDataType.getFieldList().get(pos).getType(), pos + ic.offsetInCalciteSchema);
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType) CorrelationId(org.apache.calcite.rel.core.CorrelationId) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

CorrelationId (org.apache.calcite.rel.core.CorrelationId)74 RelNode (org.apache.calcite.rel.RelNode)39 RexNode (org.apache.calcite.rex.RexNode)33 RelDataType (org.apache.calcite.rel.type.RelDataType)25 ArrayList (java.util.ArrayList)22 RelOptCluster (org.apache.calcite.plan.RelOptCluster)19 RexBuilder (org.apache.calcite.rex.RexBuilder)18 RelBuilder (org.apache.calcite.tools.RelBuilder)17 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)15 ImmutableList (com.google.common.collect.ImmutableList)12 RelTraitSet (org.apache.calcite.plan.RelTraitSet)12 RexCorrelVariable (org.apache.calcite.rex.RexCorrelVariable)11 RexShuttle (org.apache.calcite.rex.RexShuttle)11 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)10 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)10 List (java.util.List)9 RelOptUtil (org.apache.calcite.plan.RelOptUtil)9 JoinRelType (org.apache.calcite.rel.core.JoinRelType)9 ByteString (org.apache.calcite.avatica.util.ByteString)7 SqlOperator (org.apache.calcite.sql.SqlOperator)7