Search in sources :

Example 96 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 testAggregateGroupingWithFilterFails.

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

Example 97 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 testDistinctAlready.

@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));
}
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 98 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 testScanFilterEquals.

@Test
public void testScanFilterEquals() {
    // Equivalent SQL:
    // SELECT *
    // FROM emp
    // WHERE deptno = 20
    final RelBuilder builder = RelBuilder.create(config().build());
    RelNode root = builder.scan("EMP").filter(builder.equals(builder.field("DEPTNO"), builder.literal(20))).build();
    final String expected = "LogicalFilter(condition=[=($7, 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 99 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 testScanFilterTriviallyFalse.

@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"));
}
Also used : RelBuilder(org.apache.calcite.tools.RelBuilder) RelNode(org.apache.calcite.rel.RelNode) Test(org.junit.Test)

Example 100 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 testValuesNullable.

/**
 * Tests creating Values with some field names and some values null.
 */
@Test
public void testValuesNullable() {
    // Equivalent SQL:
    // VALUES (null, 1, 'abc'), (false, null, 'longer string')
    final RelBuilder builder = RelBuilder.create(config().build());
    RelNode root = builder.values(new String[] { "a", null, "c" }, null, 1, "abc", false, null, "longer string").build();
    final String expected = "LogicalValues(tuples=[[{ null, 1, 'abc' }, { false, null, 'longer string' }]])\n";
    assertThat(root, hasTree(expected));
    final String expectedType = "RecordType(BOOLEAN a, INTEGER expr$1, CHAR(13) CHARACTER SET \"ISO-8859-1\" COLLATE \"ISO-8859-1$en_US$primary\" NOT NULL c) NOT NULL";
    assertThat(root.getRowType().getFullTypeString(), is(expectedType));
}
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