Search in sources :

Example 11 with TableId

use of com.google.cloud.bigquery.TableId in project presto by prestodb.

the class BigQuerySplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layout, SplitSchedulingContext splitSchedulingContext) {
    BigQueryTableLayoutHandle bigQueryTableLayoutHandle = (BigQueryTableLayoutHandle) layout;
    BigQueryTableHandle bigQueryTableHandle = bigQueryTableLayoutHandle.getTable();
    TableId tableId = bigQueryTableHandle.getTableId();
    int actualParallelism = parallelism.orElse(nodeManager.getRequiredWorkerNodes().size());
    Optional<String> filter = Optional.empty();
    List<BigQuerySplit> splits = isEmptyProjectionIsRequired(bigQueryTableHandle.getProjectedColumns()) ? createEmptyProjection(tableId, actualParallelism, filter) : readFromBigQuery(tableId, bigQueryTableHandle.getProjectedColumns(), actualParallelism, filter);
    return new FixedSplitSource(splits);
}
Also used : TableId(com.google.cloud.bigquery.TableId) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource)

Example 12 with TableId

use of com.google.cloud.bigquery.TableId in project presto by prestodb.

the class BigQueryClient method addTableMappingIfNeeded.

private void addTableMappingIfNeeded(DatasetId datasetID, Table table) {
    TableId bigQueryTableId = table.getTableId();
    TableId prestoTableId = TableId.of(datasetID.getProject(), datasetID.getDataset(), createTableName());
    tableIds.putIfAbsent(bigQueryTableId, prestoTableId);
}
Also used : TableId(com.google.cloud.bigquery.TableId)

Example 13 with TableId

use of com.google.cloud.bigquery.TableId in project beam by apache.

the class BigQueryClient method insertAll.

/**
 * Inserts multiple rows of the same schema to a BigQuery table.
 */
public void insertAll(Collection<Map<String, ?>> rows, String table) {
    TableId tableId = TableId.of(projectId, dataset, table);
    InsertAllRequest.Builder builder = InsertAllRequest.newBuilder(tableId);
    for (Map<String, ?> row : rows) {
        builder.addRow(row);
    }
    InsertAllResponse response = client.insertAll(builder.build());
    handleBigQueryResponseExceptions(response);
}
Also used : TableId(com.google.cloud.bigquery.TableId) InsertAllRequest(com.google.cloud.bigquery.InsertAllRequest) InsertAllResponse(com.google.cloud.bigquery.InsertAllResponse)

Example 14 with TableId

use of com.google.cloud.bigquery.TableId in project beam by apache.

the class BigQueryIOIT method tearDown.

@AfterClass
public static void tearDown() {
    BigQueryOptions options = BigQueryOptions.newBuilder().build();
    BigQuery client = options.getService();
    TableId tableId = TableId.of(options.getProjectId(), testBigQueryDataset, testBigQueryTable);
    client.delete(tableId);
}
Also used : TableId(com.google.cloud.bigquery.TableId) BigQuery(com.google.cloud.bigquery.BigQuery) BigQueryOptions(com.google.cloud.bigquery.BigQueryOptions) AfterClass(org.junit.AfterClass)

Example 15 with TableId

use of com.google.cloud.bigquery.TableId in project google-cloud-java by GoogleCloudPlatform.

the class ITBigQueryTest method testExtractJob.

@Test
public void testExtractJob() throws InterruptedException, TimeoutException {
    String tableName = "test_export_job_table";
    TableId destinationTable = TableId.of(DATASET, tableName);
    LoadJobConfiguration configuration = LoadJobConfiguration.newBuilder(destinationTable, "gs://" + BUCKET + "/" + LOAD_FILE).setSchema(SIMPLE_SCHEMA).build();
    Job remoteLoadJob = bigquery.create(JobInfo.of(configuration));
    remoteLoadJob = remoteLoadJob.waitFor();
    assertNull(remoteLoadJob.getStatus().getError());
    ExtractJobConfiguration extractConfiguration = ExtractJobConfiguration.newBuilder(destinationTable, "gs://" + BUCKET + "/" + EXTRACT_FILE).setPrintHeader(false).build();
    Job remoteExtractJob = bigquery.create(JobInfo.of(extractConfiguration));
    remoteExtractJob = remoteExtractJob.waitFor();
    assertNull(remoteExtractJob.getStatus().getError());
    assertEquals(CSV_CONTENT, new String(storage.readAllBytes(BUCKET, EXTRACT_FILE), StandardCharsets.UTF_8));
    assertTrue(bigquery.delete(DATASET, tableName));
}
Also used : TableId(com.google.cloud.bigquery.TableId) LoadJobConfiguration(com.google.cloud.bigquery.LoadJobConfiguration) Job(com.google.cloud.bigquery.Job) ExtractJobConfiguration(com.google.cloud.bigquery.ExtractJobConfiguration) Test(org.junit.Test)

Aggregations

TableId (com.google.cloud.bigquery.TableId)34 Table (com.google.cloud.bigquery.Table)13 Test (org.junit.Test)13 Job (com.google.cloud.bigquery.Job)11 StandardTableDefinition (com.google.cloud.bigquery.StandardTableDefinition)9 TableInfo (com.google.cloud.bigquery.TableInfo)8 FieldValue (com.google.cloud.bigquery.FieldValue)7 List (java.util.List)7 BigQuery (com.google.cloud.bigquery.BigQuery)6 Schema (com.google.cloud.bigquery.Schema)6 InsertAllResponse (com.google.cloud.bigquery.InsertAllResponse)5 QueryResponse (com.google.cloud.bigquery.QueryResponse)5 Field (com.google.cloud.bigquery.Field)4 QueryRequest (com.google.cloud.bigquery.QueryRequest)4 FixedSplitSource (com.facebook.presto.spi.FixedSplitSource)3 CopyJobConfiguration (com.google.cloud.bigquery.CopyJobConfiguration)3 InsertAllRequest (com.google.cloud.bigquery.InsertAllRequest)3 ImmutableList (com.google.common.collect.ImmutableList)3 String.format (java.lang.String.format)3 Logger (com.facebook.airlift.log.Logger)2