Search in sources :

Example 86 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.

the class RelBuilderTest method testValuesAllNull.

@Test
public void testValuesAllNull() {
    final RelBuilder builder = RelBuilder.create(config().build());
    RelDataType rowType = builder.getTypeFactory().builder().add("a", SqlTypeName.BIGINT).add("a", SqlTypeName.VARCHAR, 10).build();
    RelNode root = builder.values(rowType, null, null, 1, null).build();
    final String expected = "LogicalValues(tuples=[[{ null, null }, { 1, null }]])\n";
    assertThat(root, hasTree(expected));
    final String expectedType = "RecordType(BIGINT NOT NULL a, VARCHAR(10) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL a) NOT NULL";
    assertThat(root.getRowType().getFullTypeString(), is(expectedType));
}
Also used : RelBuilder(org.apache.calcite.tools.RelBuilder) RelNode(org.apache.calcite.rel.RelNode) RelDataType(org.apache.calcite.rel.type.RelDataType) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 87 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.

the class RelBuilderTest method testAliasPastTop.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-1523">[CALCITE-1523]
 * Add RelBuilder field() method to reference aliased relations not on top of
 * stack</a>, accessing tables aliased that are not accessible in the top
 * RelNode.
 */
@Test
public void testAliasPastTop() {
    // Equivalent SQL:
    // SELECT *
    // FROM emp
    // LEFT JOIN dept ON emp.deptno = dept.deptno
    // AND emp.empno = 123
    // AND dept.deptno IS NOT NULL
    final RelBuilder builder = RelBuilder.create(config().build());
    RelNode root = builder.scan("EMP").scan("DEPT").join(JoinRelType.LEFT, builder.call(SqlStdOperatorTable.EQUALS, builder.field(2, "EMP", "DEPTNO"), builder.field(2, "DEPT", "DEPTNO")), builder.call(SqlStdOperatorTable.EQUALS, builder.field(2, "EMP", "EMPNO"), builder.literal(123))).build();
    final String expected = "" + "LogicalJoin(condition=[AND(=($7, $8), =($0, 123))], joinType=[left])\n" + "  LogicalTableScan(table=[[scott, EMP]])\n" + "  LogicalTableScan(table=[[scott, DEPT]])\n";
    assertThat(root, hasTree(expected));
}
Also used : RelBuilder(org.apache.calcite.tools.RelBuilder) RelNode(org.apache.calcite.rel.RelNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 88 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.

the class RelBuilderTest method testScan.

@Test
public void testScan() {
    // Equivalent SQL:
    // SELECT *
    // FROM emp
    final RelNode root = RelBuilder.create(config().build()).scan("EMP").build();
    assertThat(root, hasTree("LogicalTableScan(table=[[scott, EMP]])\n"));
}
Also used : RelNode(org.apache.calcite.rel.RelNode) Test(org.junit.Test)

Example 89 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.

the class RelBuilderTest method testJoin2.

@Test
public void testJoin2() {
    // Equivalent SQL:
    // SELECT *
    // FROM emp
    // LEFT JOIN dept ON emp.deptno = dept.deptno
    // AND emp.empno = 123
    // AND dept.deptno IS NOT NULL
    final RelBuilder builder = RelBuilder.create(config().build());
    RelNode root = builder.scan("EMP").scan("DEPT").join(JoinRelType.LEFT, builder.call(SqlStdOperatorTable.EQUALS, builder.field(2, 0, "DEPTNO"), builder.field(2, 1, "DEPTNO")), builder.call(SqlStdOperatorTable.EQUALS, builder.field(2, 0, "EMPNO"), builder.literal(123)), builder.call(SqlStdOperatorTable.IS_NOT_NULL, builder.field(2, 1, "DEPTNO"))).build();
    // Note that "dept.deptno IS NOT NULL" has been simplified away.
    final String expected = "" + "LogicalJoin(condition=[AND(=($7, $8), =($0, 123))], joinType=[left])\n" + "  LogicalTableScan(table=[[scott, EMP]])\n" + "  LogicalTableScan(table=[[scott, DEPT]])\n";
    assertThat(root, hasTree(expected));
}
Also used : RelBuilder(org.apache.calcite.tools.RelBuilder) RelNode(org.apache.calcite.rel.RelNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 90 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.

the class RelBuilderTest method testUnion3.

@Test
public void testUnion3() {
    // Equivalent SQL:
    // SELECT deptno FROM dept
    // UNION ALL
    // SELECT empno FROM emp
    // UNION ALL
    // SELECT deptno FROM emp
    final RelBuilder builder = RelBuilder.create(config().build());
    RelNode root = builder.scan("DEPT").project(builder.field("DEPTNO")).scan("EMP").project(builder.field("EMPNO")).scan("EMP").project(builder.field("DEPTNO")).union(true, 3).build();
    final String expected = "" + "LogicalUnion(all=[true])\n" + "  LogicalProject(DEPTNO=[$0])\n" + "    LogicalTableScan(table=[[scott, DEPT]])\n" + "  LogicalProject(EMPNO=[$0])\n" + "    LogicalTableScan(table=[[scott, EMP]])\n" + "  LogicalProject(DEPTNO=[$7])\n" + "    LogicalTableScan(table=[[scott, EMP]])\n";
    assertThat(root, hasTree(expected));
}
Also used : RelBuilder(org.apache.calcite.tools.RelBuilder) RelNode(org.apache.calcite.rel.RelNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

RelNode (org.apache.calcite.rel.RelNode)1133 RexNode (org.apache.calcite.rex.RexNode)353 ArrayList (java.util.ArrayList)273 Test (org.junit.Test)239 RelBuilder (org.apache.calcite.tools.RelBuilder)161 RelDataType (org.apache.calcite.rel.type.RelDataType)156 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)142 RexBuilder (org.apache.calcite.rex.RexBuilder)129 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)121 RelTraitSet (org.apache.calcite.plan.RelTraitSet)114 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)97 RexInputRef (org.apache.calcite.rex.RexInputRef)85 HashMap (java.util.HashMap)82 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)77 Project (org.apache.calcite.rel.core.Project)74 RelOptCluster (org.apache.calcite.plan.RelOptCluster)71 List (java.util.List)67 Pair (org.apache.calcite.util.Pair)67 AggregateCall (org.apache.calcite.rel.core.AggregateCall)63 SqlNode (org.apache.calcite.sql.SqlNode)61