/** * 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)); }
/** * 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); }
/** * 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; }
/** * 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)); }
/** * 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)); }
/** * 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)); }
/** * 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); }
/** * 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)); }
/** * 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()); }
/** * 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); }