Search in sources :

Example 56 with IgniteRel

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

the class AggregateDistinctPlannerTest method mapReduceDistinctWithIndex.

/**
 * MapReduceDistinctWithIndex.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 *
 * @throws Exception If failed.
 */
@ParameterizedTest
@EnumSource
public void mapReduceDistinctWithIndex(AggregateAlgorithm algo) throws Exception {
    TestTable tbl = createAffinityTable().addIndex(RelCollations.of(ImmutableIntList.of(1, 2)), "val0_val1");
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("TEST", tbl);
    String sql = "SELECT DISTINCT val0, val1 FROM test";
    IgniteRel phys = physicalPlan(sql, publicSchema, algo.rulesToDisable);
    IgniteAggregate mapAgg = findFirstNode(phys, byClass(algo.map));
    IgniteReduceAggregateBase rdcAgg = findFirstNode(phys, byClass(algo.reduce));
    assertNotNull(rdcAgg, "Invalid plan\n" + RelOptUtil.toString(phys, SqlExplainLevel.ALL_ATTRIBUTES));
    assertNotNull(mapAgg, "Invalid plan\n" + RelOptUtil.toString(phys));
    assertTrue(nullOrEmpty(rdcAgg.getAggregateCalls()), "Invalid plan\n" + RelOptUtil.toString(phys));
    assertTrue(nullOrEmpty(mapAgg.getAggCallList()), "Invalid plan\n" + RelOptUtil.toString(phys));
    if (algo == AggregateAlgorithm.SORT) {
        assertNotNull(findFirstNode(phys, byClass(IgniteIndexScan.class)));
    }
}
Also used : IgniteAggregate(org.apache.ignite.internal.sql.engine.rel.IgniteAggregate) IgniteReduceAggregateBase(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceAggregateBase) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 57 with IgniteRel

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

the class AggregatePlannerTest method expandDistinctAggregates.

/**
 * ExpandDistinctAggregates.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 *
 * @throws Exception If failed.
 */
