Search in sources :

Example 31 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.

the class PigRelBuilderStyleTest method testImplWithGroupByMultipleFields.

@Test
@Ignore("CALCITE-1751")
public void testImplWithGroupByMultipleFields() {
    final SchemaPlus schema = createTestSchema();
    final RelBuilder builder = createRelBuilder(schema);
    final RelNode node = builder.scan("t").aggregate(builder.groupKey("tc1", "tc0"), builder.count(false, "c", builder.field("tc1"))).build();
    final RelNode optimized = optimizeWithVolcano(node);
    assertScriptAndResults("t", getPigScript(optimized, schema), "t = LOAD 'target/data.txt" + "' USING PigStorage() AS (tc0:chararray, tc1:chararray);\n" + "t = GROUP t BY (tc0, tc1);\n" + "t = FOREACH t {\n" + "  GENERATE group.tc0 AS tc0, group.tc1 AS tc1, COUNT(t.tc1) AS c;\n" + "};", new String[] { "(a,1,1)", "(b,2,1)", "(c,3,1)" });
}
Also used : RelBuilder(org.apache.calcite.tools.RelBuilder) RelNode(org.apache.calcite.rel.RelNode) SchemaPlus(org.apache.calcite.schema.SchemaPlus) Ignore(org.junit.Ignore) Test(org.junit.Test) PigTest(org.apache.pig.pigunit.PigTest)

Example 32 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.

the class PigRelBuilderStyleTest method testImplWithJoin.

@Test
public void testImplWithJoin() throws Exception {
    final SchemaPlus schema = createTestSchema();
    final RelBuilder builder = createRelBuilder(schema);
    final RelNode node = builder.scan("t").scan("s").join(JoinRelType.INNER, builder.equals(builder.field(2, 0, "tc1"), builder.field(2, 1, "sc0"))).filter(builder.call(GREATER_THAN, builder.field("tc0"), builder.literal("a"))).build();
    final RelNode optimized = optimizeWithVolcano(node);
    assertScriptAndResults("t", getPigScript(optimized, schema), "t = LOAD 'target/data.txt" + "' USING PigStorage() AS (tc0:chararray, tc1:chararray);\n" + "t = FILTER t BY (tc0 > 'a');\n" + "s = LOAD 'target/data2.txt" + "' USING PigStorage() AS (sc0:chararray, sc1:chararray);\n" + "t = JOIN t BY tc1 , s BY sc0;", new String[] { "(b,2,2,label2)" });
}
Also used : RelBuilder(org.apache.calcite.tools.RelBuilder) RelNode(org.apache.calcite.rel.RelNode) SchemaPlus(org.apache.calcite.schema.SchemaPlus) Test(org.junit.Test) PigTest(org.apache.pig.pigunit.PigTest)

Example 33 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.

the class PigRelBuilderStyleTest method testScanAndFilter.

@Test
public void testScanAndFilter() throws Exception {
    final SchemaPlus schema = createTestSchema();
    final RelBuilder builder = createRelBuilder(schema);
    final RelNode node = builder.scan("t").filter(builder.call(GREATER_THAN, builder.field("tc0"), builder.literal("abc"))).build();
    final RelNode optimized = optimizeWithVolcano(node);
    assertScriptAndResults("t", getPigScript(optimized, schema), "t = LOAD 'target/data.txt" + "' USING PigStorage() AS (tc0:chararray, tc1:chararray);\n" + "t = FILTER t BY (tc0 > 'abc');", new String[] { "(b,2)", "(c,3)" });
}
Also used : RelBuilder(org.apache.calcite.tools.RelBuilder) RelNode(org.apache.calcite.rel.RelNode) SchemaPlus(org.apache.calcite.schema.SchemaPlus) Test(org.junit.Test) PigTest(org.apache.pig.pigunit.PigTest)

Example 34 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.

the class PigRelBuilderStyleTest method testImplWithMultipleFilters.

@Test
@Ignore("CALCITE-1751")
public void testImplWithMultipleFilters() {
    final SchemaPlus schema = createTestSchema();
    final RelBuilder builder = createRelBuilder(schema);
    final RelNode node = builder.scan("t").filter(builder.and(builder.call(GREATER_THAN, builder.field("tc0"), builder.literal("abc")), builder.call(EQUALS, builder.field("tc1"), builder.literal("3")))).build();
    final RelNode optimized = optimizeWithVolcano(node);
    assertScriptAndResults("t", getPigScript(optimized, schema), "t = LOAD 'target/data.txt" + "' USING PigStorage() AS (tc0:chararray, tc1:chararray);\n" + "t = FILTER t BY (tc0 > 'abc') AND (tc1 == '3');", new String[] { "(c,3)" });
}
Also used : RelBuilder(org.apache.calcite.tools.RelBuilder) RelNode(org.apache.calcite.rel.RelNode) SchemaPlus(org.apache.calcite.schema.SchemaPlus) Ignore(org.junit.Ignore) Test(org.junit.Test) PigTest(org.apache.pig.pigunit.PigTest)

Example 35 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.

the class PigRelBuilderStyleTest method testImplWithGroupByAndCount.

@Test
@Ignore("CALCITE-1751")
public void testImplWithGroupByAndCount() {
    final SchemaPlus schema = createTestSchema();
    final RelBuilder builder = createRelBuilder(schema);
    final RelNode node = builder.scan("t").aggregate(builder.groupKey("tc0"), builder.count(false, "c", builder.field("tc1"))).build();
    final RelNode optimized = optimizeWithVolcano(node);
    assertScriptAndResults("t", getPigScript(optimized, schema), "t = LOAD 'target/data.txt" + "' USING PigStorage() AS (tc0:chararray, tc1:chararray);\n" + "t = GROUP t BY (tc0);\n" + "t = FOREACH t {\n" + "  GENERATE group AS tc0, COUNT(t.tc1) AS c;\n" + "};", new String[] { "(a,1)", "(b,1)", "(c,1)" });
}
Also used : RelBuilder(org.apache.calcite.tools.RelBuilder) RelNode(org.apache.calcite.rel.RelNode) SchemaPlus(org.apache.calcite.schema.SchemaPlus) Ignore(org.junit.Ignore) Test(org.junit.Test) PigTest(org.apache.pig.pigunit.PigTest)

Aggregations

SchemaPlus (org.apache.calcite.schema.SchemaPlus)182 Test (org.junit.Test)57 CalciteConnection (org.apache.calcite.jdbc.CalciteConnection)42 Connection (java.sql.Connection)39 AbstractSchema (org.apache.calcite.schema.impl.AbstractSchema)33 ResultSet (java.sql.ResultSet)26 ReflectiveSchema (org.apache.calcite.adapter.java.ReflectiveSchema)24 RelNode (org.apache.calcite.rel.RelNode)21 Table (org.apache.calcite.schema.Table)20 SqlNode (org.apache.calcite.sql.SqlNode)19 IOException (java.io.IOException)17 Statement (java.sql.Statement)17 PreparedStatement (java.sql.PreparedStatement)16 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)15 AbstractSchema (org.apache.drill.exec.store.AbstractSchema)15 ArrayList (java.util.ArrayList)14 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)14 SQLException (java.sql.SQLException)13 Properties (java.util.Properties)13 SchemaPlus (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus)13