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));
}
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));
}
Aggregations