@ParameterizedTest
@EnumSource
public void expandDistinctAggregates(AggregateAlgorithm algo) throws Exception {
    TestTable tbl = createAffinityTable().addIndex(RelCollations.of(ImmutableIntList.of(3, 1, 0)), "idx_val0").addIndex(RelCollations.of(ImmutableIntList.of(3, 2, 0)), "idx_val1");
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("TEST", tbl);
    String sql = "SELECT " + "/*+ EXPAND_DISTINCT_AGG */ " + "SUM(DISTINCT val0), AVG(DISTINCT val1) FROM test GROUP BY grp0";
    IgniteRel phys = physicalPlan(sql, publicSchema, algo.rulesToDisable);
    // Plan must not contain distinct accumulators.
    assertFalse(findNodes(phys, byClass(IgniteAggregate.class)).stream().anyMatch(n -> ((Aggregate) n).getAggCallList().stream().anyMatch(AggregateCall::isDistinct)), "Invalid plan\n" + RelOptUtil.toString(phys, SqlExplainLevel.ALL_ATTRIBUTES));
    assertNotNull(findFirstNode(phys, byClass(Join.class)), "Invalid plan\n" + RelOptUtil.toString(phys, SqlExplainLevel.ALL_ATTRIBUTES));
    // Check the first aggrgation step is SELECT DISTINCT (doesn't contains any accumulators)
    assertTrue(findNodes(phys, byClass(algo.reduce)).stream().allMatch(n -> ((IgniteReduceAggregateBase) n).getAggregateCalls().isEmpty()), "Invalid plan\n" + RelOptUtil.toString(phys, SqlExplainLevel.ALL_ATTRIBUTES));
    assertTrue(findNodes(phys, byClass(algo.map)).stream().allMatch(n -> ((Aggregate) n).getAggCallList().isEmpty()), "Invalid plan\n" + RelOptUtil.toString(phys, SqlExplainLevel.ALL_ATTRIBUTES));
    // Check the second aggrgation step contains accumulators.
    assertTrue(findNodes(phys, byClass(algo.single)).stream().noneMatch(n -> ((Aggregate) n).getAggCallList().isEmpty()), "Invalid plan\n" + RelOptUtil.toString(phys, SqlExplainLevel.ALL_ATTRIBUTES));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) IgniteSort(org.apache.ignite.internal.sql.engine.rel.IgniteSort) EnumSource(org.junit.jupiter.params.provider.EnumSource) SqlAvgAggFunction(org.apache.calcite.sql.fun.SqlAvgAggFunction) IgniteSingleAggregateBase(org.apache.ignite.internal.sql.engine.rel.agg.IgniteSingleAggregateBase) IgniteSingleSortAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteSingleSortAggregate) IgniteAggregate(org.apache.ignite.internal.sql.engine.rel.IgniteAggregate) RelOptUtil(org.apache.calcite.plan.RelOptUtil) Join(org.apache.calcite.rel.core.Join) IgniteIndexScan(org.apache.ignite.internal.sql.engine.rel.IgniteIndexScan) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) IgniteMapAggregateBase(org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapAggregateBase) IgniteReduceSortAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceSortAggregate) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArrayUtils.concat(org.apache.ignite.internal.util.ArrayUtils.concat) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IsInstanceOf(org.hamcrest.core.IsInstanceOf) RelCollations(org.apache.calcite.rel.RelCollations) IgniteDistributions(org.apache.ignite.internal.sql.engine.trait.IgniteDistributions) ImmutableIntList(org.apache.calcite.util.ImmutableIntList) SqlExplainLevel(org.apache.calcite.sql.SqlExplainLevel) Aggregate(org.apache.calcite.rel.core.Aggregate) IgniteMapSortAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapSortAggregate) IgniteReduceHashAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceHashAggregate) IgniteReduceAggregateBase(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceAggregateBase) TraitUtils(org.apache.ignite.internal.sql.engine.trait.TraitUtils) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AggregateCall(org.apache.calcite.rel.core.AggregateCall) IgniteMapHashAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapHashAggregate) CollectionUtils.first(org.apache.ignite.internal.util.CollectionUtils.first) IgniteSingleHashAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteSingleHashAggregate) AggregateCall(org.apache.calcite.rel.core.AggregateCall) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) IgniteSingleSortAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteSingleSortAggregate) IgniteAggregate(org.apache.ignite.internal.sql.engine.rel.IgniteAggregate) IgniteReduceSortAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceSortAggregate) Aggregate(org.apache.calcite.rel.core.Aggregate) IgniteMapSortAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapSortAggregate) IgniteReduceHashAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceHashAggregate) IgniteMapHashAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapHashAggregate) IgniteSingleHashAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteSingleHashAggregate) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 58 with IgniteRel

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

the class AggregatePlannerTest method singleWithoutIndex.

/**
 * SingleWithoutIndex.
 * TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
 *
 * @throws Exception If failed.
 */
@ParameterizedTest
@EnumSource
public void singleWithoutIndex(AggregateAlgorithm algo) throws Exception {
    TestTable tbl = createBroadcastTable().addIndex(RelCollations.of(ImmutableIntList.of(1, 2)), "val0_val1");
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("TEST", tbl);
    String sql = "SELECT AVG(val0) FROM test GROUP BY grp0";
    IgniteRel phys = physicalPlan(sql, publicSchema, algo.rulesToDisable);
    IgniteSingleAggregateBase agg = findFirstNode(phys, byClass(algo.single));
    assertNotNull(agg, "Invalid plan\n" + RelOptUtil.toString(phys));
    assertThat("Invalid plan\n" + RelOptUtil.toString(phys), first(agg.getAggCallList()).getAggregation(), IsInstanceOf.instanceOf(SqlAvgAggFunction.class));
    if (algo == AggregateAlgorithm.SORT) {
        assertNotNull(findFirstNode(phys, byClass(IgniteSort.class)));
    }
}
Also used : SqlAvgAggFunction(org.apache.calcite.sql.fun.SqlAvgAggFunction) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSingleAggregateBase(org.apache.ignite.internal.sql.engine.rel.agg.IgniteSingleAggregateBase) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 59 with IgniteRel

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

the class CorrelatedNestedLoopJoinPlannerTest method testInvalidIndexExpressions.

/**
 * Check join with not equi condition. Current implementation of the CorrelatedNestedLoopJoinTest is not applicable
 * for such case.
 */
