Search in sources :

Example 51 with Table

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

the class BigQueryTableProviderTest method testDefaultMethod_whenPropertiesAreNotSet.

@Test
public void testDefaultMethod_whenPropertiesAreNotSet() {
    Table table = fakeTable("hello");
    BigQueryTable sqlTable = (BigQueryTable) provider.buildBeamSqlTable(table);
    assertEquals(Method.DIRECT_READ, sqlTable.method);
}
Also used : Table(org.apache.beam.sdk.extensions.sql.meta.Table) BeamSqlTable(org.apache.beam.sdk.extensions.sql.meta.BeamSqlTable) Test(org.junit.Test)

Example 52 with Table

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

the class BigQueryTableProviderTest method testSelectExportMethod.

@Test
public void testSelectExportMethod() {
    Table table = fakeTableWithProperties("hello", "{ " + METHOD_PROPERTY + ": " + "\"" + Method.EXPORT.toString() + "\" }");
    BigQueryTable sqlTable = (BigQueryTable) provider.buildBeamSqlTable(table);
    assertEquals(Method.EXPORT, sqlTable.method);
}
Also used : Table(org.apache.beam.sdk.extensions.sql.meta.Table) BeamSqlTable(org.apache.beam.sdk.extensions.sql.meta.BeamSqlTable) Test(org.junit.Test)

Example 53 with Table

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

the class BigQueryTableProviderTest method testSelectWriteDispositionMethodEmpty.

@Test
public void testSelectWriteDispositionMethodEmpty() {
    Table table = fakeTableWithProperties("hello", "{ " + WRITE_DISPOSITION_PROPERTY + ": " + "\"" + WriteDisposition.WRITE_EMPTY.toString() + "\" }");
    BigQueryTable sqlTable = (BigQueryTable) provider.buildBeamSqlTable(table);
    assertEquals(WriteDisposition.WRITE_EMPTY, sqlTable.writeDisposition);
}
Also used : Table(org.apache.beam.sdk.extensions.sql.meta.Table) BeamSqlTable(org.apache.beam.sdk.extensions.sql.meta.BeamSqlTable) Test(org.junit.Test)

Example 54 with Table

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

the class BigQueryTableProviderTest method testSelectDefaultMethodExplicitly.

@Test
public void testSelectDefaultMethodExplicitly() {
    Table table = fakeTableWithProperties("hello", "{ " + METHOD_PROPERTY + ": " + "\"" + Method.DEFAULT.toString() + "\" }");
    BigQueryTable sqlTable = (BigQueryTable) provider.buildBeamSqlTable(table);
    assertEquals(Method.DEFAULT, sqlTable.method);
}
Also used : Table(org.apache.beam.sdk.extensions.sql.meta.Table) BeamSqlTable(org.apache.beam.sdk.extensions.sql.meta.BeamSqlTable) Test(org.junit.Test)

Example 55 with Table

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

the class BigQueryRowCountIT method testPipelineOptionInjection.

/**
 * This tests if the pipeline options are injected in the path of SQL Transform.
 */
@Test
public void testPipelineOptionInjection() {
    BigQueryTestTableProvider provider = new BigQueryTestTableProvider();
    Table table = getTable("testTable", bigQuery.tableSpec());
    provider.addTable("testTable", table);
    pipeline.apply(Create.of(new TableRow().set("id", 1).set("name", "name1"), new TableRow().set("id", 2).set("name", "name2"), new TableRow().set("id", 3).set("name", "name3")).withCoder(TableRowJsonCoder.of())).apply(BigQueryIO.writeTableRows().to(bigQuery.tableSpec()).withSchema(new TableSchema().setFields(ImmutableList.of(new TableFieldSchema().setName("id").setType("INTEGER"), new TableFieldSchema().setName("name").setType("STRING")))).withoutValidation());
    pipeline.run().waitUntilFinish();
    // changing pipeline options
    readingPipeline.getOptions().setJobName(FAKE_JOB_NAME);
    // Reading from the table should update the statistics of bigQuery table
    readingPipeline.apply(SqlTransform.query(" select * from testTable ").withDefaultTableProvider("bigquery", provider));
    readingPipeline.run().waitUntilFinish();
    BigQueryTestTable sqlTable = (BigQueryTestTable) provider.buildBeamSqlTable(table);
    assertEquals(FAKE_JOB_NAME, sqlTable.getJobName());
}
Also used : Table(org.apache.beam.sdk.extensions.sql.meta.Table) BeamSqlTable(org.apache.beam.sdk.extensions.sql.meta.BeamSqlTable) TableSchema(com.google.api.services.bigquery.model.TableSchema) TableRow(com.google.api.services.bigquery.model.TableRow) TableFieldSchema(com.google.api.services.bigquery.model.TableFieldSchema) Test(org.junit.Test)

Aggregations

Table (org.apache.beam.sdk.extensions.sql.meta.Table)65 Test (org.junit.Test)49 BeamSqlTable (org.apache.beam.sdk.extensions.sql.meta.BeamSqlTable)37 Schema (org.apache.beam.sdk.schemas.Schema)9 Before (org.junit.Before)9 InMemoryMetaStore (org.apache.beam.sdk.extensions.sql.meta.store.InMemoryMetaStore)8 TestTableProvider (org.apache.beam.sdk.extensions.sql.meta.provider.test.TestTableProvider)7 TextTableProvider (org.apache.beam.sdk.extensions.sql.meta.provider.text.TextTableProvider)5 BeamTableStatistics (org.apache.beam.sdk.extensions.sql.impl.BeamTableStatistics)4 JSONObject (com.alibaba.fastjson.JSONObject)3 Row (org.apache.beam.sdk.values.Row)3 TableFieldSchema (com.google.api.services.bigquery.model.TableFieldSchema)2 TableRow (com.google.api.services.bigquery.model.TableRow)2 TableSchema (com.google.api.services.bigquery.model.TableSchema)2 Property (com.pholser.junit.quickcheck.Property)2 List (java.util.List)2 BeamSqlCli (org.apache.beam.sdk.extensions.sql.BeamSqlCli)2 InvalidTableException (org.apache.beam.sdk.extensions.sql.meta.provider.InvalidTableException)2 BigtableTableTestUtils.createReadTable (org.apache.beam.sdk.extensions.sql.meta.provider.bigtable.BigtableTableTestUtils.createReadTable)2 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)2