@Test public void testPermute() { final RelBuilder builder = RelBuilder.create(config().build()); RelNode root = builder.scan("EMP") .permute(Mappings.bijection(Arrays.asList(1, 2, 0))) .build(); final String expected = "LogicalProject(JOB=[$2], EMPNO=[$0], ENAME=[$1])\n" + " LogicalTableScan(table=[[scott, EMP]])\n"; assertThat(root, hasTree(expected)); }
@Test public void testPermute() { final RelBuilder builder = RelBuilder.create(config().build()); RelNode root = builder.scan("EMP") .permute(Mappings.bijection(Arrays.asList(1, 2, 0))) .build(); final String expected = "LogicalProject(JOB=[$2], EMPNO=[$0], ENAME=[$1])\n" + " LogicalTableScan(table=[[scott, EMP]])\n"; assertThat(root, hasTree(expected)); }
@Test public void testExchange() { final RelBuilder builder = RelBuilder.create(config().build()); final RelNode root = builder.scan("EMP") .exchange(RelDistributions.hash(Lists.newArrayList(0))) .build(); final String expected = "LogicalExchange(distribution=[hash[0]])\n" + " LogicalTableScan(table=[[scott, EMP]])\n"; assertThat(root, hasTree(expected)); }
@Test public void testScanQualifiedTable() { // Equivalent SQL: // SELECT * // FROM "scott"."emp" final RelNode root = RelBuilder.create(config().build()) .scan("scott", "EMP") .build(); assertThat(root, hasTree("LogicalTableScan(table=[[scott, EMP]])\n")); }
@Test public void testScanQualifiedTable() { // Equivalent SQL: // SELECT * // FROM "scott"."emp" final RelNode root = RelBuilder.create(config().build()) .scan("scott", "EMP") .build(); assertThat(root, hasTree("LogicalTableScan(table=[[scott, EMP]])\n")); }
@Test public void testProjectIdentity() { final RelBuilder builder = RelBuilder.create(config().build()); RelNode root = builder.scan("DEPT") .project(builder.fields(Mappings.bijection(Arrays.asList(0, 1, 2)))) .build(); final String expected = "LogicalTableScan(table=[[scott, DEPT]])\n"; assertThat(root, hasTree(expected)); }
@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")); }
@Test public void testProjectIdentity() { final RelBuilder builder = RelBuilder.create(config().build()); RelNode root = builder.scan("DEPT") .project(builder.fields(Mappings.bijection(Arrays.asList(0, 1, 2)))) .build(); final String expected = "LogicalTableScan(table=[[scott, DEPT]])\n"; assertThat(root, hasTree(expected)); }
@Test public void testProjectLeadingEdge() { final RelBuilder builder = RelBuilder.create(config().build()); RelNode root = builder.scan("EMP") .project(builder.fields(Mappings.bijection(Arrays.asList(0, 1, 2)))) .build(); final String expected = "LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2])\n" + " LogicalTableScan(table=[[scott, EMP]])\n"; assertThat(root, hasTree(expected)); }
@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")); }
@Test public void testProjectLeadingEdge() { final RelBuilder builder = RelBuilder.create(config().build()); RelNode root = builder.scan("EMP") .project(builder.fields(Mappings.bijection(Arrays.asList(0, 1, 2)))) .build(); final String expected = "LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2])\n" + " LogicalTableScan(table=[[scott, EMP]])\n"; assertThat(root, hasTree(expected)); }
@Test public void testSortExchange() { final RelBuilder builder = RelBuilder.create(config().build()); final RelNode root = builder.scan("EMP") .sortExchange(RelDistributions.hash(Lists.newArrayList(0)), RelCollations.of(0)) .build(); final String expected = "LogicalSortExchange(distribution=[hash[0]], collation=[[0]])\n" + " LogicalTableScan(table=[[scott, EMP]])\n"; assertThat(root, hasTree(expected)); } }
@Test public void testDistinctAlready() { // DEPT is already distinct final RelBuilder builder = RelBuilder.create(config().build()); RelNode root = builder.scan("DEPT") .distinct() .build(); final String expected = "LogicalTableScan(table=[[scott, DEPT]])\n"; assertThat(root, hasTree(expected)); }
@Test public void testDistinctAlready() { // DEPT is already distinct final RelBuilder builder = RelBuilder.create(config().build()); RelNode root = builder.scan("DEPT") .distinct() .build(); final String expected = "LogicalTableScan(table=[[scott, DEPT]])\n"; assertThat(root, hasTree(expected)); }
@Test public void testScanFilterTrue() { // Equivalent SQL: // SELECT * // FROM emp // WHERE TRUE final RelBuilder builder = RelBuilder.create(config().build()); RelNode root = builder.scan("EMP") .filter(builder.literal(true)) .build(); assertThat(root, hasTree("LogicalTableScan(table=[[scott, EMP]])\n")); }
@Test public void testSortLimit0() { // Equivalent SQL: // SELECT * // FROM emp // ORDER BY deptno DESC FETCH 0 final RelBuilder builder = RelBuilder.create(config().build()); final RelNode root = builder.scan("EMP") .sortLimit(-1, 0, builder.desc(builder.field("DEPTNO"))) .build(); final String expected = "LogicalValues(tuples=[[]])\n"; assertThat(root, hasTree(expected)); }
@Test public void testScanFilterTriviallyFalse() { // Equivalent SQL: // SELECT * // FROM emp // WHERE 1 = 2 final RelBuilder builder = RelBuilder.create(config().build()); RelNode root = builder.scan("EMP") .filter(builder.equals(builder.literal(1), builder.literal(2))) .build(); assertThat(root, hasTree("LogicalValues(tuples=[[]])\n")); }
@Test public void testScanFilterTriviallyFalse() { // Equivalent SQL: // SELECT * // FROM emp // WHERE 1 = 2 final RelBuilder builder = RelBuilder.create(config().build()); RelNode root = builder.scan("EMP") .filter(builder.equals(builder.literal(1), builder.literal(2))) .build(); assertThat(root, hasTree("LogicalValues(tuples=[[]])\n")); }
@Test public void testAggregateGrouping() { final RelBuilder builder = RelBuilder.create(config().build()); RelNode root = builder.scan("EMP") .aggregate(builder.groupKey(6, 7), builder.aggregateCall(SqlStdOperatorTable.GROUPING, false, false, null, "g", builder.field("DEPTNO"))) .build(); final String expected = "" + "LogicalAggregate(group=[{6, 7}], g=[GROUPING($7)])\n" + " LogicalTableScan(table=[[scott, EMP]])\n"; assertThat(root, hasTree(expected)); }
@Test public void testAggregateGrouping() { final RelBuilder builder = RelBuilder.create(config().build()); RelNode root = builder.scan("EMP") .aggregate(builder.groupKey(6, 7), builder.aggregateCall(SqlStdOperatorTable.GROUPING, builder.field("DEPTNO")).as("g")) .build(); final String expected = "" + "LogicalAggregate(group=[{6, 7}], g=[GROUPING($7)])\n" + " LogicalTableScan(table=[[scott, EMP]])\n"; assertThat(root, hasTree(expected)); }