Search in sources :

Example 1 with IgniteReduceHashAggregate

use of org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceHashAggregate 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));
}
Also used : IgniteRel(org.apache.ignite.internal.sql.engine.rel.IgniteRel) IgniteReduceHashAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceHashAggregate) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) IgniteMapHashAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapHashAggregate) SqlCountAggFunction(org.apache.calcite.sql.fun.SqlCountAggFunction) Test(org.junit.jupiter.api.Test)

Example 2 with IgniteReduceHashAggregate

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

the class HashAggregatePlannerTest method subqueryWithAggregate.

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

        @Override
        public IgniteDistribution distribution() {
            return IgniteDistributions.affinity(0, "Employers", "hash");
        }
    };
    IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
    publicSchema.addTable("EMPS", employer);
    String sql = "SELECT * FROM emps WHERE emps.salary = (SELECT AVG(emps.salary) FROM emps)";
    IgniteRel phys = physicalPlan(sql, publicSchema);
    assertNotNull(phys);
    IgniteReduceHashAggregate rdcAgg = findFirstNode(phys, byClass(IgniteReduceHashAggregate.class));
    IgniteMapHashAggregate mapAgg = findFirstNode(phys, byClass(IgniteMapHashAggregate.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(SqlAvgAggFunction.class));
    assertThat("Invalid plan\n" + RelOptUtil.toString(phys), first(mapAgg.getAggCallList()).getAggregation(), IsInstanceOf.instanceOf(SqlAvgAggFunction.class));
}
Also used : SqlAvgAggFunction(org.apache.calcite.sql.fun.SqlAvgAggFunction) 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) IgniteReduceHashAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceHashAggregate) IgniteSchema(org.apache.ignite.internal.sql.engine.schema.IgniteSchema) IgniteMapHashAggregate(org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapHashAggregate) Test(org.junit.jupiter.api.Test)

Aggregations

IgniteRel (org.apache.ignite.internal.sql.engine.rel.IgniteRel)2 IgniteMapHashAggregate (org.apache.ignite.internal.sql.engine.rel.agg.IgniteMapHashAggregate)2 IgniteReduceHashAggregate (org.apache.ignite.internal.sql.engine.rel.agg.IgniteReduceHashAggregate)2 IgniteSchema (org.apache.ignite.internal.sql.engine.schema.IgniteSchema)2 Test (org.junit.jupiter.api.Test)2 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)1 SqlAvgAggFunction (org.apache.calcite.sql.fun.SqlAvgAggFunction)1 SqlCountAggFunction (org.apache.calcite.sql.fun.SqlCountAggFunction)1 IgniteTypeFactory (org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory)1