Java Code Examples for com.google.api.services.bigquery.model.Table#getTableReference()

The following examples show how to use com.google.api.services.bigquery.model.Table#getTableReference() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BigqueryConnection.java    From nomulus with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the specified Bigquery table to reflect the metadata from the input.
 *
 * <p>Returns the input DestinationTable. If the specified table does not already exist, it will
 * be inserted into the dataset.
 *
 * <p>Clients can call this function directly to update a table on demand, or can pass it to
 * Futures.transform() to update a table produced as the asynchronous result of a load or query
 * job (e.g. to add a description to it).
 */
private DestinationTable updateTable(final DestinationTable destinationTable) {
  Table table = destinationTable.getTable();
  TableReference ref = table.getTableReference();
  try {
    if (checkTableExists(ref.getDatasetId(), ref.getTableId())) {
      // Make sure to use patch() rather than update(). The former changes only those properties
      // which are specified, while the latter would change everything, blanking out unspecified
      // properties.
      bigquery
          .tables()
          .patch(ref.getProjectId(), ref.getDatasetId(), ref.getTableId(), table)
          .execute();
    } else {
      bigquery.tables().insert(ref.getProjectId(), ref.getDatasetId(), table).execute();
    }
    return destinationTable;
  } catch (IOException e) {
    throw BigqueryJobFailureException.create(e);
  }
}
 
Example 2
Source File: UpdateSnapshotViewAction.java    From nomulus with Apache License 2.0 6 votes vote down vote up
private static void updateTable(Bigquery bigquery, Table table) throws IOException {
  TableReference ref = table.getTableReference();
  try {
    bigquery
        .tables()
        .update(ref.getProjectId(), ref.getDatasetId(), ref.getTableId(), table)
        .execute();
  } catch (GoogleJsonResponseException e) {
    if (e.getDetails() != null && e.getDetails().getCode() == 404) {
      bigquery.tables().insert(ref.getProjectId(), ref.getDatasetId(), table).execute();
    } else {
      logger.atWarning().withCause(e).log(
          "UpdateSnapshotViewAction failed, caught exception %s", e.getDetails());
    }
  }
}
 
Example 3
Source File: FakeDatasetService.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public void createTable(Table table) throws IOException {
  TableReference tableReference = table.getTableReference();
  validateWholeTableReference(tableReference);
  synchronized (tables) {
    Map<String, TableContainer> dataset =
        tables.get(tableReference.getProjectId(), tableReference.getDatasetId());
    if (dataset == null) {
      throwNotFound(
          "Tried to get a dataset %s:%s, but no such table was set",
          tableReference.getProjectId(), tableReference.getDatasetId());
    }
    dataset.computeIfAbsent(tableReference.getTableId(), k -> new TableContainer(table));
  }
}
 
Example 4
Source File: BqClient.java    From digdag with Apache License 2.0 5 votes vote down vote up
void emptyTable(String projectId, Table table)
        throws IOException
{
    TableReference r = table.getTableReference();
    deleteTable(r.getProjectId(), r.getDatasetId(), r.getTableId());
    createTable(projectId, table);
}