Search in sources :

Example 1 with IgniteLogicalTableScan

use of org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalTableScan in project ignite-3 by apache.

the class ExposeIndexRule method onMatch.

/**
 * {@inheritDoc}
 */
@Override
public void onMatch(RelOptRuleCall call) {
    IgniteLogicalTableScan scan = call.rel(0);
    RelOptCluster cluster = scan.getCluster();
    RelOptTable optTable = scan.getTable();
    InternalIgniteTable igniteTable = optTable.unwrap(InternalIgniteTable.class);
    List<RexNode> proj = scan.projects();
    RexNode condition = scan.condition();
    ImmutableBitSet requiredCols = scan.requiredColumns();
    List<IgniteLogicalIndexScan> indexes = igniteTable.indexes().keySet().stream().map(idxName -> igniteTable.toRel(cluster, optTable, idxName, proj, condition, requiredCols)).collect(Collectors.toList());
    if (indexes.isEmpty()) {
        return;
    }
    Map<RelNode, RelNode> equivMap = new HashMap<>(indexes.size());
    for (int i = 1; i < indexes.size(); i++) {
        equivMap.put(indexes.get(i), scan);
    }
    call.transformTo(indexes.get(0), equivMap);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) RelOptCluster(org.apache.calcite.plan.RelOptCluster) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) HashMap(java.util.HashMap) RelRule(org.apache.calcite.plan.RelRule) RelNode(org.apache.calcite.rel.RelNode) Collectors(java.util.stream.Collectors) RelOptRuleCall(org.apache.calcite.plan.RelOptRuleCall) RelOptTable(org.apache.calcite.plan.RelOptTable) RelOptRule(org.apache.calcite.plan.RelOptRule) List(java.util.List) IgniteLogicalIndexScan(org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalIndexScan) InternalIgniteTable(org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable) IgniteLogicalTableScan(org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalTableScan) RexNode(org.apache.calcite.rex.RexNode) Value(org.immutables.value.Value) Map(java.util.Map) InternalIgniteTable(org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) HashMap(java.util.HashMap) IgniteLogicalTableScan(org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalTableScan) RelNode(org.apache.calcite.rel.RelNode) IgniteLogicalIndexScan(org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalIndexScan) RelOptTable(org.apache.calcite.plan.RelOptTable) RexNode(org.apache.calcite.rex.RexNode)

Example 2 with IgniteLogicalTableScan

use of org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalTableScan in project ignite-3 by apache.

the class LogicalOrToUnionRule method buildInput.

private void buildInput(RelBuilder relBldr, RelNode input, RexNode condition) {
    IgniteLogicalTableScan scan = (IgniteLogicalTableScan) input;
    // Set default traits, real traits will be calculated for physical node.
    RelTraitSet trait = scan.getCluster().traitSet();
    relBldr.push(IgniteLogicalTableScan.create(scan.getCluster(), trait, scan.getTable(), scan.projects(), condition, scan.requiredColumns()));
}
Also used : IgniteLogicalTableScan(org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalTableScan) RelTraitSet(org.apache.calcite.plan.RelTraitSet)

Example 3 with IgniteLogicalTableScan

use of org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalTableScan in project ignite-3 by apache.

the class LogicalOrToUnionRule method idxCollationCheck.

/**
 * Compares intersection (currently beginning position) of condition and index fields.
 * This rule need to be triggered only if appropriate indexes will be found otherwise it`s not applicable.
 *
 * @param call Set of appropriate RelNode.
 * @param operands Operands from OR expression.
 */
private boolean idxCollationCheck(RelOptRuleCall call, List<RexNode> operands) {
    final IgniteLogicalTableScan scan = call.rel(0);
    InternalIgniteTable tbl = scan.getTable().unwrap(InternalIgniteTable.class);
    IgniteTypeFactory typeFactory = Commons.typeFactory(scan.getCluster());
    int fieldCnt = tbl.getRowType(typeFactory).getFieldCount();
    BitSet idxsFirstFields = new BitSet(fieldCnt);
    for (IgniteIndex idx : tbl.indexes().values()) {
        List<RelFieldCollation> fieldCollations = idx.collation().getFieldCollations();
        if (!CollectionUtils.nullOrEmpty(fieldCollations)) {
            idxsFirstFields.set(fieldCollations.get(0).getFieldIndex());
        }
    }
    Mappings.TargetMapping mapping = scan.requiredColumns() == null ? null : Commons.inverseMapping(scan.requiredColumns(), fieldCnt);
    for (RexNode op : operands) {
        BitSet conditionFields = new BitSet(fieldCnt);
        new RexShuttle() {

            @Override
            public RexNode visitLocalRef(RexLocalRef inputRef) {
                conditionFields.set(mapping == null ? inputRef.getIndex() : mapping.getSourceOpt(inputRef.getIndex()));
                return inputRef;
            }
        }.apply(op);
        if (!conditionFields.intersects(idxsFirstFields)) {
            return false;
        }
    }
    return true;
}
Also used : IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) RexShuttle(org.apache.calcite.rex.RexShuttle) InternalIgniteTable(org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteLogicalTableScan(org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalTableScan) BitSet(java.util.BitSet) Mappings(org.apache.calcite.util.mapping.Mappings) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) RexLocalRef(org.apache.calcite.rex.RexLocalRef) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

IgniteLogicalTableScan (org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalTableScan)3 RexNode (org.apache.calcite.rex.RexNode)2 InternalIgniteTable (org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable)2 BitSet (java.util.BitSet)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 RelOptRule (org.apache.calcite.plan.RelOptRule)1 RelOptRuleCall (org.apache.calcite.plan.RelOptRuleCall)1 RelOptTable (org.apache.calcite.plan.RelOptTable)1 RelRule (org.apache.calcite.plan.RelRule)1 RelTraitSet (org.apache.calcite.plan.RelTraitSet)1 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)1 RelNode (org.apache.calcite.rel.RelNode)1 RexLocalRef (org.apache.calcite.rex.RexLocalRef)1 RexShuttle (org.apache.calcite.rex.RexShuttle)1 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)1 Mappings (org.apache.calcite.util.mapping.Mappings)1