Search in sources :

Example 76 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 testAggregateGroupingWithDistinctFails.

@Test
public void testAggregateGroupingWithDistinctFails() {
    final RelBuilder builder = RelBuilder.create(config().build());
    try {
        RelNode root = builder.scan("EMP").aggregate(builder.groupKey(6, 7), builder.aggregateCall(SqlStdOperatorTable.GROUPING, true, false, null, "g", builder.field("DEPTNO"))).build();
        fail("expected error, got " + root);
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), is("DISTINCT not allowed"));
    }
}
Also used : RelBuilder(org.apache.calcite.tools.RelBuilder) RelNode(org.apache.calcite.rel.RelNode) Test(org.junit.Test)

Example 77 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 testAliasAggregate.

@Test
public void testAliasAggregate() {
    final RelBuilder builder = RelBuilder.create(config().build());
    RelNode root = builder.scan("EMP").as("EMP_alias").project(builder.field("DEPTNO"), builder.literal(20)).aggregate(builder.groupKey(builder.field("EMP_alias", "DEPTNO")), builder.aggregateCall(SqlStdOperatorTable.SUM, false, false, null, null, builder.field(1))).project(builder.alias(builder.field(1), "sum"), builder.field("EMP_alias", "DEPTNO")).build();
    final String expected = "" + "LogicalProject(sum=[$1], DEPTNO=[$0])\n" + "  LogicalAggregate(group=[{0}], agg#0=[SUM($1)])\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 78 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 testConvert.

@Test
public void testConvert() {
    final RelBuilder builder = RelBuilder.create(config().build());
    RelDataType rowType = builder.getTypeFactory().builder().add("a", SqlTypeName.BIGINT).add("b", SqlTypeName.VARCHAR, 10).add("c", SqlTypeName.VARCHAR, 10).build();
    RelNode root = builder.scan("DEPT").convert(rowType, false).build();
    final String expected = "" + "LogicalProject(DEPTNO=[CAST($0):BIGINT NOT NULL], DNAME=[CAST($1):VARCHAR(10) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL], LOC=[CAST($2):VARCHAR(10) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL])\n" + "  LogicalTableScan(table=[[scott, DEPT]])\n";
    assertThat(root, hasTree(expected));
}
Also used : RelBuilder(org.apache.calcite.tools.RelBuilder) RelNode(org.apache.calcite.rel.RelNode) RelDataType(org.apache.calcite.rel.type.RelDataType) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 79 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 testAggregateGroupingSetDuplicateIgnored.

@Test
public void testAggregateGroupingSetDuplicateIgnored() {
    final RelBuilder builder = RelBuilder.create(config().build());
    RelNode root = builder.scan("EMP").aggregate(builder.groupKey(ImmutableBitSet.of(7, 6), ImmutableList.of(ImmutableBitSet.of(7), ImmutableBitSet.of(6), ImmutableBitSet.of(7)))).build();
    final String expected = "" + "LogicalAggregate(group=[{6, 7}], groups=[[{6}, {7}]])\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 80 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 testMultiLevelAlias.

@Test
public void testMultiLevelAlias() {
    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).project(builder.field("DEPT", "DEPTNO"), builder.field(16), builder.field("m", "EMPNO"), builder.field("e", "MGR")).as("all").filter(builder.call(SqlStdOperatorTable.GREATER_THAN, builder.field("DEPT", "DEPTNO"), builder.literal(100))).project(builder.field("DEPT", "DEPTNO"), builder.field("all", "EMPNO")).build();
    final String expected = "" + "LogicalProject(DEPTNO=[$0], EMPNO=[$2])\n" + "  LogicalFilter(condition=[>($0, 100)])\n" + "    LogicalProject(DEPTNO=[$16], DEPTNO0=[$16], EMPNO=[$8], MGR=[$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)

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