@Override public Table create(Table table, Map<Option, ?> options) { try { // unset the type, as it is output only table.setType(null); TableReference reference = table.getTableReference(); return bigquery .tables() .insert(reference.getProjectId(), reference.getDatasetId(), table) .setFields(Option.FIELDS.getString(options)) .execute(); } catch (IOException ex) { throw translate(ex); } }
@Override public Table patch(Table table, Map<Option, ?> options) { try { // unset the type, as it is output only table.setType(null); TableReference reference = table.getTableReference(); return bigquery .tables() .patch(reference.getProjectId(), reference.getDatasetId(), reference.getTableId(), table) .setFields(Option.FIELDS.getString(options)) .execute(); } catch (IOException ex) { throw translate(ex); } }
BuilderImpl(Table tablePb) { this.tableId = TableId.fromPb(tablePb.getTableReference()); if (tablePb.getLastModifiedTime() != null) { this.setLastModifiedTime(tablePb.getLastModifiedTime().longValue()); } this.description = tablePb.getDescription(); this.expirationTime = tablePb.getExpirationTime(); this.friendlyName = tablePb.getFriendlyName(); this.creationTime = tablePb.getCreationTime(); this.etag = tablePb.getEtag(); this.generatedId = tablePb.getId(); this.selfLink = tablePb.getSelfLink(); this.numBytes = tablePb.getNumBytes(); this.numRows = tablePb.getNumRows(); this.definition = TableDefinition.fromPb(tablePb); if (tablePb.getEncryptionConfiguration() != null) { this.encryptionConfiguration = new EncryptionConfiguration.Builder(tablePb.getEncryptionConfiguration()).build(); } this.labels = Labels.fromPb(tablePb.getLabels()); }
public String tableSpec() { return String.format( "%s:%s.%s", table.getTableReference().getProjectId(), table.getTableReference().getDatasetId(), table.getTableReference().getTableId()); }
private void tearDown() throws IOException, InterruptedException { if (this.datasetService == null) { return; } try { if (table != null) { datasetService.deleteTable(table.getTableReference()); } } finally { datasetService = null; table = null; } }
@Override public List<String> getExportPaths() throws IOException { List<String> paths = new ArrayList<>(); long numTableRows = tableToExport.getNumRows().longValue(); long numTableBytes = tableToExport.getNumBytes(); int numShards = computeNumShards(numTableBytes); logger.atInfo().log("Computed '%s' shards for sharded BigQuery export.", numShards); for (int i = 0; i < numShards; ++i) { String exportPattern = String.format( "%s/shard-%d/%s", gcsPath, i, fileFormat.getFilePattern()); paths.add(exportPattern); } logger.atInfo().log( "Table '%s' to be exported has %s rows and %s bytes", BigQueryStrings.toString(tableToExport.getTableReference()), numTableRows, numTableBytes); return paths; }
public static TableInfo createViewInfo(com.google.api.services.bigquery.model.Table model) { String type = model.getType(); if (type == null) { model.setType(TableDefinition.Type.VIEW.name()); } TableId tableId = TableId.fromPb(model.getTableReference()); return TableInfo.of(tableId, ViewDefinition.of(new String(model.getView().getQuery().getBytes()))); }
void emptyTable(String projectId, Table table) throws IOException { TableReference r = table.getTableReference(); deleteTable(r.getProjectId(), r.getDatasetId(), r.getTableId()); createTable(projectId, table); }
private TableSchema getSchema(Bigquery bq) { try { return bq.tables() .get( pipelineOptions.getProject(), pipelineOptions.getTargetDataset(), table.getTableReference().getTableId()) .execute() .getSchema(); } catch (IOException e) { throw new RuntimeException(e); } }
private List<TableRow> getTableRows(Bigquery bq) { try { return bq.tabledata() .list( pipelineOptions.getProject(), pipelineOptions.getTargetDataset(), table.getTableReference().getTableId()) .execute() .getRows(); } catch (IOException e) { throw new RuntimeException(e); } }
public static TableInfo createTableInfo(com.google.api.services.bigquery.model.Table model) { String type = model.getType(); if (type == null) { model.setType(TableDefinition.Type.TABLE.name()); } TableId tableId = TableId.fromPb(model.getTableReference()); TableDefinition definition = tableDefinition(model); return TableInfo.newBuilder(tableId, definition).build(); }
BuilderImpl(Table tablePb) { this.tableId = TableId.fromPb(tablePb.getTableReference()); if (tablePb.getLastModifiedTime() != null) { this.lastModifiedTime(tablePb.getLastModifiedTime().longValue()); } this.description = tablePb.getDescription(); this.expirationTime = tablePb.getExpirationTime(); this.friendlyName = tablePb.getFriendlyName(); this.creationTime = tablePb.getCreationTime(); this.etag = tablePb.getEtag(); this.generatedId = tablePb.getId(); this.selfLink = tablePb.getSelfLink(); this.definition = TableDefinition.fromPb(tablePb); }
BuilderImpl(Table tablePb) { this.tableId = TableId.fromPb(tablePb.getTableReference()); if (tablePb.getLastModifiedTime() != null) { this.lastModifiedTime(tablePb.getLastModifiedTime().longValue()); } this.description = tablePb.getDescription(); this.expirationTime = tablePb.getExpirationTime(); this.friendlyName = tablePb.getFriendlyName(); this.creationTime = tablePb.getCreationTime(); this.etag = tablePb.getEtag(); this.generatedId = tablePb.getId(); this.selfLink = tablePb.getSelfLink(); this.definition = TableDefinition.fromPb(tablePb); }
@Override public Table create(Table table, Map<Option, ?> options) { try { // unset the type, as it is output only table.setType(null); return bigquery.tables() .insert(this.options.projectId(), table.getTableReference().getDatasetId(), table) .setFields(FIELDS.getString(options)) .execute(); } catch (IOException ex) { throw translate(ex); } }
@Override public Table create(Table table, Map<Option, ?> options) { try { // unset the type, as it is output only table.setType(null); return bigquery.tables() .insert(this.options.projectId(), table.getTableReference().getDatasetId(), table) .setFields(FIELDS.getString(options)) .execute(); } catch (IOException ex) { throw translate(ex); } }
@Override public Table create(Table table, Map<Option, ?> options) { try { // unset the type, as it is output only table.setType(null); TableReference reference = table.getTableReference(); return bigquery .tables() .insert(reference.getProjectId(), reference.getDatasetId(), table) .setFields(Option.FIELDS.getString(options)) .execute(); } catch (IOException ex) { throw translate(ex); } }
@Override public Table patch(Table table, Map<Option, ?> options) { try { // unset the type, as it is output only table.setType(null); TableReference reference = table.getTableReference(); return bigquery .tables() .patch(reference.getProjectId(), reference.getDatasetId(), reference.getTableId(), table) .setFields(Option.FIELDS.getString(options)) .execute(); } catch (IOException ex) { throw translate(ex); } }
@Override public Table patch(Table table, Map<Option, ?> options) { try { // unset the type, as it is output only table.setType(null); TableReference reference = table.getTableReference(); return bigquery.tables() .patch(this.options.projectId(), reference.getDatasetId(), reference.getTableId(), table) .setFields(FIELDS.getString(options)) .execute(); } catch (IOException ex) { throw translate(ex); } }
@Override public Table patch(Table table, Map<Option, ?> options) { try { // unset the type, as it is output only table.setType(null); TableReference reference = table.getTableReference(); return bigquery.tables() .patch(this.options.projectId(), reference.getDatasetId(), reference.getTableId(), table) .setFields(FIELDS.getString(options)) .execute(); } catch (IOException ex) { throw translate(ex); } }
@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)); } }