Search in sources :

Example 1 with BeamSqlTable

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

the class SqlTransform method toTableMap.

@SuppressWarnings("unchecked")
private Map<String, BeamSqlTable> toTableMap(PInput inputs) {
    /**
     * A single PCollection is transformed to a table named PCOLLECTION, other input types are
     * expanded and converted to tables using the tags as names.
     */
    if (inputs instanceof PCollection) {
        PCollection<?> pCollection = (PCollection<?>) inputs;
        return ImmutableMap.of(PCOLLECTION_NAME, new BeamPCollectionTable(pCollection));
    }
    ImmutableMap.Builder<String, BeamSqlTable> tables = ImmutableMap.builder();
    for (Map.Entry<TupleTag<?>, PValue> input : inputs.expand().entrySet()) {
        PCollection<?> pCollection = (PCollection<?>) input.getValue();
        tables.put(input.getKey().getId(), new BeamPCollectionTable(pCollection));
    }
    return tables.build();
}
Also used : PCollection(org.apache.beam.sdk.values.PCollection) BeamSqlTable(org.apache.beam.sdk.extensions.sql.meta.BeamSqlTable) BeamPCollectionTable(org.apache.beam.sdk.extensions.sql.impl.schema.BeamPCollectionTable) TupleTag(org.apache.beam.sdk.values.TupleTag) PValue(org.apache.beam.sdk.values.PValue) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMap) ImmutableMap(org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableMap)

Example 2 with BeamSqlTable

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

the class BigQueryRowCountIT method testEmptyTable.

@Test
public void testEmptyTable() {
    BigQueryTableProvider provider = new BigQueryTableProvider();
    Table table = getTable("testTable", bigQuery.tableSpec());
    BeamSqlTable sqlTable = provider.buildBeamSqlTable(table);
    BeamTableStatistics size = sqlTable.getTableStatistics(TestPipeline.testingPipelineOptions());
    assertNotNull(size);
    assertEquals(0d, size.getRowCount(), 0.1);
}
Also used : Table(org.apache.beam.sdk.extensions.sql.meta.Table) BeamSqlTable(org.apache.beam.sdk.extensions.sql.meta.BeamSqlTable) BeamSqlTable(org.apache.beam.sdk.extensions.sql.meta.BeamSqlTable) BeamTableStatistics(org.apache.beam.sdk.extensions.sql.impl.BeamTableStatistics) Test(org.junit.Test)

Example 3 with BeamSqlTable

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

the class SchemaIOTableProviderWrapperTest method testBuildIOReader.

@Test
public void testBuildIOReader() {
    TestSchemaIOTableProviderWrapper provider = new TestSchemaIOTableProviderWrapper();
    BeamSqlTable beamSqlTable = provider.buildBeamSqlTable(testTable);
    PCollection<Row> result = beamSqlTable.buildIOReader(pipeline.begin());
    PAssert.that(result).containsInAnyOrder(rows);
    pipeline.run();
}
Also used : BeamSqlTable(org.apache.beam.sdk.extensions.sql.meta.BeamSqlTable) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 4 with BeamSqlTable

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

the class KafkaTableProviderTest method testBuildBeamSqlProtoTable.

@Test
public void testBuildBeamSqlProtoTable() {
    Table table = mockProtoTable("hello", PayloadMessages.SimpleMessage.class);
    BeamSqlTable sqlTable = provider.buildBeamSqlTable(table);
    assertNotNull(sqlTable);
    assertTrue(sqlTable instanceof BeamKafkaTable);
    BeamKafkaTable kafkaTable = (BeamKafkaTable) sqlTable;
    assertEquals(LOCATION_BROKER, kafkaTable.getBootstrapServers());
    assertEquals(ImmutableList.of(LOCATION_TOPIC), kafkaTable.getTopics());
}
Also used : Table(org.apache.beam.sdk.extensions.sql.meta.Table) BeamSqlTable(org.apache.beam.sdk.extensions.sql.meta.BeamSqlTable) BeamSqlTable(org.apache.beam.sdk.extensions.sql.meta.BeamSqlTable) PayloadMessages(org.apache.beam.sdk.extensions.protobuf.PayloadMessages) Test(org.junit.Test)

Example 5 with BeamSqlTable

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

the class KafkaTableProviderTest method testBuildBeamSqlAvroTable.

@Test
public void testBuildBeamSqlAvroTable() {
    Table table = mockTable("hello", "avro");
    BeamSqlTable sqlTable = provider.buildBeamSqlTable(table);
    assertNotNull(sqlTable);
    assertTrue(sqlTable instanceof BeamKafkaTable);
    BeamKafkaTable kafkaTable = (BeamKafkaTable) sqlTable;
    assertEquals(LOCATION_BROKER, kafkaTable.getBootstrapServers());
    assertEquals(ImmutableList.of(LOCATION_TOPIC), kafkaTable.getTopics());
}
Also used : Table(org.apache.beam.sdk.extensions.sql.meta.Table) BeamSqlTable(org.apache.beam.sdk.extensions.sql.meta.BeamSqlTable) BeamSqlTable(org.apache.beam.sdk.extensions.sql.meta.BeamSqlTable) Test(org.junit.Test)

Aggregations

BeamSqlTable (org.apache.beam.sdk.extensions.sql.meta.BeamSqlTable)31 Test (org.junit.Test)25 Table (org.apache.beam.sdk.extensions.sql.meta.Table)21 Schema (org.apache.beam.sdk.schemas.Schema)5 BeamTableStatistics (org.apache.beam.sdk.extensions.sql.impl.BeamTableStatistics)3 DefaultTableFilter (org.apache.beam.sdk.extensions.sql.meta.DefaultTableFilter)2 Row (org.apache.beam.sdk.values.Row)2 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)2 JSONObject (com.alibaba.fastjson.JSONObject)1 TableFieldSchema (com.google.api.services.bigquery.model.TableFieldSchema)1 TableRow (com.google.api.services.bigquery.model.TableRow)1 TableSchema (com.google.api.services.bigquery.model.TableSchema)1 AutoService (com.google.auto.service.AutoService)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 PayloadMessages (org.apache.beam.sdk.extensions.protobuf.PayloadMessages)1 BeamSqlSeekableTable (org.apache.beam.sdk.extensions.sql.BeamSqlSeekableTable)1