Search in sources :

Example 66 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.

the class PigRelBuilderTest method testScan.

@Test
public void testScan() {
    // Equivalent SQL:
    // SELECT *
    // FROM emp
    final PigRelBuilder builder = PigRelBuilder.create(config().build());
    final RelNode root = builder.scan("EMP").build();
    assertThat(str(root), is("LogicalTableScan(table=[[scott, EMP]])\n"));
}
Also used : PigRelBuilder(org.apache.calcite.tools.PigRelBuilder) RelNode(org.apache.calcite.rel.RelNode) Test(org.junit.Test)

Example 67 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.

the class PigRelBuilderTest method testGroup2.

@Test
public void testGroup2() {
    // Equivalent to Pig Latin:
    // r = GROUP e BY deptno, d BY deptno;
    final PigRelBuilder builder = PigRelBuilder.create(config().build());
    final RelNode root = builder.scan("EMP").scan("DEPT").group(null, null, -1, builder.groupKey("DEPTNO").alias("e"), builder.groupKey("DEPTNO").alias("d")).build();
    final String plan = "LogicalJoin(condition=[=($0, $2)], joinType=[inner])\n" + "  LogicalAggregate(group=[{0}], EMP=[COLLECT($8)])\n" + "    LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], $f8=[ROW($0, $1, $2, $3, $4, $5, $6, $7)])\n" + "      LogicalTableScan(table=[[scott, EMP]])\n  LogicalAggregate(group=[{0}], DEPT=[COLLECT($3)])\n" + "    LogicalProject(DEPTNO=[$0], DNAME=[$1], LOC=[$2], $f3=[ROW($0, $1, $2)])\n" + "      LogicalTableScan(table=[[scott, DEPT]])\n";
    assertThat(str(root), is(plan));
}
Also used : PigRelBuilder(org.apache.calcite.tools.PigRelBuilder) RelNode(org.apache.calcite.rel.RelNode) Test(org.junit.Test)

Example 68 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project calcite by apache.

the class PigRelBuilderTest method testFilter.

@Test
public void testFilter() {
    // Syntax:
    // FILTER name BY expr
    // Example:
    // output_var = FILTER input_var BY (field1 is not null);
    final PigRelBuilder builder = PigRelBuilder.create(config().build());
    final RelNode root = builder.load("EMP.csv", null, null).filter(builder.isNotNull(builder.field("MGR"))).build();
    final String plan = "LogicalFilter(condition=[IS NOT NULL($3)])\n" + "  LogicalTableScan(table=[[scott, EMP]])\n";
    assertThat(str(root), is(plan));
}
Also used : PigRelBuilder(org.apache.calcite.tools.PigRelBuilder) RelNode(org.apache.calcite.rel.RelNode) Test(org.junit.Test)

Example 69 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 testProject2.

/**
 * Tests each method that creates a scalar expression.
 */
@Test
public void testProject2() {
    final RelBuilder builder = RelBuilder.create(config().build());
    RelNode root = builder.scan("EMP").project(builder.field("DEPTNO"), builder.cast(builder.field(6), SqlTypeName.SMALLINT), builder.or(builder.equals(builder.field("DEPTNO"), builder.literal(20)), builder.and(builder.literal(null), builder.equals(builder.field("DEPTNO"), builder.literal(10)), builder.and(builder.isNull(builder.field(6)), builder.not(builder.isNotNull(builder.field(7))))), builder.equals(builder.field("DEPTNO"), builder.literal(20)), builder.equals(builder.field("DEPTNO"), builder.literal(30))), builder.alias(builder.isNull(builder.field(2)), "n2"), builder.alias(builder.isNotNull(builder.field(3)), "nn2"), builder.literal(20), builder.field(6), builder.alias(builder.field(6), "C")).build();
    final String expected = "" + "LogicalProject(DEPTNO=[$7], COMM=[CAST($6):SMALLINT NOT NULL]," + " $f2=[OR(=($7, 20), AND(null, =($7, 10), IS NULL($6)," + " IS NULL($7)), =($7, 30))], n2=[IS NULL($2)]," + " nn2=[IS NOT NULL($3)], $f5=[20], COMM0=[$6], C=[$6])\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 70 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 testJoinCartesian.

@Test
public void testJoinCartesian() {
    // Equivalent SQL:
    // SELECT * emp CROSS JOIN dept
    final RelBuilder builder = RelBuilder.create(config().build());
    RelNode root = builder.scan("EMP").scan("DEPT").join(JoinRelType.INNER).build();
    final String expected = "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