use of com.google.api.services.bigquery.model.TableReference in project beam by apache.
the class BigQueryTableSource method createReader.
@Override
public BoundedReader<TableRow> createReader(PipelineOptions options) throws IOException {
BigQueryOptions bqOptions = options.as(BigQueryOptions.class);
checkState(jsonTable.isAccessible());
TableReference tableRef = BigQueryIO.JSON_FACTORY.fromString(jsonTable.get(), TableReference.class);
return new BigQueryReader(this, bqServices.getReaderFromTable(bqOptions, tableRef));
}
use of com.google.api.services.bigquery.model.TableReference in project beam by apache.
the class BigQueryTableSource method getEstimatedSizeBytes.
@Override
public synchronized long getEstimatedSizeBytes(PipelineOptions options) throws Exception {
if (tableSizeBytes.get() == null) {
TableReference table = setDefaultProjectIfAbsent(options.as(BigQueryOptions.class), BigQueryIO.JSON_FACTORY.fromString(jsonTable.get(), TableReference.class));
Long numBytes = bqServices.getDatasetService(options.as(BigQueryOptions.class)).getTable(table).getNumBytes();
tableSizeBytes.compareAndSet(null, numBytes);
}
return tableSizeBytes.get();
}
use of com.google.api.services.bigquery.model.TableReference in project beam by apache.
the class BigQueryTableSource method getTableToExtract.
@Override
protected TableReference getTableToExtract(BigQueryOptions bqOptions) throws IOException {
checkState(jsonTable.isAccessible());
TableReference tableReference = BigQueryIO.JSON_FACTORY.fromString(jsonTable.get(), TableReference.class);
return setDefaultProjectIfAbsent(bqOptions, tableReference);
}
use of com.google.api.services.bigquery.model.TableReference in project beam by apache.
the class CreateTables method possibleCreateTable.
private void possibleCreateTable(BigQueryOptions options, TableDestination tableDestination, TableSchema tableSchema) throws InterruptedException, IOException {
String tableSpec = tableDestination.getTableSpec();
TableReference tableReference = tableDestination.getTableReference();
String tableDescription = tableDestination.getTableDescription();
if (createDisposition != createDisposition.CREATE_NEVER && !createdTables.contains(tableSpec)) {
synchronized (createdTables) {
// Another thread may have succeeded in creating the table in the meanwhile, so
// check again. This check isn't needed for correctness, but we add it to prevent
// every thread from attempting a create and overwhelming our BigQuery quota.
DatasetService datasetService = bqServices.getDatasetService(options);
if (!createdTables.contains(tableSpec)) {
if (datasetService.getTable(tableReference) == null) {
datasetService.createTable(new Table().setTableReference(tableReference).setSchema(tableSchema).setDescription(tableDescription));
}
createdTables.add(tableSpec);
}
}
}
}
Aggregations