use of com.google.api.services.bigquery.model.TableRow in project beam by apache.
the class BigQueryIOTest method testWriteValidatesDataset.
private void testWriteValidatesDataset(boolean unbounded) throws Exception {
String projectId = "someproject";
String datasetId = "somedataset";
BigQueryOptions options = TestPipeline.testingPipelineOptions().as(BigQueryOptions.class);
options.setProject(projectId);
FakeBigQueryServices fakeBqServices = new FakeBigQueryServices().withJobService(new FakeJobService()).withDatasetService(new FakeDatasetService());
Pipeline p = TestPipeline.create(options);
TableReference tableRef = new TableReference();
tableRef.setDatasetId(datasetId);
tableRef.setTableId("sometable");
PCollection<TableRow> tableRows;
if (unbounded) {
tableRows = p.apply(GenerateSequence.from(0)).apply(MapElements.via(new SimpleFunction<Long, TableRow>() {
@Override
public TableRow apply(Long input) {
return null;
}
})).setCoder(TableRowJsonCoder.of());
} else {
tableRows = p.apply(Create.empty(TableRowJsonCoder.of()));
}
thrown.expect(RuntimeException.class);
// Message will be one of following depending on the execution environment.
thrown.expectMessage(Matchers.either(Matchers.containsString("Unable to confirm BigQuery dataset presence")).or(Matchers.containsString("BigQuery dataset not found for table")));
tableRows.apply(BigQueryIO.writeTableRows().to(tableRef).withCreateDisposition(CreateDisposition.CREATE_IF_NEEDED).withSchema(new TableSchema()).withTestServices(fakeBqServices));
p.run();
}
use of com.google.api.services.bigquery.model.TableRow in project beam by apache.
the class BigQueryIOTest method testCoder_nullCell.
// Test that BigQuery's special null placeholder objects can be encoded.
@Test
public void testCoder_nullCell() throws CoderException {
TableRow row = new TableRow();
row.set("temperature", Data.nullOf(Object.class));
row.set("max_temperature", Data.nullOf(Object.class));
byte[] bytes = CoderUtils.encodeToByteArray(TableRowJsonCoder.of(), row);
TableRow newRow = CoderUtils.decodeFromByteArray(TableRowJsonCoder.of(), bytes);
byte[] newBytes = CoderUtils.encodeToByteArray(TableRowJsonCoder.of(), newRow);
Assert.assertArrayEquals(bytes, newBytes);
}
use of com.google.api.services.bigquery.model.TableRow in project beam by apache.
the class BigQueryIOTest method testRuntimeOptionsNotCalledInApplyOutput.
@Test
public void testRuntimeOptionsNotCalledInApplyOutput() {
RuntimeTestOptions options = PipelineOptionsFactory.as(RuntimeTestOptions.class);
BigQueryOptions bqOptions = options.as(BigQueryOptions.class);
bqOptions.setTempLocation("gs://testbucket/testdir");
Pipeline pipeline = TestPipeline.create(options);
BigQueryIO.Write<TableRow> write = BigQueryIO.writeTableRows().to(options.getOutputTable()).withSchema(NestedValueProvider.of(options.getOutputSchema(), new JsonSchemaToTableSchema())).withoutValidation();
pipeline.apply(Create.empty(TableRowJsonCoder.of())).apply(write);
// Test that this doesn't throw.
DisplayData.from(write);
}
Aggregations