Search in sources :

Example 1 with AssertRelNode

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

the class TestLogicalPlan method testSort.

@Test
public void testSort() throws SqlParseException {
    String sql = "select * from test order by name, amount desc";
    RelRoot relRoot = parse(sql);
    AssertRelNode assertSort = Assert.relNode(relRoot.rel);
    assertSort.isA(LogicalSort.class).convention(Convention.NONE).singleInput().isA(LogicalProject.class).convention(Convention.NONE).singleInput().isA(DingoTableScan.class).convention(DingoConventions.DINGO);
    LogicalSort logicalSort = (LogicalSort) assertSort.getInstance();
    List<RelFieldCollation> collations = logicalSort.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(logicalSort.fetch).isNull();
    assertThat(logicalSort.offset).isNull();
}
Also used : RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) DingoTableScan(io.dingodb.calcite.rel.DingoTableScan) RelRoot(org.apache.calcite.rel.RelRoot) NlsString(org.apache.calcite.util.NlsString) AssertRelNode(io.dingodb.calcite.assertion.AssertRelNode) LogicalSort(org.apache.calcite.rel.logical.LogicalSort) Test(org.junit.jupiter.api.Test)

Example 2 with AssertRelNode

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

the class TestPhysicalPlan method testAvg2.

@Test
public void testAvg2() throws SqlParseException {
    String sql = "select name, avg(id), avg(amount) from test group by name";
    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)

Example 3 with AssertRelNode

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

the class TestPhysicalPlan method testSortLimit.

@Test
public void testSortLimit() throws SqlParseException {
    String sql = "select * from test order by name limit 3";
    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(dingoSort.fetch).isNotNull();
    assertThat(RexLiteral.intValue(dingoSort.fetch)).isEqualTo(3);
    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 4 with AssertRelNode

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

the class TestPhysicalPlan method testAvg1.

@Test
public void testAvg1() throws SqlParseException {
    String sql = "select name, avg(amount) from test group by name";
    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)

Example 5 with AssertRelNode

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

the class TestLogicalPlan method testLimitOffset.

@Test
public void testLimitOffset() throws SqlParseException {
    String sql = "select * from test limit 3 offset 2";
    RelRoot relRoot = parse(sql);
    AssertRelNode assertSort = Assert.relNode(relRoot.rel);
    assertSort.isA(LogicalSort.class).convention(Convention.NONE).singleInput().isA(LogicalProject.class).convention(Convention.NONE).singleInput().isA(DingoTableScan.class).convention(DingoConventions.DINGO);
    LogicalSort logicalSort = (LogicalSort) assertSort.getInstance();
    assertThat(logicalSort.fetch).isNotNull();
    assertThat(RexLiteral.intValue(logicalSort.fetch)).isEqualTo(3);
    assertThat(logicalSort.offset).isNotNull();
    assertThat(RexLiteral.intValue(logicalSort.offset)).isEqualTo(2);
}
Also used : DingoTableScan(io.dingodb.calcite.rel.DingoTableScan) RelRoot(org.apache.calcite.rel.RelRoot) NlsString(org.apache.calcite.util.NlsString) AssertRelNode(io.dingodb.calcite.assertion.AssertRelNode) LogicalSort(org.apache.calcite.rel.logical.LogicalSort) 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