Search in sources :

Example 6 with AssertRelNode

use of io.dingodb.calcite.assertion.AssertRelNode in project dingo by dingodb.

the class TestPhysicalPlan method testOffsetLimit.

@Test
public void testOffsetLimit() throws SqlParseException {
    String sql = "select * from test limit 3 offset 2";
    RelNode relNode = parse(sql);
    AssertRelNode assertSort = Assert.relNode(relNode).isA(EnumerableRoot.class).convention(EnumerableConvention.INSTANCE).singleInput();
    assertSort.isA(DingoSort.class).convention(DingoConventions.ROOT).singleInput().isA(DingoCoalesce.class).convention(DingoConventions.ROOT).singleInput().isA(DingoExchange.class).convention(DingoConventions.PARTITIONED).singleInput().isA(DingoPartScan.class).convention(DingoConventions.DISTRIBUTED);
    DingoSort dingoSort = (DingoSort) assertSort.getInstance();
    List<RelFieldCollation> collations = dingoSort.getCollation().getFieldCollations();
    assertThat(collations).isEmpty();
    assertThat(dingoSort.fetch).isNotNull();
    assertThat(RexLiteral.intValue(dingoSort.fetch)).isEqualTo(3);
    assertThat(dingoSort.offset).isNotNull();
    assertThat(RexLiteral.intValue(dingoSort.offset)).isEqualTo(2);
}
Also used : DingoSort(io.dingodb.calcite.rel.DingoSort) RelNode(org.apache.calcite.rel.RelNode) AssertRelNode(io.dingodb.calcite.assertion.AssertRelNode) DingoPartScan(io.dingodb.calcite.rel.DingoPartScan) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) DingoCoalesce(io.dingodb.calcite.rel.DingoCoalesce) AssertRelNode(io.dingodb.calcite.assertion.AssertRelNode) Test(org.junit.jupiter.api.Test)

Example 7 with AssertRelNode

use of io.dingodb.calcite.assertion.AssertRelNode in project dingo by dingodb.

the class TestPhysicalPlan method testSort.

@Test
public void testSort() throws SqlParseException {
    String sql = "select * from test order by name, amount desc";
    RelNode relNode = parse(sql);
    AssertRelNode assertSort = Assert.relNode(relNode).isA(EnumerableRoot.class).convention(EnumerableConvention.INSTANCE).singleInput();
    assertSort.isA(DingoSort.class).convention(DingoConventions.ROOT).singleInput().isA(DingoCoalesce.class).convention(DingoConventions.ROOT).singleInput().isA(DingoExchange.class).convention(DingoConventions.PARTITIONED).singleInput().isA(DingoPartScan.class).convention(DingoConventions.DISTRIBUTED);
    DingoSort dingoSort = (DingoSort) assertSort.getInstance();
    List<RelFieldCollation> collations = dingoSort.getCollation().getFieldCollations();
    assertThat(collations.get(0)).hasFieldOrPropertyWithValue("fieldIndex", 1).hasFieldOrPropertyWithValue("direction", ASCENDING).hasFieldOrPropertyWithValue("nullDirection", LAST);
    assertThat(collations.get(1)).hasFieldOrPropertyWithValue("fieldIndex", 2).hasFieldOrPropertyWithValue("direction", DESCENDING).hasFieldOrPropertyWithValue("nullDirection", FIRST);
    assertThat(dingoSort.fetch).isNull();
    assertThat(dingoSort.offset).isNull();
}
Also used : DingoSort(io.dingodb.calcite.rel.DingoSort) RelNode(org.apache.calcite.rel.RelNode) AssertRelNode(io.dingodb.calcite.assertion.AssertRelNode) DingoPartScan(io.dingodb.calcite.rel.DingoPartScan) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) DingoCoalesce(io.dingodb.calcite.rel.DingoCoalesce) AssertRelNode(io.dingodb.calcite.assertion.AssertRelNode) Test(org.junit.jupiter.api.Test)

Example 8 with AssertRelNode

use of io.dingodb.calcite.assertion.AssertRelNode in project dingo by dingodb.

the class TestPhysicalPlan method testAvg.

@Test
public void testAvg() throws SqlParseException {
    String sql = "select avg(amount) from test";
    RelNode relNode = parse(sql);
    AssertRelNode assertAgg = Assert.relNode(relNode).isA(EnumerableRoot.class).convention(EnumerableConvention.INSTANCE).singleInput().isA(DingoProject.class).convention(DingoConventions.ROOT).singleInput().isA(DingoReduce.class).convention(DingoConventions.ROOT).singleInput().isA(DingoExchange.class).convention(DingoConventions.PARTITIONED).singleInput().isA(DingoAggregate.class).convention(DingoConventions.DISTRIBUTED);
    DingoAggregate agg = (DingoAggregate) assertAgg.getInstance();
    assertThat(agg.getAggList()).map(Object::getClass).map(Class::getSimpleName).contains("SumAgg", "CountAgg");
    assertAgg.singleInput().isA(DingoPartScan.class).convention(DingoConventions.DISTRIBUTED);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) AssertRelNode(io.dingodb.calcite.assertion.AssertRelNode) EnumerableRoot(io.dingodb.calcite.rel.EnumerableRoot) DingoAggregate(io.dingodb.calcite.rel.DingoAggregate) DingoPartScan(io.dingodb.calcite.rel.DingoPartScan) DingoReduce(io.dingodb.calcite.rel.DingoReduce) AssertRelNode(io.dingodb.calcite.assertion.AssertRelNode) Test(org.junit.jupiter.api.Test)

Aggregations

AssertRelNode (io.dingodb.calcite.assertion.AssertRelNode)8 Test (org.junit.jupiter.api.Test)8 DingoPartScan (io.dingodb.calcite.rel.DingoPartScan)6 RelNode (org.apache.calcite.rel.RelNode)6 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)4 DingoAggregate (io.dingodb.calcite.rel.DingoAggregate)3 DingoCoalesce (io.dingodb.calcite.rel.DingoCoalesce)3 DingoReduce (io.dingodb.calcite.rel.DingoReduce)3 DingoSort (io.dingodb.calcite.rel.DingoSort)3 EnumerableRoot (io.dingodb.calcite.rel.EnumerableRoot)3 DingoTableScan (io.dingodb.calcite.rel.DingoTableScan)2 RelRoot (org.apache.calcite.rel.RelRoot)2 LogicalSort (org.apache.calcite.rel.logical.LogicalSort)2 NlsString (org.apache.calcite.util.NlsString)2