Search in sources :

Example 6 with TableProvider

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

the class BeamSqlMultipleSchemasTest method testSelectFromExtraSchema.

@Test
public void testSelectFromExtraSchema() {
    PCollection<Row> inputMain = pipeline.apply("mainInput", create(row(1, "pcollection_1"), row(2, "pcollection_2")));
    PCollection<Row> inputExtra = pipeline.apply("extraInput", create(row(1, "_extra_table_1"), row(2, "_extra_table_2")));
    TableProvider extraInputProvider = extraTableProvider("extraTable", inputExtra);
    PCollection<Row> result = inputMain.apply(SqlTransform.query("SELECT f_int, f_string FROM extraSchema.extraTable").withTableProvider("extraSchema", extraInputProvider));
    PAssert.that(result).containsInAnyOrder(row(1, "_extra_table_1"), row(2, "_extra_table_2"));
    pipeline.run();
}
Also used : Row(org.apache.beam.sdk.values.Row) ReadOnlyTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.ReadOnlyTableProvider) TableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.TableProvider) Test(org.junit.Test)

Example 7 with TableProvider

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

the class BeamSqlMultipleSchemasTest method testOverrideUnqualifiedMainSchema.

@Test
public void testOverrideUnqualifiedMainSchema() {
    PCollection<Row> inputMain = pipeline.apply("mainInput", create(row(1, "pcollection_1"), row(2, "pcollection_2")));
    PCollection<Row> inputExtra = pipeline.apply("extraInput", create(row(1, "_extra_table_1"), row(2, "_extra_table_2")));
    TableProvider extraInputProvider = extraTableProvider("extraTable", inputExtra);
    PCollection<Row> result = inputMain.apply(SqlTransform.query("SELECT f_int, f_string FROM extraTable").withTableProvider("beam", extraInputProvider));
    PAssert.that(result).containsInAnyOrder(row(1, "_extra_table_1"), row(2, "_extra_table_2"));
    pipeline.run();
}
Also used : Row(org.apache.beam.sdk.values.Row) ReadOnlyTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.ReadOnlyTableProvider) TableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.TableProvider) Test(org.junit.Test)

Example 8 with TableProvider

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

the class BeamSqlMultipleSchemasTest method testSetDefaultQualifiedSchema.

@Test
public void testSetDefaultQualifiedSchema() {
    PCollection<Row> inputMain = pipeline.apply("mainInput", create(row(1, "pcollection_1"), row(2, "pcollection_2")));
    PCollection<Row> inputExtra = pipeline.apply("extraInput", create(row(1, "_extra_table_1"), row(2, "_extra_table_2")));
    TableProvider extraInputProvider = extraTableProvider("extraTable", inputExtra);
    PCollection<Row> result = inputMain.apply(SqlTransform.query("SELECT f_int, f_string FROM extraSchema.extraTable").withDefaultTableProvider("extraSchema", extraInputProvider));
    PAssert.that(result).containsInAnyOrder(row(1, "_extra_table_1"), row(2, "_extra_table_2"));
    pipeline.run();
}
Also used : Row(org.apache.beam.sdk.values.Row) ReadOnlyTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.ReadOnlyTableProvider) TableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.TableProvider) Test(org.junit.Test)

Example 9 with TableProvider

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

the class BeamSqlMultipleSchemasTest method testOverrideQualifiedMainSchema.

@Test
public void testOverrideQualifiedMainSchema() {
    PCollection<Row> inputMain = pipeline.apply("mainInput", create(row(1, "pcollection_1"), row(2, "pcollection_2")));
    PCollection<Row> inputExtra = pipeline.apply("extraInput", create(row(1, "_extra_table_1"), row(2, "_extra_table_2")));
    TableProvider extraInputProvider = extraTableProvider("extraTable", inputExtra);
    PCollection<Row> result = inputMain.apply(SqlTransform.query("SELECT f_int, f_string FROM beam.extraTable").withTableProvider("beam", extraInputProvider));
    PAssert.that(result).containsInAnyOrder(row(1, "_extra_table_1"), row(2, "_extra_table_2"));
    pipeline.run();
}
Also used : Row(org.apache.beam.sdk.values.Row) ReadOnlyTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.ReadOnlyTableProvider) TableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.TableProvider) Test(org.junit.Test)

Example 10 with TableProvider

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

the class BeamSqlMultipleSchemasTest method testSetDefaultUnqualifiedSchema.

@Test
public void testSetDefaultUnqualifiedSchema() {
    PCollection<Row> inputMain = pipeline.apply("mainInput", create(row(1, "pcollection_1"), row(2, "pcollection_2")));
    PCollection<Row> inputExtra = pipeline.apply("extraInput", create(row(1, "_extra_table_1"), row(2, "_extra_table_2")));
    TableProvider extraInputProvider = extraTableProvider("extraTable", inputExtra);
    PCollection<Row> result = inputMain.apply(SqlTransform.query("SELECT f_int, f_string FROM extraTable").withDefaultTableProvider("extraSchema", extraInputProvider));
    PAssert.that(result).containsInAnyOrder(row(1, "_extra_table_1"), row(2, "_extra_table_2"));
    pipeline.run();
}
Also used : Row(org.apache.beam.sdk.values.Row) ReadOnlyTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.ReadOnlyTableProvider) TableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.TableProvider) Test(org.junit.Test)

Aggregations

TableProvider (org.apache.beam.sdk.extensions.sql.meta.provider.TableProvider)13 Row (org.apache.beam.sdk.values.Row)11 Test (org.junit.Test)11 ReadOnlyTableProvider (org.apache.beam.sdk.extensions.sql.meta.provider.ReadOnlyTableProvider)9 BeamSqlEnv (org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv)4 DirectOptions (org.apache.beam.runners.direct.DirectOptions)2 InMemoryMetaStore (org.apache.beam.sdk.extensions.sql.meta.store.InMemoryMetaStore)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 StandardCharsets (java.nio.charset.StandardCharsets)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1