Search in sources :

Example 1 with TestTableProvider

use of org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.

the class ZetaSQLPushDownTest method initializeBeamTableProvider.

private static void initializeBeamTableProvider() {
    Table projectTable = getTable("InMemoryTableProject", PushDownOptions.PROJECT);
    Table bothTable = getTable("InMemoryTableBoth", PushDownOptions.BOTH);
    Row[] rows = { row(BASIC_SCHEMA, 100L, 1L, "one", 100L), row(BASIC_SCHEMA, 200L, 2L, "two", 200L) };
    tableProvider = new TestTableProvider();
    tableProvider.createTable(projectTable);
    tableProvider.createTable(bothTable);
    tableProvider.addRows(projectTable.getName(), rows);
    tableProvider.addRows(bothTable.getName(), rows);
}
Also used : TestTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider) Table(org.apache.beam.sdk.extensions.sql.meta.Table) Row(org.apache.beam.sdk.values.Row)

Example 2 with TestTableProvider

use of org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.

the class BeamAggregateProjectMergeRuleTest method buildUp.

@Before
public void buildUp() {
    TestTableProvider tableProvider = new TestTableProvider();
    Table projectTable = getTable("TEST_PROJECT", PushDownOptions.PROJECT);
    Table filterTable = getTable("TEST_FILTER", PushDownOptions.FILTER);
    Table noneTable = getTable("TEST_NONE", PushDownOptions.NONE);
    tableProvider.createTable(projectTable);
    tableProvider.createTable(filterTable);
    tableProvider.createTable(noneTable);
    // Rules are cost based, need rows to optimize!
    tableProvider.addRows("TEST_PROJECT", Row.withSchema(BASIC_SCHEMA).addValues(1, 2, "3", 4).build());
    tableProvider.addRows("TEST_FILTER", Row.withSchema(BASIC_SCHEMA).addValues(1, 2, "3", 4).build());
    tableProvider.addRows("TEST_NONE", Row.withSchema(BASIC_SCHEMA).addValues(1, 2, "3", 4).build());
    sqlEnv = BeamSqlEnv.inMemory(tableProvider);
}
Also used : TestTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider) Table(org.apache.beam.sdk.extensions.sql.meta.Table) Before(org.junit.Before)

Example 3 with TestTableProvider

use of org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.

the class BigQueryFilterTest method buildUp.

@Before
public void buildUp() {
    TestTableProvider tableProvider = new TestTableProvider();
    Table table = getTable("TEST", PushDownOptions.NONE);
    tableProvider.createTable(table);
    tableProvider.addRows(table.getName(), row(BASIC_SCHEMA, 100, 1, "one", (short) 100, true), row(BASIC_SCHEMA, 200, 2, "two", (short) 200, false));
    sqlEnv = BeamSqlEnv.builder(tableProvider).setPipelineOptions(PipelineOptionsFactory.create()).build();
}
Also used : TestTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider) Table(org.apache.beam.sdk.extensions.sql.meta.Table) Before(org.junit.Before)

Example 4 with TestTableProvider

use of org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.

the class ThreeTablesSchema method testSystemNotReorderingMediumSmallLarge.

@Test
public void testSystemNotReorderingMediumSmallLarge() {
    TestTableProvider tableProvider = new TestTableProvider();
    createThreeTables(tableProvider);
    BeamSqlEnv env = BeamSqlEnv.withTableProvider(tableProvider);
    // This is a correct ordered join because large table is on the top. It should not change that.
    BeamRelNode parsedQuery = env.parseQuery("select * from medium_table " + " JOIN small_table on medium_table.small_key = small_table.medium_key " + " JOIN large_table on large_table.medium_key = medium_table.large_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 5 with TestTableProvider

use of org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider in project beam by apache.

the class BeamDDLNestedTypesTest method executeCreateTableWith.

private Table executeCreateTableWith(String fieldType) throws SqlParseException {
    String createTable = "CREATE EXTERNAL TABLE tablename ( " + "fieldName " + fieldType + " ) " + "TYPE 'text' " + "LOCATION '/home/admin/person'\n";
    System.out.println(createTable);
    TestTableProvider tableProvider = new TestTableProvider();
    BeamSqlEnv env = BeamSqlEnv.withTableProvider(tableProvider);
    env.executeDdl(createTable);
    return tableProvider.getTables().get("tablename");
}
Also used : TestTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider) BeamSqlEnv(org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv)

Aggregations

TestTableProvider (org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider)32 Test (org.junit.Test)25 BeamSqlEnv (org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv)16 Before (org.junit.Before)8 Connection (java.sql.Connection)7 ResultSet (java.sql.ResultSet)7 Table (org.apache.beam.sdk.extensions.sql.meta.Table)7 Timestamp (java.sql.Timestamp)6 Schema (org.apache.beam.sdk.schemas.Schema)6 Row (org.apache.beam.sdk.values.Row)6 CalciteConnection (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteConnection)6 CalciteSchema (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema)6 ReadableInstant (org.joda.time.ReadableInstant)6 JSONObject (com.alibaba.fastjson.JSONObject)5 Calendar (java.util.Calendar)5 BeamRelNode (org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4