Search in sources :

Example 1 with IgniteTableSpool

use of org.apache.ignite.internal.sql.engine.rel.IgniteTableSpool 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)

Example 2 with IgniteTableSpool

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

the class FilterSpoolMergeToHashIndexSpoolRule 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);
    }
    final RelNode input = spool.getInput();
    List<RexNode> searchRow = RexUtils.buildHashSearchRow(cluster, filter.getCondition(), spool.getRowType());
    if (nullOrEmpty(searchRow)) {
        return;
    }
    RelNode res = new IgniteHashIndexSpool(cluster, trait.replace(RelCollations.EMPTY), input, searchRow, filter.getCondition());
    call.transformTo(res);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) CorrelationTrait(org.apache.ignite.internal.sql.engine.trait.CorrelationTrait) RelNode(org.apache.calcite.rel.RelNode) IgniteFilter(org.apache.ignite.internal.sql.engine.rel.IgniteFilter) IgniteTableSpool(org.apache.ignite.internal.sql.engine.rel.IgniteTableSpool) IgniteHashIndexSpool(org.apache.ignite.internal.sql.engine.rel.IgniteHashIndexSpool) RelTraitSet(org.apache.calcite.plan.RelTraitSet) RexNode(org.apache.calcite.rex.RexNode)

Example 3 with IgniteTableSpool

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

the class TableSpoolPlannerTest method tableSpoolDistributed.

/**
 * TableSpoolDistributed.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 *
 * @throws Exception If failed.
 */
@Test
public void tableSpoolDistributed() throws Exception {
    IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
    TestTable t0 = new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("JID", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build()) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.affinity(0, "T0", "hash");
        }
    };
    TestTable t1 = new TestTable(new RelDataTypeFactory.Builder(f).add("ID", f.createJavaType(Integer.class)).add("JID", f.createJavaType(Integer.class)).add("VAL", f.createJavaType(String.class)).build()) {

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.affinity(0, "T1", "hash");
        }
    };
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("T0", t0);
    publicSchema.addTable("T1", t1);
    String sql = "select * " + "from t0 " + "join t1 on t0.jid > t1.jid";
    IgniteRel phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "NestedLoopJoinConverter", "FilterSpoolMergeRule");
    assertNotNull(phys);
    IgniteTableSpool tblSpool = findFirstNode(phys, byClass(IgniteTableSpool.class));
    assertNotNull(tblSpool, "Invalid plan:\n" + RelOptUtil.toString(phys));
    checkSplitAndSerialization(phys, publicSchema);
}
Also used : IgniteTableSpool(org.apache.ignite.internal.sql.engine.rel.IgniteTableSpool) IgniteTypeFactory(org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 4 with IgniteTableSpool

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

the class TraitUtils method convertRewindability.

/**
 * Convert rewindability. TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 */
@Nullable
public static RelNode convertRewindability(RewindabilityTrait toTrait, RelNode rel) {
    RewindabilityTrait fromTrait = rewindability(rel);
    if (fromTrait.satisfies(toTrait)) {
        return rel;
    }
    RelTraitSet traits = rel.getTraitSet().replace(toTrait).replace(CorrelationTrait.UNCORRELATED);
    return new IgniteTableSpool(rel.getCluster(), traits, Spool.Type.LAZY, RelOptRule.convert(rel, rel.getTraitSet().replace(CorrelationTrait.UNCORRELATED)));
}
Also used : IgniteTableSpool(org.apache.ignite.internal.sql.engine.rel.IgniteTableSpool) RelTraitSet(org.apache.calcite.plan.RelTraitSet) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IgniteTableSpool (org.apache.ignite.internal.sql.engine.rel.IgniteTableSpool)4 RelTraitSet (org.apache.calcite.plan.RelTraitSet)3 RelOptCluster (org.apache.calcite.plan.RelOptCluster)2 RelNode (org.apache.calcite.rel.RelNode)2 IgniteFilter (org.apache.ignite.internal.sql.engine.rel.IgniteFilter)2 CorrelationTrait (org.apache.ignite.internal.sql.engine.trait.CorrelationTrait)2 RelCollation (org.apache.calcite.rel.RelCollation)1 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)1 RexNode (org.apache.calcite.rex.RexNode)1 IgniteHashIndexSpool (org.apache.ignite.internal.sql.engine.rel.IgniteHashIndexSpool)1 IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)1 IgniteSortedIndexSpool (org.apache.ignite.internal.sql.engine.rel.IgniteSortedIndexSpool)1 IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)1 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)1 IndexConditions (org.apache.ignite.internal.sql.engine.util.IndexConditions)1 Nullable (org.jetbrains.annotations.Nullable)1 Test (org.junit.jupiter.api.Test)1