Search in sources :

Example 1 with IndexConditions

use of org.apache.ignite.internal.sql.engine.util.IndexConditions in project ignite-3 by apache.

the class IgniteLogicalIndexScan method create.

/**
 * Creates a IgniteLogicalIndexScan.
 */
public static IgniteLogicalIndexScan create(RelOptCluster cluster, RelTraitSet traits, RelOptTable table, String idxName, @Nullable List<RexNode> proj, @Nullable RexNode cond, @Nullable ImmutableBitSet requiredColumns) {
    InternalIgniteTable tbl = table.unwrap(InternalIgniteTable.class);
    IgniteTypeFactory typeFactory = Commons.typeFactory(cluster);
    RelCollation collation = tbl.getIndex(idxName).collation();
    if (requiredColumns != null) {
        Mappings.TargetMapping targetMapping = Commons.mapping(requiredColumns, tbl.getRowType(typeFactory).getFieldCount());
        collation = collation.apply(targetMapping);
    }
    IndexConditions idxCond = new IndexConditions();
    if (collation != null && !collation.getFieldCollations().isEmpty()) {
        idxCond = RexUtils.buildSortedIndexConditions(cluster, collation, cond, tbl.getRowType(typeFactory), requiredColumns);
    }
    return new IgniteLogicalIndexScan(cluster, traits, table, idxName, proj, cond, idxCond, requiredColumns);
}
Also used : RelCollation(org.apache.calcite.rel.RelCollation) InternalIgniteTable(org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable) Mappings(org.apache.calcite.util.mapping.Mappings) IndexConditions(org.apache.ignite.internal.sql.engine.util.IndexConditions) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)

Example 2 with IndexConditions

use of org.apache.ignite.internal.sql.engine.util.IndexConditions in project ignite-3 by apache.

the class FilterSpoolMergeToSortedIndexSpoolRule method onMatch.

/**
 * {@inheritDoc}
 */
@Override
public void onMatch(RelOptRuleCall call) {
    final IgniteFilter filter = call.rel(0);
    final IgniteTableSpool spool = call.rel(1);
    RelOptCluster cluster = spool.getCluster();
    RelTraitSet trait = spool.getTraitSet();
    CorrelationTrait filterCorr = TraitUtils.correlation(filter);
    if (filterCorr.correlated()) {
        trait = trait.replace(filterCorr);
    }
    RelNode input = spool.getInput();
    IndexConditions idxCond = RexUtils.buildSortedIndexConditions(cluster, TraitUtils.collation(input), filter.getCondition(), spool.getRowType(), null);
    if (nullOrEmpty(idxCond.lowerCondition()) && nullOrEmpty(idxCond.upperCondition())) {
        return;
    }
    RelCollation collation = TraitUtils.createCollation(idxCond.keys());
    RelNode res = new IgniteSortedIndexSpool(cluster, trait.replace(collation), convert(input, input.getTraitSet().replace(collation)), collation, filter.getCondition(), idxCond);
    call.transformTo(res);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) IgniteSortedIndexSpool(org.apache.ignite.internal.sql.engine.rel.IgniteSortedIndexSpool) CorrelationTrait(org.apache.ignite.internal.sql.engine.trait.CorrelationTrait) RelCollation(org.apache.calcite.rel.RelCollation) RelNode(org.apache.calcite.rel.RelNode) IgniteFilter(org.apache.ignite.internal.sql.engine.rel.IgniteFilter) IgniteTableSpool(org.apache.ignite.internal.sql.engine.rel.IgniteTableSpool) IndexConditions(org.apache.ignite.internal.sql.engine.util.IndexConditions) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Aggregations

RelCollation (org.apache.calcite.rel.RelCollation)2 IndexConditions (org.apache.ignite.internal.sql.engine.util.IndexConditions)2 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 RelTraitSet (org.apache.calcite.plan.RelTraitSet)1 RelNode (org.apache.calcite.rel.RelNode)1 Mappings (org.apache.calcite.util.mapping.Mappings)1 IgniteFilter (org.apache.ignite.internal.sql.engine.rel.IgniteFilter)1 IgniteSortedIndexSpool (org.apache.ignite.internal.sql.engine.rel.IgniteSortedIndexSpool)1 IgniteTableSpool (org.apache.ignite.internal.sql.engine.rel.IgniteTableSpool)1 InternalIgniteTable (org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable)1 CorrelationTrait (org.apache.ignite.internal.sql.engine.trait.CorrelationTrait)1 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)1