Search in sources :

Example 1 with DingoSort

use of io.dingodb.calcite.rel.DingoSort in project dingo by dingodb.

the class DingoSortRule method convert.

@Override
public RelNode convert(@Nonnull RelNode rel) {
    LogicalSort sort = (LogicalSort) rel;
    RelTraitSet traitSet = sort.getTraitSet().replace(DingoConventions.ROOT);
    return new DingoSort(sort.getCluster(), traitSet, convert(sort.getInput(), traitSet), sort.getCollation(), sort.offset, sort.fetch);
}
Also used : DingoSort(io.dingodb.calcite.rel.DingoSort) RelTraitSet(org.apache.calcite.plan.RelTraitSet) LogicalSort(org.apache.calcite.rel.logical.LogicalSort)

Example 2 with DingoSort

use of io.dingodb.calcite.rel.DingoSort 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 3 with DingoSort

use of io.dingodb.calcite.rel.DingoSort 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 4 with DingoSort

use of io.dingodb.calcite.rel.DingoSort 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)

Aggregations

DingoSort (io.dingodb.calcite.rel.DingoSort)4 AssertRelNode (io.dingodb.calcite.assertion.AssertRelNode)3 DingoCoalesce (io.dingodb.calcite.rel.DingoCoalesce)3 DingoPartScan (io.dingodb.calcite.rel.DingoPartScan)3 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)3 RelNode (org.apache.calcite.rel.RelNode)3 Test (org.junit.jupiter.api.Test)3 RelTraitSet (org.apache.calcite.plan.RelTraitSet)1 LogicalSort (org.apache.calcite.rel.logical.LogicalSort)1