Search in sources :

Example 6 with InternalIgniteTable

use of org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable 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

InternalIgniteTable (org.apache.ignite.internal.sql.engine.schema.InternalIgniteTable)6 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)4 RexNode (org.apache.calcite.rex.RexNode)3 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)3 RelDataType (org.apache.calcite.rel.type.RelDataType)2 Mappings (org.apache.calcite.util.mapping.Mappings)2 ScanNode (org.apache.ignite.internal.sql.engine.exec.rel.ScanNode)2 TableScanNode (org.apache.ignite.internal.sql.engine.exec.rel.TableScanNode)2 IgniteLogicalTableScan (org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalTableScan)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 RelCollation (org.apache.calcite.rel.RelCollation)1