Search in sources :

Example 71 with IgniteSchema

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

the class JoinColocationPlannerTest method joinSameTableComplexAff.

/**
 * Join of the same tables with a complex affinity is expected to be colocated.
 */
@Test
public void joinSameTableComplexAff() throws Exception {
    TestTable tbl = createTable("TEST_TBL", IgniteDistributions.affinity(ImmutableIntList.of(0, 1), ThreadLocalRandom.current().nextInt(), "hash"), "ID1", Integer.class, "ID2", Integer.class, "VAL", String.class);
    tbl.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(0, 1)), "PK", tbl));
    IgniteSchema schema = createSchema(tbl);
    String sql = "select count(*) " + "from TEST_TBL t1 " + "join TEST_TBL t2 on t1.id1 = t2.id1 and t1.id2 = t2.id2";
    RelNode phys = physicalPlan(sql, schema, "NestedLoopJoinConverter", "CorrelatedNestedLoopJoin");
    IgniteMergeJoin join = findFirstNode(phys, byClass(IgniteMergeJoin.class));
    String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
    assertThat(invalidPlanMsg, join, notNullValue());
    assertThat(invalidPlanMsg, join.distribution().function().affinity(), is(true));
    assertThat(invalidPlanMsg, join.getLeft(), instanceOf(IgniteIndexScan.class));
    assertThat(invalidPlanMsg, join.getRight(), instanceOf(IgniteIndexScan.class));
}
Also used : IgniteMergeJoin(org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin) IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) RelNode(org.apache.calcite.rel.RelNode) IgniteIndexScan(org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 72 with IgniteSchema

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

the class JoinColocationPlannerTest method joinComplexToSimpleAff.

/**
 * Re-hashing based on simple affinity is possible, so bigger table with complex affinity should be sended to the smaller one.
 */
@Test
public void joinComplexToSimpleAff() throws Exception {
    TestTable complexTbl = createTable("COMPLEX_TBL", 2 * DEFAULT_TBL_SIZE, IgniteDistributions.affinity(ImmutableIntList.of(0, 1), ThreadLocalRandom.current().nextInt(), "hash"), "ID1", Integer.class, "ID2", Integer.class, "VAL", String.class);
    complexTbl.addIndex(new IgniteIndex(RelCollations.of(ImmutableIntList.of(0, 1)), "PK", complexTbl));
    TestTable simpleTbl = createTable("SIMPLE_TBL", DEFAULT_TBL_SIZE, IgniteDistributions.affinity(0, "default", "hash"), "ID", Integer.class, "VAL", String.class);
    simpleTbl.addIndex(new IgniteIndex(RelCollations.of(0), "PK", simpleTbl));
    IgniteSchema schema = createSchema(complexTbl, simpleTbl);
    String sql = "select count(*) " + "from COMPLEX_TBL t1 " + "join SIMPLE_TBL t2 on t1.id1 = t2.id";
    RelNode phys = physicalPlan(sql, schema, "NestedLoopJoinConverter", "CorrelatedNestedLoopJoin");
    IgniteMergeJoin join = findFirstNode(phys, byClass(IgniteMergeJoin.class));
    String invalidPlanMsg = "Invalid plan:\n" + RelOptUtil.toString(phys);
    assertThat(invalidPlanMsg, join, notNullValue());
    assertThat(invalidPlanMsg, join.distribution().function().affinity(), is(true));
    List<IgniteExchange> exchanges = findNodes(phys, node -> node instanceof IgniteExchange && ((IgniteRel) node).distribution().function().affinity());
    assertThat(invalidPlanMsg, exchanges, hasSize(1));
    assertThat(invalidPlanMsg, exchanges.get(0).getInput(0), instanceOf(IgniteIndexScan.class));
    assertThat(invalidPlanMsg, exchanges.get(0).getInput(0).getTable().unwrap(TestTable.class), equalTo(complexTbl));
}
Also used : IgniteMergeJoin(org.apache.ignite.internal.sql.engine.rel.IgniteMergeJoin) IgniteIndex(org.apache.ignite.internal.sql.engine.schema.IgniteIndex) RelNode(org.apache.calcite.rel.RelNode) IgniteIndexScan(org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) IgniteExchange(org.apache.ignite.internal.sql.engine.rel.IgniteExchange) Test(org.junit.jupiter.api.Test)

Example 73 with IgniteSchema

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

the class LimitOffsetPlannerTest method testLimit.

@Test
public void testLimit() throws Exception {
    IgniteSchema publicSchema = createSchemaWithTable(IgniteDistributions.broadcast());
    String sql = "SELECT * FROM TEST OFFSET 10 ROWS FETCH FIRST 10 ROWS ONLY";
    assertPlan(sql, publicSchema, nodeOrAnyChild(isInstanceOf(IgniteLimit.class)).and(hasChildThat(isInstanceOf(IgniteSort.class)).negate()));
    sql = "SELECT * FROM TEST ORDER BY ID OFFSET 10 ROWS FETCH FIRST 10 ROWS ONLY";
    assertPlan(sql, publicSchema, nodeOrAnyChild(isInstanceOf(IgniteLimit.class).and(hasChildThat(isInstanceOf(IgniteSort.class)))));
}
Also used : IgniteLimit(org.apache.ignite.internal.sql.engine.rel.IgniteLimit) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 74 with IgniteSchema

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

the class SortAggregatePlannerTest method testNoSortAppendingWithCorrectCollation.

/**
 * Checks if already sorted input exist and involved [Map|Reduce]SortAggregate.
 */
@Test
public void testNoSortAppendingWithCorrectCollation() throws Exception {
    RelFieldCollation coll = new RelFieldCollation(1, RelFieldCollation.Direction.DESCENDING);
    TestTable tbl = createAffinityTable().addIndex(RelCollations.of(coll), "val0Idx");
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("TEST", tbl);
    String sql = "SELECT ID FROM test WHERE VAL0 IN (SELECT VAL0 FROM test)";
    IgniteRel phys = physicalPlan(sql, publicSchema, "NestedLoopJoinConverter", "CorrelatedNestedLoopJoin", "CorrelateToNestedLoopRule", "HashSingleAggregateConverterRule", "HashMapReduceAggregateConverterRule");
    assertTrue(findFirstNode(phys, byClass(IgniteSort.class)) == null && findFirstNode(phys, byClass(IgniteTableScan.class)) == null, "Invalid plan\n" + RelOptUtil.toString(phys));
}
Also used : IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) Test(org.junit.jupiter.api.Test)

