Search in sources :

Example 1 with Streamingbuffer

use of com.google.api.services.bigquery.model.Streamingbuffer in project beam by apache.

the class BigQueryIOStorageReadTest method doTableSourceEstimatedSizeTest.

private void doTableSourceEstimatedSizeTest(boolean useStreamingBuffer) throws Exception {
    fakeDatasetService.createDataset("foo.com:project", "dataset", "", "", null);
    TableReference tableRef = BigQueryHelpers.parseTableSpec("foo.com:project:dataset.table");
    Table table = new Table().setTableReference(tableRef).setNumBytes(100L);
    if (useStreamingBuffer) {
        table.setStreamingBuffer(new Streamingbuffer().setEstimatedBytes(BigInteger.TEN));
    }
    fakeDatasetService.createTable(table);
    BigQueryStorageTableSource<TableRow> tableSource = BigQueryStorageTableSource.create(ValueProvider.StaticValueProvider.of(tableRef), null, null, new TableRowParser(), TableRowJsonCoder.of(), new FakeBigQueryServices().withDatasetService(fakeDatasetService));
    assertEquals(100, tableSource.getEstimatedSizeBytes(options));
}
Also used : TableReference(com.google.api.services.bigquery.model.TableReference) Table(com.google.api.services.bigquery.model.Table) TableRow(com.google.api.services.bigquery.model.TableRow) FakeBigQueryServices(org.apache.beam.sdk.io.gcp.testing.FakeBigQueryServices) Streamingbuffer(com.google.api.services.bigquery.model.Streamingbuffer) TableRowParser(org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO.TableRowParser)

Example 2 with Streamingbuffer

use of com.google.api.services.bigquery.model.Streamingbuffer in project beam by apache.

the class BigQueryIOReadTest method testEstimatedSizeWithStreamingBuffer.

@Test
public void testEstimatedSizeWithStreamingBuffer() throws Exception {
    List<TableRow> data = ImmutableList.of(new TableRow().set("name", "a").set("number", 1L), new TableRow().set("name", "b").set("number", 2L), new TableRow().set("name", "c").set("number", 3L), new TableRow().set("name", "d").set("number", 4L), new TableRow().set("name", "e").set("number", 5L), new TableRow().set("name", "f").set("number", 6L));
    TableReference table = BigQueryHelpers.parseTableSpec("project:data_set.table_name");
    fakeDatasetService.createDataset("project", "data_set", "", "", null);
    fakeDatasetService.createTable(new Table().setTableReference(table).setSchema(new TableSchema().setFields(ImmutableList.of(new TableFieldSchema().setName("name").setType("STRING"), new TableFieldSchema().setName("number").setType("INTEGER")))).setStreamingBuffer(new Streamingbuffer().setEstimatedBytes(BigInteger.valueOf(10))));
    fakeDatasetService.insertAll(table, data, null);
    String stepUuid = "testStepUuid";
    BoundedSource<TableRow> bqSource = BigQueryTableSourceDef.create(fakeBqServices, ValueProvider.StaticValueProvider.of(table)).toSource(stepUuid, TableRowJsonCoder.of(), BigQueryIO.TableRowParser.INSTANCE, false);
    PipelineOptions options = PipelineOptionsFactory.create();
    // Each row should have 24 bytes (See StringUtf8Coder in detail):
    // first 1 byte indicating length and following 23 bytes: {"name":"a","number":1}
    // 10 bytes comes from the estimated bytes of the Streamingbuffer
    long expectedSize = 24L * data.size() + 10;
    assertEquals(expectedSize, bqSource.getEstimatedSizeBytes(options));
}
Also used : TableReference(com.google.api.services.bigquery.model.TableReference) BigQueryResourceNaming.createTempTableReference(org.apache.beam.sdk.io.gcp.bigquery.BigQueryResourceNaming.createTempTableReference) Table(com.google.api.services.bigquery.model.Table) TableSchema(com.google.api.services.bigquery.model.TableSchema) PipelineOptions(org.apache.beam.sdk.options.PipelineOptions) TableRow(com.google.api.services.bigquery.model.TableRow) ByteString(com.google.protobuf.ByteString) TableFieldSchema(com.google.api.services.bigquery.model.TableFieldSchema) Streamingbuffer(com.google.api.services.bigquery.model.Streamingbuffer) Test(org.junit.Test)

Aggregations

Streamingbuffer (com.google.api.services.bigquery.model.Streamingbuffer)2 Table (com.google.api.services.bigquery.model.Table)2 TableReference (com.google.api.services.bigquery.model.TableReference)2 TableRow (com.google.api.services.bigquery.model.TableRow)2 TableFieldSchema (com.google.api.services.bigquery.model.TableFieldSchema)1 TableSchema (com.google.api.services.bigquery.model.TableSchema)1 ByteString (com.google.protobuf.ByteString)1 TableRowParser (org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO.TableRowParser)1 BigQueryResourceNaming.createTempTableReference (org.apache.beam.sdk.io.gcp.bigquery.BigQueryResourceNaming.createTempTableReference)1 FakeBigQueryServices (org.apache.beam.sdk.io.gcp.testing.FakeBigQueryServices)1 PipelineOptions (org.apache.beam.sdk.options.PipelineOptions)1 Test (org.junit.Test)1