Search in sources :

Example 11 with IgniteIndex

use of org.apache.ignite.internal.sql.engine.schema.IgniteIndex in project ignite-3 by apache.

the class TableDmlPlannerTest method updateCachesDependentIndexScan.

/**
 * UpdateCachesDependentIndexScan.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 *
 * @throws Exception If failed.
 */
@Test
public void updateCachesDependentIndexScan() throws Exception {
    TestTable tbl = createTable("TEST", IgniteDistributions.random(), "VAL", Integer.class);
    tbl.addIndex(new IgniteIndex(RelCollations.of(0), "IDX", tbl));
    IgniteSchema schema = createSchema(tbl);
    String sql = "update test set val = 2 * val where val between 2 and 10";
    RelNode phys = physicalPlan(sql, schema, "LogicalTableScanConverterRule");
    assertNotNull(phys);
    String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
    IgniteTableModify modifyNode = findFirstNode(phys, byClass(IgniteTableModify.class));
    assertThat(invalidPlanMsg, modifyNode, notNullValue());
    assertThat(invalidPlanMsg, modifyNode.getInput(), instanceOf(Spool.class));
    Spool spool = (Spool) modifyNode.getInput();
    assertThat(invalidPlanMsg, spool.readType, equalTo(Spool.Type.EAGER));
    assertThat(invalidPlanMsg, findFirstNode(phys, byClass(IgniteIndexScan.class)), notNullValue());
}
Also used : IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) RelNode(org.apache.calcite.rel.RelNode) IgniteTableModify(org.apache.ignite.internal.sql.engine.rel.IgniteTableModify) Spool(org.apache.calcite.rel.core.Spool) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 12 with IgniteIndex

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

IgniteIndex (org.apache.ignite.internal.sql.engine.schema.IgniteIndex)12 IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)11 Test (org.junit.jupiter.api.Test)11 RelNode (org.apache.calcite.rel.RelNode)8 IgniteIndexScan (org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan)5 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)5 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)4 IgniteMergeJoin (org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin)4 IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 RelCollations (org.apache.calcite.rel.RelCollations)2 Spool (org.apache.calcite.rel.core.Spool)2 RelDataType (org.apache.calcite.rel.type.RelDataType)2 SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)2 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)2 IgniteAggregate (org.apache.ignite.internal.sql.engine.rel.IgniteAggregate)2 IgniteExchange (org.apache.ignite.internal.sql.engine.rel.IgniteExchange)2 IgniteTableModify (org.apache.ignite.internal.sql.engine.rel.IgniteTableModify)2 IgniteTableScan (org.apache.ignite.internal.sql.engine.rel.IgniteTableScan)2 IgniteDistributions (org.apache.ignite.internal.sql.engine.trait.IgniteDistributions)2