@Test
public void testInvalidIndexExpressions() 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.broadcast();
        }
    }.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.broadcast();
        }
    }.addIndex(RelCollations.of(ImmutableIntList.of(1, 0)), "t1_jid_idx"));
    String sql = "select * " + "from t0 " + "join t1 on t0.jid + 2 > t1.jid * 2";
    IgniteRel phys = physicalPlan(sql, publicSchema, "MergeJoinConverter", "NestedLoopJoinConverter", "FilterSpoolMergeRule");
    assertNotNull(phys);
}
Also used : 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 60 with IgniteRel

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

the class CorrelatedSubqueryPlannerTest method test.

/**
 * Test verifies the row type is consistent for correlation variable and
 * node that actually puts this variable into a context.
 *
 * <p>In this particular test the row type of the left input of CNLJ node should
 * match the row type correlated variable in the filter was created with.
 *
 * @throws Exception In case of any unexpected error.
 */
@Test
public void test() throws Exception {
    IgniteSchema schema = createSchema(createTable("T1", IgniteDistributions.single(), "A", Integer.class, "B", Integer.class, "C", Integer.class, "D", Integer.class, "E", Integer.class));
    String sql = "" + "SELECT (SELECT count(*) FROM t1 AS x WHERE x.b<t1.b)\n" + "  FROM t1\n" + " WHERE (a>e-2 AND a<e+2)\n" + "    OR c>d\n" + " ORDER BY 1;";
    IgniteRel rel = physicalPlan(sql, schema, "FilterTableScanMergeRule");
    IgniteFilter filter = findFirstNode(rel, byClass(IgniteFilter.class).and(f -> RexUtils.hasCorrelation(((Filter) f).getCondition())));
    RexFieldAccess fieldAccess = findFirst(filter.getCondition(), RexFieldAccess.class);
    assertNotNull(fieldAccess);
    assertEquals(RexCorrelVariable.class, fieldAccess.getReferenceExpr().getClass());
    IgniteCorrelatedNestedLoopJoin join = findFirstNode(rel, byClass(IgniteCorrelatedNestedLoopJoin.class));
    assertEquals(fieldAccess.getReferenceExpr().getType(), join.getLeft().getRowType());
}
Also used : IgniteDistributions(org.apache.ignite.internal.sql.engine.trait.IgniteDistributions) RexUtils(org.apache.ignite.internal.sql.engine.util.RexUtils) Test(org.junit.jupiter.api.Test) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) RexFieldAccess(org.apache.calcite.rex.RexFieldAccess) IgniteCorrelatedNestedLoopJoin(org.apache.ignite.internal.sql.engine.rel.IgniteCorrelatedNestedLoopJoin) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) IgniteFilter(org.apache.ignite.internal.sql.engine.rel.IgniteFilter) RexCorrelVariable(org.apache.calcite.rex.RexCorrelVariable) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Filter(org.apache.calcite.rel.core.Filter) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteFilter(org.apache.ignite.internal.sql.engine.rel.IgniteFilter) IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) IgniteCorrelatedNestedLoopJoin(org.apache.ignite.internal.sql.engine.rel.IgniteCorrelatedNestedLoopJoin) RexFieldAccess(org.apache.calcite.rex.RexFieldAccess) Test(org.junit.jupiter.api.Test)

Aggregations

IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)102 IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)93 Test (org.junit.jupiter.api.Test)89 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)64 IgniteSort (org.apache.ignite.internal.sql.engine.rel.IgniteSort)39 RelCollation (org.apache.calcite.rel.RelCollation)33 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)19 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)16 PlanningContext (org.apache.ignite.internal.sql.engine.prepare.PlanningContext)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 RexFieldAccess (org.apache.calcite.rex.RexFieldAccess)7 RexNode (org.apache.calcite.rex.RexNode)7 SchemaPlus (org.apache.calcite.schema.SchemaPlus)7 IgniteDistribution (org.apache.ignite.internal.sql.engine.trait.IgniteDistribution)7 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 QueryTemplate (org.apache.ignite.internal.sql.engine.prepare.QueryTemplate)6 Splitter (org.apache.ignite.internal.sql.engine.prepare.Splitter)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6