use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.
the class RelBuilderTest method testIntersect.
@Test
public void testIntersect() {
// Equivalent SQL:
// SELECT empno FROM emp
// WHERE deptno = 20
// INTERSECT
// SELECT deptno FROM dept
final RelBuilder builder = RelBuilder.create(config().build());
RelNode root = builder.scan("DEPT").project(builder.field("DEPTNO")).scan("EMP").filter(builder.call(SqlStdOperatorTable.EQUALS, builder.field("DEPTNO"), builder.literal(20))).project(builder.field("EMPNO")).intersect(false).build();
final String expected = "" + "LogicalIntersect(all=[false])\n" + " LogicalProject(DEPTNO=[$0])\n" + " LogicalTableScan(table=[[scott, DEPT]])\n" + " LogicalProject(EMPNO=[$0])\n" + " LogicalFilter(condition=[=($7, 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 testFilterCastNull.
@Test
public void testFilterCastNull() {
final RelBuilder builder = RelBuilder.create(config().build());
final RelDataTypeFactory typeFactory = builder.getTypeFactory();
final RelNode root = builder.scan("EMP").filter(builder.getRexBuilder().makeCast(typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BOOLEAN), true), builder.equals(builder.field("DEPTNO"), builder.literal(10)))).build();
final String expected = "" + "LogicalFilter(condition=[=($7, 10)])\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 testUnionAlias.
@Test
public void testUnionAlias() {
final RelBuilder builder = RelBuilder.create(config().build());
RelNode root = builder.scan("EMP").as("e1").project(builder.field("EMPNO"), builder.call(SqlStdOperatorTable.CONCAT, builder.field("ENAME"), builder.literal("-1"))).scan("EMP").as("e2").project(builder.field("EMPNO"), builder.call(SqlStdOperatorTable.CONCAT, builder.field("ENAME"), builder.literal("-2"))).union(// aliases lost here
false).project(builder.fields(Lists.newArrayList(1, 0))).build();
final String expected = "" + "LogicalProject($f1=[$1], EMPNO=[$0])\n" + " LogicalUnion(all=[false])\n" + " LogicalProject(EMPNO=[$0], $f1=[||($1, '-1')])\n" + " LogicalTableScan(table=[[scott, EMP]])\n" + " LogicalProject(EMPNO=[$0], $f1=[||($1, '-2')])\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 testRename.
@Test
public void testRename() {
final RelBuilder builder = RelBuilder.create(config().build());
// No rename necessary (null name is ignored)
RelNode root = builder.scan("DEPT").rename(Arrays.asList("DEPTNO", null)).build();
final String expected = "LogicalTableScan(table=[[scott, DEPT]])\n";
assertThat(root, hasTree(expected));
// No rename necessary (prefix matches)
root = builder.scan("DEPT").rename(ImmutableList.of("DEPTNO")).build();
assertThat(root, hasTree(expected));
// Add project to rename fields
root = builder.scan("DEPT").rename(Arrays.asList("NAME", null, "DEPTNO")).build();
final String expected2 = "" + "LogicalProject(NAME=[$0], DNAME=[$1], DEPTNO=[$2])\n" + " LogicalTableScan(table=[[scott, DEPT]])\n";
assertThat(root, hasTree(expected2));
// If our requested list has non-unique names, we might get the same field
// names we started with. Don't add a useless project.
root = builder.scan("DEPT").rename(Arrays.asList("DEPTNO", null, "DEPTNO")).build();
final String expected3 = "" + "LogicalProject(DEPTNO=[$0], DNAME=[$1], DEPTNO0=[$2])\n" + " LogicalTableScan(table=[[scott, DEPT]])\n";
assertThat(root, hasTree(expected3));
root = builder.scan("DEPT").rename(Arrays.asList("DEPTNO", null, "DEPTNO")).rename(Arrays.asList("DEPTNO", null, "DEPTNO")).build();
// No extra Project
assertThat(root, hasTree(expected3));
// Name list too long
try {
root = builder.scan("DEPT").rename(ImmutableList.of("NAME", "DEPTNO", "Y", "Z")).build();
fail("expected error, got " + root);
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), is("More names than fields"));
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.
the class RelBuilderTest method testRenameValues.
@Test
public void testRenameValues() {
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));
// When you rename Values, you get a Values with a new row type, no Project
root = builder.push(root).rename(ImmutableList.of("x", "y z")).build();
assertThat(root, hasTree(expected));
assertThat(root.getRowType().getFieldNames().toString(), is("[x, y z]"));
}
Aggregations