use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema 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));
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema 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)));
}
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema 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);
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema 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());
}
use of org.apache.ignite.internal.sql.engine.schema.IgniteSchema in project ignite-3 by apache.
the class HashAggregatePlannerTest method noGroupByAggregate.
/**
* NoGroupByAggregate.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
@Test
public void noGroupByAggregate() throws Exception {
TestTable tbl = createAffinityTable().addIndex(RelCollations.of(ImmutableIntList.of(1, 2)), "val0_val1");
IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
publicSchema.addTable("TEST", tbl);
String sqlCount = "SELECT COUNT(*) FROM test";
IgniteRel phys = physicalPlan(sqlCount, publicSchema);
IgniteMapHashAggregate mapAgg = findFirstNode(phys, byClass(IgniteMapHashAggregate.class));
IgniteReduceHashAggregate rdcAgg = findFirstNode(phys, byClass(IgniteReduceHashAggregate.class));
assertNotNull(rdcAgg, "Invalid plan\n" + RelOptUtil.toString(phys));
assertNotNull(mapAgg, "Invalid plan\n" + RelOptUtil.toString(phys));
assertThat("Invalid plan\n" + RelOptUtil.toString(phys), first(rdcAgg.getAggregateCalls()).getAggregation(), IsInstanceOf.instanceOf(SqlCountAggFunction.class));
assertThat("Invalid plan\n" + RelOptUtil.toString(phys), first(mapAgg.getAggCallList()).getAggregation(), IsInstanceOf.instanceOf(SqlCountAggFunction.class));
}
Aggregations