use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.
the class RelBuilderTest method testFilterCastAny.
@Test
public void testFilterCastAny() {
final RelBuilder builder = RelBuilder.create(config().build());
final RelDataType anyType = builder.getTypeFactory().createSqlType(SqlTypeName.ANY);
final RelNode root = builder.scan("EMP").filter(builder.cast(builder.getRexBuilder().makeInputRef(anyType, 0), SqlTypeName.BOOLEAN)).build();
final String expected = "" + "LogicalFilter(condition=[CAST($0):BOOLEAN NOT NULL])\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 testJoin.
@Test
public void testJoin() {
// Equivalent SQL:
// SELECT *
// FROM (SELECT * FROM emp WHERE comm IS NULL)
// JOIN dept ON emp.deptno = dept.deptno
final RelBuilder builder = RelBuilder.create(config().build());
RelNode root = builder.scan("EMP").filter(builder.call(SqlStdOperatorTable.IS_NULL, builder.field("COMM"))).scan("DEPT").join(JoinRelType.INNER, builder.call(SqlStdOperatorTable.EQUALS, builder.field(2, 0, "DEPTNO"), builder.field(2, 1, "DEPTNO"))).build();
final String expected = "" + "LogicalJoin(condition=[=($7, $8)], joinType=[inner])\n" + " LogicalFilter(condition=[IS NULL($6)])\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 testAggregate3.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-2192">[CALCITE-2192]
* RelBuilder wrongly skips creation of Aggregate that prunes columns if input
* is unique</a>.
*/
@Test
public void testAggregate3() {
// Equivalent SQL:
// SELECT DISTINCT deptno FROM (
// SELECT deptno, COUNT(*)
// FROM emp
// GROUP BY deptno)
final RelBuilder builder = RelBuilder.create(config().build());
RelNode root = builder.scan("EMP").aggregate(builder.groupKey(builder.field(1)), builder.aggregateCall(SqlStdOperatorTable.COUNT, false, false, null, "C")).aggregate(builder.groupKey(builder.field(0))).build();
final String expected = "" + "LogicalProject(ENAME=[$0])\n" + " LogicalAggregate(group=[{1}], C=[COUNT()])\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 testAliasLimit.
@Test
public void testAliasLimit() {
final RelBuilder builder = RelBuilder.create(config().build());
RelNode root = builder.scan("EMP").as("e").sort(1).sortLimit(10, // aliases were lost here if preceded by sort()
20).project(builder.field("e", "EMPNO")).build();
final String expected = "" + "LogicalProject(EMPNO=[$0])\n" + " LogicalSort(sort0=[$1], dir0=[ASC], offset=[10], fetch=[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 testSortThenLimit.
/**
* Tests that a sort on a field followed by a limit gives the same
* effect as calling sortLimit.
*
* <p>In general a relational operator cannot rely on the order of its input,
* but it is reasonable to merge sort and limit if they were created by
* consecutive builder operations. And clients such as Piglet rely on it.
*/
@Test
public void testSortThenLimit() {
final RelBuilder builder = RelBuilder.create(config().build());
final RelNode root = builder.scan("EMP").sort(builder.desc(builder.field("DEPTNO"))).limit(-1, 10).build();
final String expected = "" + "LogicalSort(sort0=[$7], dir0=[DESC], fetch=[10])\n" + " LogicalTableScan(table=[[scott, EMP]])\n";
assertThat(root, hasTree(expected));
final RelNode root2 = builder.scan("EMP").sortLimit(-1, 10, builder.desc(builder.field("DEPTNO"))).build();
assertThat(root2, hasTree(expected));
}
Aggregations