Esempio n. 1
0
 /**
  * Updates the table's information. Dataset's and table's user-defined ids cannot be changed. A
  * new {@code Table} object is returned.
  *
  * @param tableInfo new table's information. Dataset's and table's user-defined ids must match the
  *     ones of the current table
  * @param options dataset options
  * @return a {@code Table} object with updated information
  * @throws BigQueryException upon failure
  */
 public Table update(BaseTableInfo tableInfo, BigQuery.TableOption... options) {
   checkArgument(
       Objects.equals(tableInfo.tableId().dataset(), info.tableId().dataset()),
       "Dataset's user-defined ids must match");
   checkArgument(
       Objects.equals(tableInfo.tableId().table(), info.tableId().table()),
       "Table's user-defined ids must match");
   return new Table(bigquery, bigquery.update(tableInfo, options));
 }
Esempio n. 2
0
 /**
  * Insert rows into the table.
  *
  * @param rows rows to be inserted
  * @param skipInvalidRows whether to insert all valid rows, even if invalid rows exist. If not set
  *     the entire insert operation will fail if rows to be inserted contain an invalid row
  * @param ignoreUnknownValues whether to accept rows that contain values that do not match the
  *     schema. The unknown values are ignored. If not set, rows with unknown values are considered
  *     to be invalid
  * @throws BigQueryException upon failure
  */
 InsertAllResponse insert(
     Iterable<InsertAllRequest.RowToInsert> rows,
     boolean skipInvalidRows,
     boolean ignoreUnknownValues)
     throws BigQueryException {
   InsertAllRequest request =
       InsertAllRequest.builder(info.tableId(), rows)
           .skipInvalidRows(skipInvalidRows)
           .ignoreUnknownValues(ignoreUnknownValues)
           .build();
   return bigquery.insertAll(request);
 }
Esempio n. 3
0
 /**
  * Checks if this table exists.
  *
  * @return {@code true} if this table exists, {@code false} otherwise
  * @throws BigQueryException upon failure
  */
 public boolean exists() {
   return bigquery.getTable(info.tableId(), BigQuery.TableOption.fields()) != null;
 }
Esempio n. 4
0
 /**
  * Starts a BigQuery Job to load data into the current table from the provided source URIs.
  * Returns the started {@link Job} object.
  *
  * @param format the format of the exported data
  * @param sourceUris the fully-qualified Google Cloud Storage URIs (e.g. gs://bucket/path) from
  *     which to load the data
  * @param options job options
  * @throws BigQueryException upon failure
  */
 Job load(FormatOptions format, List<String> sourceUris, BigQuery.JobOption... options)
     throws BigQueryException {
   LoadJobConfiguration loadConfig = LoadJobConfiguration.of(info.tableId(), sourceUris, format);
   return new Job(bigquery, bigquery.create(JobInfo.of(loadConfig), options));
 }
Esempio n. 5
0
 /**
  * Starts a BigQuery Job to extract the current table to the provided destination URIs. Returns
  * the started {@link Job} object.
  *
  * @param format the format of the exported data
  * @param destinationUris the fully-qualified Google Cloud Storage URIs (e.g. gs://bucket/path)
  *     where the extracted table should be written
  * @param options job options
  * @throws BigQueryException upon failure
  */
 Job extract(String format, List<String> destinationUris, BigQuery.JobOption... options)
     throws BigQueryException {
   ExtractJobConfiguration extractConfiguration =
       ExtractJobConfiguration.of(info.tableId(), destinationUris, format);
   return new Job(bigquery, bigquery.create(JobInfo.of(extractConfiguration), options));
 }
Esempio n. 6
0
 /**
  * Starts a BigQuery Job to copy the current table to the provided destination table. Returns the
  * started {@link Job} object.
  *
  * @param destinationTable the destination table of the copy job
  * @param options job options
  * @throws BigQueryException upon failure
  */
 Job copy(TableId destinationTable, BigQuery.JobOption... options) throws BigQueryException {
   CopyJobConfiguration configuration = CopyJobConfiguration.of(destinationTable, info.tableId());
   return new Job(bigquery, bigquery.create(JobInfo.of(configuration), options));
 }
Esempio n. 7
0
 /**
  * Returns the paginated list rows in this table.
  *
  * @param options table data list options
  * @throws BigQueryException upon failure
  */
 Page<List<FieldValue>> list(BigQuery.TableDataListOption... options) throws BigQueryException {
   return bigquery.listTableData(info.tableId(), options);
 }
Esempio n. 8
0
 /**
  * Insert rows into the table.
  *
  * @param rows rows to be inserted
  * @throws BigQueryException upon failure
  */
 InsertAllResponse insert(Iterable<InsertAllRequest.RowToInsert> rows) throws BigQueryException {
   return bigquery.insertAll(InsertAllRequest.of(info.tableId(), rows));
 }
Esempio n. 9
0
 /**
  * Deletes this table.
  *
  * @return {@code true} if table was deleted, {@code false} if it was not found
  * @throws BigQueryException upon failure
  */
 public boolean delete() {
   return bigquery.delete(info.tableId());
 }
Esempio n. 10
0
 /**
  * Fetches current table's latest information. Returns {@code null} if the table does not exist.
  *
  * @param options table options
  * @return a {@code Table} object with latest information or {@code null} if not found
  * @throws BigQueryException upon failure
  */
 public Table reload(BigQuery.TableOption... options) {
   return Table.get(bigquery, info.tableId(), options);
 }