Search in sources :

Example 36 with RelNode

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

the class CoralSparkTest method testLateralViewArray.

@Test
public void testLateralViewArray() {
    RelNode relNode = TestUtils.toRelNode("SELECT col FROM (SELECT ARRAY('a1', 'a2') as a) tmp LATERAL VIEW EXPLODE(a) a_alias AS col");
    String targetSql = "SELECT t2.col\n" + "FROM (SELECT ARRAY ('a1', 'a2') a\n" + "FROM (VALUES  (0)) t (ZERO)) t0 LATERAL VIEW EXPLODE(t0.a) t2 AS col";
    assertEquals(CoralSpark.create(relNode).getSparkSql(), targetSql);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 37 with RelNode

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

the class CoralSparkTest method testNegationOperator.

@Test
public void testNegationOperator() {
    RelNode relNode = TestUtils.toRelNode("SELECT !FALSE as a FROM foo");
    String targetSql = "SELECT NOT FALSE a\n" + "FROM default.foo";
    assertEquals(CoralSpark.create(relNode).getSparkSql(), targetSql);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 38 with RelNode

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

the class CoralSparkTest method testCastDecimal.

@Test
public void testCastDecimal() {
    RelNode relNode = TestUtils.toRelNode("SELECT CAST(a as DECIMAL(6, 2)) as casted_decimal FROM default.foo");
    String targetSql = "SELECT CAST(a AS DECIMAL(6, 2)) casted_decimal\n" + "FROM default.foo";
    assertEquals(CoralSpark.create(relNode).getSparkSql(), targetSql);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 39 with RelNode

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

the class CoralSparkTest method testLateralViewStar.

@Test
public void testLateralViewStar() {
    RelNode relNode = TestUtils.toRelNode(String.join("\n", "", "SELECT a, t.*", "FROM complex", "LATERAL VIEW explode(complex.c) t"));
    String targetSql = "SELECT complex.a, t0.col\n" + "FROM default.complex LATERAL VIEW EXPLODE(complex.c) t0 AS col";
    assertEquals(CoralSpark.create(relNode).getSparkSql(), targetSql);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 40 with RelNode

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

the class CoralSparkTest method testGetSQLFromView.

@Test
public void testGetSQLFromView() {
    String targetSql = String.join("\n", "SELECT t0.bcol, bar.x", "FROM (SELECT b bcol, SUM(c) sum_c", "FROM default.foo", "GROUP BY b) t0", "INNER JOIN default.bar ON t0.sum_c = bar.y");
    RelNode relNode = TestUtils.toRelNode("default", "foo_bar_view");
    CoralSpark coralSpark = CoralSpark.create(relNode);
    String expandedSql = coralSpark.getSparkSql();
    assertEquals(expandedSql, targetSql);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Aggregations

RelNode (org.apache.calcite.rel.RelNode)2258 RexNode (org.apache.calcite.rex.RexNode)605 ArrayList (java.util.ArrayList)517 Test (org.junit.jupiter.api.Test)438 RelBuilder (org.apache.calcite.tools.RelBuilder)411 RelDataType (org.apache.calcite.rel.type.RelDataType)309 RexBuilder (org.apache.calcite.rex.RexBuilder)278 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)265 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)260 RelTraitSet (org.apache.calcite.plan.RelTraitSet)209 RexInputRef (org.apache.calcite.rex.RexInputRef)208 List (java.util.List)193 Project (org.apache.calcite.rel.core.Project)185 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)169 RelOptCluster (org.apache.calcite.plan.RelOptCluster)168 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)166 AggregateCall (org.apache.calcite.rel.core.AggregateCall)165 Pair (org.apache.calcite.util.Pair)163 TimestampString (org.apache.calcite.util.TimestampString)154 HashMap (java.util.HashMap)153