Search in sources :

Example 76 with RelRoot

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot 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)

Example 77 with RelRoot

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project dingo by dingodb.

the class TestLogicalPlan method testAggregateGroup.

@Test
public void testAggregateGroup() throws SqlParseException {
    String sql = "select name, sum(amount) from test group by name";
    RelRoot relRoot = parse(sql);
    Assert.relNode(relRoot.rel).isA(LogicalAggregate.class).convention(Convention.NONE).singleInput().isA(LogicalProject.class).convention(Convention.NONE).singleInput().isA(DingoTableScan.class).convention(DingoConventions.DINGO);
}
Also used : LogicalAggregate(org.apache.calcite.rel.logical.LogicalAggregate) DingoTableScan(io.dingodb.calcite.rel.DingoTableScan) RelRoot(org.apache.calcite.rel.RelRoot) NlsString(org.apache.calcite.util.NlsString) Test(org.junit.jupiter.api.Test)

Example 78 with RelRoot

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project dingo by dingodb.

the class TestLogicalPlan method testProjectFilterScan.

@Test
public void testProjectFilterScan() throws SqlParseException {
    String sql = "select name, amount from test where amount > 3.0";
    RelRoot relRoot = parse(sql);
    Assert.relNode(relRoot.rel).isA(LogicalProject.class).convention(Convention.NONE).singleInput().isA(LogicalFilter.class).convention(Convention.NONE).singleInput().isA(DingoTableScan.class).convention(DingoConventions.DINGO);
}
Also used : DingoTableScan(io.dingodb.calcite.rel.DingoTableScan) RelRoot(org.apache.calcite.rel.RelRoot) NlsString(org.apache.calcite.util.NlsString) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) Test(org.junit.jupiter.api.Test)

Example 79 with RelRoot

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project dingo by dingodb.

the class TestLogicalPlan method testDelete.

@Test
public void testDelete() throws SqlParseException {
    String sql = "delete from test where id = 3";
    RelRoot relRoot = parse(sql);
    Assert.relNode(relRoot.rel).isA(LogicalTableModify.class).convention(Convention.NONE).prop("operation", TableModify.Operation.DELETE).singleInput().isA(LogicalProject.class).convention(Convention.NONE).singleInput().isA(LogicalFilter.class).convention(Convention.NONE).singleInput().isA(DingoTableScan.class).convention(DingoConventions.DINGO);
}
Also used : LogicalTableModify(org.apache.calcite.rel.logical.LogicalTableModify) DingoTableScan(io.dingodb.calcite.rel.DingoTableScan) RelRoot(org.apache.calcite.rel.RelRoot) NlsString(org.apache.calcite.util.NlsString) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) Test(org.junit.jupiter.api.Test)

Example 80 with RelRoot

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project dingo by dingodb.

the class TestRexConverter method test.

@ParameterizedTest
@MethodSource("getParameters")
public void test(String rex, String result) throws SqlParseException {
    String sql = "select " + rex + " from test";
    SqlNode sqlNode = parser.parse(sql);
    sqlNode = parser.validate(sqlNode);
    RelRoot relRoot = parser.convert(sqlNode);
    LogicalProject project = (LogicalProject) relRoot.rel;
    RexNode rexNode = project.getProjects().get(0);
    log.info("rexNode = {}", rexNode);
    Expr expr = RexConverter.convert(rexNode);
    assertThat(expr.toString()).isEqualTo(result);
}
Also used : Expr(io.dingodb.expr.parser.Expr) RelRoot(org.apache.calcite.rel.RelRoot) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) SqlNode(org.apache.calcite.sql.SqlNode) RexNode(org.apache.calcite.rex.RexNode) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

RelRoot (org.apache.calcite.rel.RelRoot)77 SqlNode (org.apache.calcite.sql.SqlNode)30 RelNode (org.apache.calcite.rel.RelNode)22 Test (org.junit.jupiter.api.Test)18 NlsString (org.apache.calcite.util.NlsString)17 DingoTableScan (io.dingodb.calcite.rel.DingoTableScan)13 SqlParseException (org.apache.calcite.sql.parser.SqlParseException)11 SqlToRelConverter (org.apache.calcite.sql2rel.SqlToRelConverter)11 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)9 SamzaSqlDslConverterFactory (org.apache.samza.sql.dsl.SamzaSqlDslConverterFactory)8 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)7 RelDataType (org.apache.calcite.rel.type.RelDataType)7 RexBuilder (org.apache.calcite.rex.RexBuilder)7 SqlValidator (org.apache.calcite.sql.validate.SqlValidator)7 DslConverter (org.apache.samza.sql.interfaces.DslConverter)7 Test (org.junit.Test)7 RelOptCluster (org.apache.calcite.plan.RelOptCluster)6 SqlParser (org.apache.calcite.sql.parser.SqlParser)6 Planner (org.apache.calcite.tools.Planner)6 LogicalFilter (org.apache.calcite.rel.logical.LogicalFilter)5