Search in sources :

Example 56 with BeamSqlEnv

use of org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv in project beam by apache.

the class ThreeTablesSchema method testSystemReorderingLargeMediumSmall.

@Test
public void testSystemReorderingLargeMediumSmall() {
    TestTableProvider tableProvider = new TestTableProvider();
    createThreeTables(tableProvider);
    BeamSqlEnv env = BeamSqlEnv.withTableProvider(tableProvider);
    // This is Join(Join(large, medium), small) which should be converted to a join that large table
    // is on the top.
    BeamRelNode parsedQuery = env.parseQuery("select * from large_table " + " JOIN medium_table on large_table.medium_key = medium_table.large_key " + " JOIN small_table on medium_table.small_key = small_table.medium_key ");
    assertTopTableInJoins(parsedQuery, "large_table");
}
Also used : TestTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider) BeamRelNode(org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode) BeamSqlEnv(org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv) Test(org.junit.Test)

Example 57 with BeamSqlEnv

use of org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv in project beam by apache.

the class BigtableTableIT method writeData.

private void writeData() {
    Pipeline p = Pipeline.create(options);
    BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(new BigtableTableProvider());
    sqlEnv.executeDdl(createFlatTableString(TABLE_ID, location()));
    String query = String.format("INSERT INTO `%s`(key, boolColumn, longColumn, stringColumn, doubleColumn) " + "VALUES ('key1', FALSE, CAST(1 as bigint), 'string1', 1.0)", TABLE_ID);
    BeamSqlRelUtils.toPCollection(p, sqlEnv.parseQuery(query));
    p.run().waitUntilFinish();
}
Also used : BeamSqlEnv(org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv) BigtableTableTestUtils.createFlatTableString(org.apache.beam.sdk.extensions.sql.meta.provider.bigtable.BigtableTableTestUtils.createFlatTableString) BigtableTableTestUtils.createFullTableString(org.apache.beam.sdk.extensions.sql.meta.provider.bigtable.BigtableTableTestUtils.createFullTableString) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Pipeline(org.apache.beam.sdk.Pipeline)

Example 58 with BeamSqlEnv

use of org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv in project beam by apache.

the class BigtableTableIT method readData.

private void readData() {
    Pipeline p = Pipeline.create(options);
    BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(new BigtableTableProvider());
    sqlEnv.executeDdl(createFullTableString(TABLE_ID, location()));
    String query = String.format("SELECT key, " + "  t.familyTest.boolColumn, " + "  t.familyTest.longColumn.val AS longValue, " + "  t.familyTest.longColumn.timestampMicros, " + "  t.familyTest.longColumn.labels, " + "  t.familyTest.stringColumn, " + "  t.familyTest.doubleColumn " + "FROM `%s` t", TABLE_ID);
    PCollection<Row> rows = BeamSqlRelUtils.toPCollection(p, sqlEnv.parseQuery(query)).apply(MapElements.via(new ReplaceTimestamp())).setRowSchema(expectedFullSchema());
    PAssert.that(rows).containsInAnyOrder(expectedFullRow(1));
    p.run().waitUntilFinish();
}
Also used : BeamSqlEnv(org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv) BigtableTableTestUtils.createFlatTableString(org.apache.beam.sdk.extensions.sql.meta.provider.bigtable.BigtableTableTestUtils.createFlatTableString) BigtableTableTestUtils.createFullTableString(org.apache.beam.sdk.extensions.sql.meta.provider.bigtable.BigtableTableTestUtils.createFullTableString) Row(org.apache.beam.sdk.values.Row) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Pipeline(org.apache.beam.sdk.Pipeline)

Example 59 with BeamSqlEnv

use of org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv in project beam by apache.

the class BigtableTableIT method readFlatData.

private void readFlatData() {
    Pipeline p = Pipeline.create(options);
    BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(new BigtableTableProvider());
    sqlEnv.executeDdl(createFlatTableString(TABLE_ID, location()));
    String query = "SELECT * FROM `" + TABLE_ID + "`";
    PCollection<Row> flatRows = BeamSqlRelUtils.toPCollection(p, sqlEnv.parseQuery(query));
    PAssert.that(flatRows).containsInAnyOrder(expectedFlatRow(1));
    p.run().waitUntilFinish();
}
Also used : BeamSqlEnv(org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv) BigtableTableTestUtils.createFlatTableString(org.apache.beam.sdk.extensions.sql.meta.provider.bigtable.BigtableTableTestUtils.createFlatTableString) BigtableTableTestUtils.createFullTableString(org.apache.beam.sdk.extensions.sql.meta.provider.bigtable.BigtableTableTestUtils.createFullTableString) Row(org.apache.beam.sdk.values.Row) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Pipeline(org.apache.beam.sdk.Pipeline)

Example 60 with BeamSqlEnv

use of org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv in project beam by apache.

the class BigtableTableWithRowsTest method testSimpleSelect.

@Test
public void testSimpleSelect() {
    createReadTable(TABLE, emulatorWrapper);
    BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(new BigtableTableProvider());
    sqlEnv.executeDdl(createFullTableString(TABLE, location()));
    String query = "SELECT key, \n" + "  bt.familyTest.boolColumn, \n" + "  bt.familyTest.longColumn.val AS longValue, \n" + "  bt.familyTest.longColumn.timestampMicros, \n" + "  bt.familyTest.longColumn.labels, \n" + "  bt.familyTest.stringColumn, \n" + "  bt.familyTest.doubleColumn \n" + "FROM beamTable bt";
    sqlEnv.parseQuery(query);
    PCollection<Row> queryOutput = BeamSqlRelUtils.toPCollection(readPipeline, sqlEnv.parseQuery(query));
    assertThat(queryOutput.getSchema(), equalTo(expectedFullSchema()));
    PCollection<Row> sorted = queryOutput.apply(MapElements.via(new SortByTimestamp())).setRowSchema(expectedFullSchema());
    PAssert.that(sorted).containsInAnyOrder(expectedFullRow(KEY1), expectedFullRow(KEY2));
    readPipeline.run().waitUntilFinish();
}
Also used : BeamSqlEnv(org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv) BigtableTableTestUtils.createFullTableString(org.apache.beam.sdk.extensions.sql.meta.provider.bigtable.BigtableTableTestUtils.createFullTableString) Row(org.apache.beam.sdk.values.Row) BigtableTableTestUtils.expectedFullRow(org.apache.beam.sdk.extensions.sql.meta.provider.bigtable.BigtableTableTestUtils.expectedFullRow) Test(org.junit.Test)

Aggregations

BeamSqlEnv (org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv)61 Test (org.junit.Test)54 Row (org.apache.beam.sdk.values.Row)36 TestTableProvider (org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider)16 PipelineResult (org.apache.beam.sdk.PipelineResult)10 State (org.apache.beam.sdk.PipelineResult.State)10 Schema (org.apache.beam.sdk.schemas.Schema)10 TableProvider (org.apache.beam.sdk.extensions.sql.meta.provider.TableProvider)8 Arrays (java.util.Arrays)6 List (java.util.List)6 Map (java.util.Map)6 ExecutorService (java.util.concurrent.ExecutorService)6 Collectors (java.util.stream.Collectors)6 PayloadMessages (org.apache.beam.sdk.extensions.protobuf.PayloadMessages)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 IOException (java.io.IOException)5 Serializable (java.io.Serializable)5 StandardCharsets (java.nio.charset.StandardCharsets)5