Example 75 with IgniteSchema

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

the class SortedIndexSpoolPlannerTest method testNotColocatedEqJoin.

/**
 * Check equi-join on not colocated fields. CorrelatedNestedLoopJoinTest is applicable for this case only with
 * IndexSpool.
 */
@Test
public void testNotColocatedEqJoin() throws Exception {
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
    publicSchema.addTable("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");
        }
    }.addIndex(RelCollations.of(ImmutableIntList.of(1, 0)), "t0_jid_idx"));
    publicSchema.addTable("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");
        }
    }.addIndex(RelCollations.of(ImmutableIntList.of(1, 0)), "t1_jid_idx"));
    String sql = "select * " + "from t0 " + "join t1 on t0.jid = t1.jid";
    IgniteRel phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "NestedLoopJoinConverter", "FilterSpoolMergeToHashIndexSpoolRule");
    IgniteSortedIndexSpool idxSpool = findFirstNode(phys, byClass(IgniteSortedIndexSpool.class));
    List<RexNode> lowerBound = idxSpool.indexCondition().lowerBound();
    assertNotNull(lowerBound);
    assertEquals(3, lowerBound.size());
    assertTrue(((RexLiteral) lowerBound.get(0)).isNull());
    assertTrue(((RexLiteral) lowerBound.get(2)).isNull());
    assertTrue(lowerBound.get(1) instanceof RexFieldAccess);
    List<RexNode> upperBound = idxSpool.indexCondition().upperBound();
    assertNotNull(upperBound);
    assertEquals(3, upperBound.size());
    assertTrue(((RexLiteral) upperBound.get(0)).isNull());
    assertTrue(((RexLiteral) upperBound.get(2)).isNull());
    assertTrue(upperBound.get(1) instanceof RexFieldAccess);
}
Also used : IgniteSortedIndexSpool(org.apache.ignite.internal.sql.engine.rel.IgniteSortedIndexSpool) 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) RexFieldAccess(org.apache.calcite.rex.RexFieldAccess) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.jupiter.api.Test)

Aggregations

IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)115 Test (org.junit.jupiter.api.Test)105 IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)93 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)66 IgniteSort (org.apache.ignite.internal.sql.engine.rel.IgniteSort)42 RelCollation (org.apache.calcite.rel.RelCollation)33 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)28 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)20 RelNode (org.apache.calcite.rel.RelNode)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 IgniteIndex (org.apache.ignite.internal.sql.engine.schema.IgniteIndex)9 IgniteDistribution (org.apache.ignite.internal.sql.engine.trait.IgniteDistribution)9 SchemaPlus (org.apache.calcite.schema.SchemaPlus)8 RexFieldAccess (org.apache.calcite.rex.RexFieldAccess)7 PlanningContext (org.apache.ignite.internal.sql.engine.prepare.PlanningContext)7 IgniteIndexScan (org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan)7 RexNode (org.apache.calcite.rex.RexNode)6 MappingQueryContext (org.apache.ignite.internal.sql.engine.prepare.MappingQueryContext)6 MultiStepPlan (org.apache.ignite.internal.sql.engine.prepare.MultiStepPlan)6 MultiStepQueryPlan (org.apache.ignite.internal.sql.engine.prepare.MultiStepQueryPlan)6