Search in sources :

Example 71 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 testAlias2.

@Test
public void testAlias2() {
    // Equivalent SQL:
    // SELECT *
    // FROM emp AS e, emp as m, dept
    // WHERE e.deptno = dept.deptno
    // AND m.empno = e.mgr
    final RelBuilder builder = RelBuilder.create(config().build());
    RelNode root = builder.scan("EMP").as("e").scan("EMP").as("m").scan("DEPT").join(JoinRelType.INNER).join(JoinRelType.INNER).filter(builder.equals(builder.field("e", "DEPTNO"), builder.field("DEPT", "DEPTNO")), builder.equals(builder.field("m", "EMPNO"), builder.field("e", "MGR"))).build();
    final String expected = "" + "LogicalFilter(condition=[AND(=($7, $16), =($8, $3))])\n" + "  LogicalJoin(condition=[true], joinType=[inner])\n" + "    LogicalTableScan(table=[[scott, EMP]])\n" + "    LogicalJoin(condition=[true], joinType=[inner])\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 72 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 testAliasProject.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-1551">[CALCITE-1551]
 * RelBuilder's project() doesn't preserve alias</a>.
 */
@Test
public void testAliasProject() {
    final RelBuilder builder = RelBuilder.create(config().build());
    RelNode root = builder.scan("EMP").as("EMP_alias").project(builder.field("DEPTNO"), builder.literal(20)).project(builder.field("EMP_alias", "DEPTNO")).build();
    final String expected = "" + "LogicalProject(DEPTNO=[$0])\n" + "  LogicalProject(DEPTNO=[$7], $f1=[20])\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)

Example 73 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 testAlias.

@Test
public void testAlias() {
    // Equivalent SQL:
    // SELECT *
    // FROM emp AS e, dept
    // WHERE e.deptno = dept.deptno
    final RelBuilder builder = RelBuilder.create(config().build());
    RelNode root = builder.scan("EMP").as("e").scan("DEPT").join(JoinRelType.LEFT).filter(builder.equals(builder.field("e", "DEPTNO"), builder.field("DEPT", "DEPTNO"))).project(builder.field("e", "ENAME"), builder.field("DEPT", "DNAME")).build();
    final String expected = "LogicalProject(ENAME=[$1], DNAME=[$9])\n" + "  LogicalFilter(condition=[=($7, $8)])\n" + "    LogicalJoin(condition=[true], joinType=[left])\n" + "      LogicalTableScan(table=[[scott, EMP]])\n" + "      LogicalTableScan(table=[[scott, DEPT]])\n";
    assertThat(root, hasTree(expected));
    final RelDataTypeField field = root.getRowType().getFieldList().get(1);
    assertThat(field.getName(), is("DNAME"));
    assertThat(field.getType().isNullable(), is(true));
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelBuilder(org.apache.calcite.tools.RelBuilder) RelNode(org.apache.calcite.rel.RelNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 74 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 testValues.

@Test
public void testValues() {
    // Equivalent SQL:
    // VALUES (true, 1), (false, -50) AS t(a, b)
    final RelBuilder builder = RelBuilder.create(config().build());
    RelNode root = builder.values(new String[] { "a", "b" }, true, 1, false, -50).build();
    final String expected = "LogicalValues(tuples=[[{ true, 1 }, { false, -50 }]])\n";
    assertThat(root, hasTree(expected));
    final String expectedType = "RecordType(BOOLEAN NOT NULL a, INTEGER NOT NULL b) NOT NULL";
    assertThat(root.getRowType().getFullTypeString(), is(expectedType));
}
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 75 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 testScanInvalidSchema.

@Test
public void testScanInvalidSchema() {
    // FROM "zzz"."emp"
    try {
        final RelNode root = RelBuilder.create(config().build()).scan("ZZZ", // the table exists, but the schema does not
        "EMP").build();
        fail("expected error, got " + root);
    } catch (Exception e) {
        assertThat(e.getMessage(), is("Table 'ZZZ.EMP' not found"));
    }
}
Also used : RelNode(org.apache.calcite.rel.RelNode) CalciteException(org.apache.calcite.runtime.CalciteException) 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