Search in sources :

Example 61 with TableReference

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));
}
Also used : TableReference(com.google.api.services.bigquery.model.TableReference)

Example 62 with TableReference

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();
}
Also used : TableReference(com.google.api.services.bigquery.model.TableReference)

Example 63 with TableReference

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);
}
Also used : TableReference(com.google.api.services.bigquery.model.TableReference)

Example 64 with 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);
            }
        }
    }
}
Also used : TableReference(com.google.api.services.bigquery.model.TableReference) Table(com.google.api.services.bigquery.model.Table) DatasetService(org.apache.beam.sdk.io.gcp.bigquery.BigQueryServices.DatasetService)

Aggregations

TableReference (com.google.api.services.bigquery.model.TableReference)64 Test (org.junit.Test)32 TableRow (com.google.api.services.bigquery.model.TableRow)24 Table (com.google.api.services.bigquery.model.Table)20 BigQueryHelpers.createTempTableReference (org.apache.beam.sdk.io.gcp.bigquery.BigQueryHelpers.createTempTableReference)17 DatasetServiceImpl (org.apache.beam.sdk.io.gcp.bigquery.BigQueryServicesImpl.DatasetServiceImpl)17 TableSchema (com.google.api.services.bigquery.model.TableSchema)12 HashBasedTable (com.google.common.collect.HashBasedTable)10 BigQueryHelpers.toJsonString (org.apache.beam.sdk.io.gcp.bigquery.BigQueryHelpers.toJsonString)10 JobStatus (com.google.api.services.bigquery.model.JobStatus)9 Pipeline (org.apache.beam.sdk.Pipeline)9 ValueInSingleWindow (org.apache.beam.sdk.values.ValueInSingleWindow)8 JobStatistics (com.google.api.services.bigquery.model.JobStatistics)7 JsonSchemaToTableSchema (org.apache.beam.sdk.io.gcp.bigquery.BigQueryHelpers.JsonSchemaToTableSchema)7 Job (com.google.api.services.bigquery.model.Job)6 TableFieldSchema (com.google.api.services.bigquery.model.TableFieldSchema)6 IOException (java.io.IOException)6 MockSleeper (com.google.api.client.testing.util.MockSleeper)5 Dataset (com.google.api.services.bigquery.model.Dataset)5 ErrorProto (com.google.api.services.bigquery.model.ErrorProto)5