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));
}
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));
}
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));
}
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));
}
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"));
}
}
Aggregations