public interface BigQuery extends com.google.cloud.Service<BigQueryOptions>
| Modifier and Type | Interface and Description |
|---|---|
static class |
BigQuery.DatasetDeleteOption
Class for specifying dataset delete options.
|
static class |
BigQuery.DatasetField
Fields of a BigQuery Dataset resource.
|
static class |
BigQuery.DatasetListOption
Class for specifying dataset list options.
|
static class |
BigQuery.DatasetOption
Class for specifying dataset get, create and update options.
|
static class |
BigQuery.IAMOption |
static class |
BigQuery.JobField
Fields of a BigQuery Job resource.
|
static class |
BigQuery.JobListOption
Class for specifying job list options.
|
static class |
BigQuery.JobOption
Class for specifying table get and create options.
|
static class |
BigQuery.ModelField
Fields of a BigQuery Model resource.
|
static class |
BigQuery.ModelListOption
Class for specifying table list options.
|
static class |
BigQuery.ModelOption
Class for specifying model get, create and update options.
|
static class |
BigQuery.QueryOption |
static class |
BigQuery.QueryResultsOption
Class for specifying query results options.
|
static class |
BigQuery.RoutineField
Fields of a BigQuery Routine resource.
|
static class |
BigQuery.RoutineListOption
Class for specifying routine list options.
|
static class |
BigQuery.RoutineOption
Class for specifying table get, create and update options.
|
static class |
BigQuery.TableDataListOption
Class for specifying table data list options.
|
static class |
BigQuery.TableField
Fields of a BigQuery Table resource.
|
static class |
BigQuery.TableListOption
Class for specifying table list options.
|
static class |
BigQuery.TableOption
Class for specifying table get, create and update options.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
cancel(JobId jobId)
Sends a job cancel request.
|
boolean |
cancel(String jobId)
Sends a job cancel request.
|
Dataset |
create(DatasetInfo datasetInfo,
BigQuery.DatasetOption... options)
Creates a new dataset.
|
Job |
create(JobInfo jobInfo,
BigQuery.JobOption... options)
Creates a new job.
|
Routine |
create(RoutineInfo routineInfo,
BigQuery.RoutineOption... options)
Creates a new routine.
|
Table |
create(TableInfo tableInfo,
BigQuery.TableOption... options)
Creates a new table.
|
boolean |
delete(DatasetId datasetId,
BigQuery.DatasetDeleteOption... options)
Deletes the requested dataset.
|
boolean |
delete(JobId jobId)
Deletes the requested job.
|
boolean |
delete(ModelId modelId)
Deletes the requested model.
|
boolean |
delete(RoutineId routineId)
Deletes the requested routine.
|
boolean |
delete(String datasetId,
BigQuery.DatasetDeleteOption... options)
Deletes the requested dataset.
|
boolean |
delete(String datasetId,
String tableId)
Deprecated.
Now that BigQuery datasets contain multiple resource types, this invocation is
ambiguous. Please use more strongly typed version of
#delete that leverages an
non-ambiguous resource type identifier such as TableId. |
boolean |
delete(TableId tableId)
Deletes the requested table.
|
Dataset |
getDataset(DatasetId datasetId,
BigQuery.DatasetOption... options)
Returns the requested dataset or
null if not found. |
Dataset |
getDataset(String datasetId,
BigQuery.DatasetOption... options)
Returns the requested dataset or
null if not found. |
com.google.cloud.Policy |
getIamPolicy(TableId tableId,
BigQuery.IAMOption... options)
Gets the IAM policy for a specified table.
|
Job |
getJob(JobId jobId,
BigQuery.JobOption... options)
Returns the requested job or
null if not found. |
Job |
getJob(String jobId,
BigQuery.JobOption... options)
Returns the requested job or
null if not found. |
Model |
getModel(ModelId tableId,
BigQuery.ModelOption... options)
Returns the requested model or
null if not found. |
Model |
getModel(String datasetId,
String modelId,
BigQuery.ModelOption... options)
Returns the requested model or
null if not found. |
QueryResponse |
getQueryResults(JobId jobId,
BigQuery.QueryResultsOption... options)
Returns results of the query associated with the provided job.
|
Routine |
getRoutine(RoutineId routineId,
BigQuery.RoutineOption... options)
Returns the requested routine or
null if not found. |
Routine |
getRoutine(String datasetId,
String routineId,
BigQuery.RoutineOption... options)
Returns the requested routine or
null if not found. |
Table |
getTable(String datasetId,
String tableId,
BigQuery.TableOption... options)
Returns the requested table or
null if not found. |
Table |
getTable(TableId tableId,
BigQuery.TableOption... options)
Returns the requested table or
null if not found. |
InsertAllResponse |
insertAll(InsertAllRequest request)
Sends an insert all request.
|
com.google.api.gax.paging.Page<Dataset> |
listDatasets(BigQuery.DatasetListOption... options)
Lists the project's datasets.
|
com.google.api.gax.paging.Page<Dataset> |
listDatasets(String projectId,
BigQuery.DatasetListOption... options)
Lists the datasets in the provided project.
|
com.google.api.gax.paging.Page<Job> |
listJobs(BigQuery.JobListOption... options)
Lists the jobs.
|
com.google.api.gax.paging.Page<Model> |
listModels(DatasetId datasetId,
BigQuery.ModelListOption... options)
Lists the models in the dataset.
|
com.google.api.gax.paging.Page<Model> |
listModels(String datasetId,
BigQuery.ModelListOption... options)
Lists the models in the dataset.
|
List<String> |
listPartitions(TableId tableId) |
com.google.api.gax.paging.Page<Routine> |
listRoutines(DatasetId datasetId,
BigQuery.RoutineListOption... options)
Lists the routines in the specified dataset.
|
com.google.api.gax.paging.Page<Routine> |
listRoutines(String datasetId,
BigQuery.RoutineListOption... options)
Lists the routines in the specified dataset.
|
TableResult |
listTableData(String datasetId,
String tableId,
BigQuery.TableDataListOption... options)
Lists the table's rows.
|
TableResult |
listTableData(String datasetId,
String tableId,
Schema schema,
BigQuery.TableDataListOption... options)
Lists the table's rows.
|
TableResult |
listTableData(TableId tableId,
BigQuery.TableDataListOption... options)
Lists the table's rows.
|
TableResult |
listTableData(TableId tableId,
Schema schema,
BigQuery.TableDataListOption... options)
Lists the table's rows.
|
com.google.api.gax.paging.Page<Table> |
listTables(DatasetId datasetId,
BigQuery.TableListOption... options)
Lists the tables in the dataset.
|
com.google.api.gax.paging.Page<Table> |
listTables(String datasetId,
BigQuery.TableListOption... options)
Lists the tables in the dataset.
|
TableResult |
query(QueryJobConfiguration configuration,
BigQuery.JobOption... options)
Runs the query associated with the request, using an internally-generated random JobId.
|
TableResult |
query(QueryJobConfiguration configuration,
JobId jobId,
BigQuery.JobOption... options)
Runs the query associated with the request, using the given JobId.
|
com.google.cloud.Policy |
setIamPolicy(TableId tableId,
com.google.cloud.Policy policy,
BigQuery.IAMOption... options)
Sets the IAM policy for a specified table.
|
List<String> |
testIamPermissions(TableId table,
List<String> permissions,
BigQuery.IAMOption... options)
Tests whether the caller holds specific permissions on a BigQuery table.
|
Dataset |
update(DatasetInfo datasetInfo,
BigQuery.DatasetOption... options)
Updates dataset information.
|
Model |
update(ModelInfo modelInfo,
BigQuery.ModelOption... options)
Updates model information.
|
Routine |
update(RoutineInfo routineInfo,
BigQuery.RoutineOption... options)
Updates routine information.
|
Table |
update(TableInfo tableInfo,
BigQuery.TableOption... options)
Updates table information.
|
TableDataWriteChannel |
writer(JobId jobId,
WriteChannelConfiguration writeChannelConfiguration)
Returns a channel to write data to be inserted into a BigQuery table.
|
TableDataWriteChannel |
writer(WriteChannelConfiguration writeChannelConfiguration)
Returns a channel to write data to be inserted into a BigQuery table.
|
Dataset create(DatasetInfo datasetInfo, BigQuery.DatasetOption... options)
Example of creating a dataset.
{
@code
String datasetName = "my_dataset_name";
Dataset dataset = null;
DatasetInfo datasetInfo = DatasetInfo.newBuilder(datasetName).build();
try {
// the dataset was created
dataset = bigquery.create(datasetInfo);
} catch (BigQueryException e) {
// the dataset was not created
}
}
BigQueryException - upon failureTable create(TableInfo tableInfo, BigQuery.TableOption... options)
Example of creating a table.
{
@code
String datasetName = "my_dataset_name";
String tableName = "my_table_name";
String fieldName = "string_field";
TableId tableId = TableId.of(datasetName, tableName);
// Table field definition
Field field = Field.of(fieldName, LegacySQLTypeName.STRING);
// Table schema definition
Schema schema = Schema.of(field);
TableDefinition tableDefinition = StandardTableDefinition.of(schema);
TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build();
Table table = bigquery.create(tableInfo);
}
BigQueryException - upon failureRoutine create(RoutineInfo routineInfo, BigQuery.RoutineOption... options)
BigQueryException - upon failureJob create(JobInfo jobInfo, BigQuery.JobOption... options)
Example of loading a newline-delimited-json file with textual fields from GCS to a table.
{
@code
String datasetName = "my_dataset_name";
String tableName = "my_table_name";
String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.json";
TableId tableId = TableId.of(datasetName, tableName);
// Table field definition
Field[] fields = new Field[] { Field.of("name", LegacySQLTypeName.STRING),
Field.of("post_abbr", LegacySQLTypeName.STRING) };
// Table schema definition
Schema schema = Schema.of(fields);
LoadJobConfiguration configuration = LoadJobConfiguration.builder(tableId, sourceUri)
.setFormatOptions(FormatOptions.json()).setCreateDisposition(CreateDisposition.CREATE_IF_NEEDED)
.setSchema(schema).build();
// Load the table
Job loadJob = bigquery.create(JobInfo.of(configuration));
loadJob = loadJob.waitFor();
// Check the table
System.out.println("State: " + loadJob.getStatus().getState());
return ((StandardTableDefinition) bigquery.getTable(tableId).getDefinition()).getNumRows();
}
Example of creating a query job.
{
@code
String query = "SELECT field FROM my_dataset_name.my_table_name";
Job job = null;
JobConfiguration jobConfiguration = QueryJobConfiguration.of(query);
JobInfo jobInfo = JobInfo.of(jobConfiguration);
try {
job = bigquery.create(jobInfo);
} catch (BigQueryException e) {
// the job was not created
}
}
BigQueryException - upon failureDataset getDataset(String datasetId, BigQuery.DatasetOption... options)
null if not found.
Example of getting a dataset.
{
@code
String datasetName = "my_dataset";
Dataset dataset = bigquery.getDataset(datasetName);
}
BigQueryException - upon failureDataset getDataset(DatasetId datasetId, BigQuery.DatasetOption... options)
null if not found.
Example of getting a dataset.
{
@code
String projectId = "my_project_id";
String datasetName = "my_dataset_name";
DatasetId datasetId = DatasetId.of(projectId, datasetName);
Dataset dataset = bigquery.getDataset(datasetId);
}
BigQueryException - upon failurecom.google.api.gax.paging.Page<Dataset> listDatasets(BigQuery.DatasetListOption... options)
DatasetInfo.getDatasetId(), DatasetInfo.getFriendlyName() and DatasetInfo.getGeneratedId()). To get complete information use either getDataset(String,
DatasetOption...) or getDataset(DatasetId, DatasetOption...).
Example of listing datasets, specifying the page size.
{
@code
// List datasets in the default project
Page datasets = bigquery.listDatasets(DatasetListOption.pageSize(100));
for (Dataset dataset : datasets.iterateAll()) {
// do something with the dataset
}
}
BigQueryException - upon failurecom.google.api.gax.paging.Page<Dataset> listDatasets(String projectId, BigQuery.DatasetListOption... options)
DatasetInfo.getDatasetId(), DatasetInfo.getFriendlyName() and DatasetInfo.getGeneratedId()). To get complete information use either getDataset(String,
DatasetOption...) or getDataset(DatasetId, DatasetOption...).
Example of listing datasets in a project, specifying the page size.
{
@code
String projectId = "my_project_id";
// List datasets in a specified project
Page datasets = bigquery.listDatasets(projectId, DatasetListOption.pageSize(100));
for (Dataset dataset : datasets.iterateAll()) {
// do something with the dataset
}
}
BigQueryException - upon failureboolean delete(String datasetId, BigQuery.DatasetDeleteOption... options)
Example of deleting a dataset from its id, even if non-empty.
{
@code
String datasetName = "my_dataset_name";
boolean deleted = bigquery.delete(datasetName, DatasetDeleteOption.deleteContents());
if (deleted) {
// the dataset was deleted
} else {
// the dataset was not found
}
}
true if dataset was deleted, false if it was not foundBigQueryException - upon failureboolean delete(DatasetId datasetId, BigQuery.DatasetDeleteOption... options)
Example of deleting a dataset, even if non-empty.
{
@code
String projectId = "my_project_id";
String datasetName = "my_dataset_name";
DatasetId datasetId = DatasetId.of(projectId, datasetName);
boolean deleted = bigquery.delete(datasetId, DatasetDeleteOption.deleteContents());
if (deleted) {
// the dataset was deleted
} else {
// the dataset was not found
}
}
true if dataset was deleted, false if it was not foundBigQueryException - upon failure@Deprecated boolean delete(String datasetId, String tableId)
#delete that leverages an
non-ambiguous resource type identifier such as TableId.true if table was deleted, false if it was not foundBigQueryException - upon failureboolean delete(TableId tableId)
Example of deleting a table.
{
@code
String projectId = "my_project_id";
String datasetName = "my_dataset_name";
String tableName = "my_table_name";
TableId tableId = TableId.of(projectId, datasetName, tableName);
boolean deleted = bigquery.delete(tableId);
if (deleted) {
// the table was deleted
} else {
// the table was not found
}
}
true if table was deleted, false if it was not foundBigQueryException - upon failureboolean delete(ModelId modelId)
Example of deleting a model.
{
@code
String projectId = "my_project_id";
String datasetName = "my_dataset_name";
String tableName = "my_model_name";
ModelId modelId = ModelId.of(projectId, datasetName, modelName);
boolean deleted = bigquery.delete(modelId);
if (deleted) {
// the model was deleted
} else {
// the model was not found
}
}
true if model was deleted, false if it was not foundBigQueryException - upon failureboolean delete(RoutineId routineId)
Example of deleting a routine.
String projectId = "my_project_id";
String datasetId = "my_dataset_id";
String routineId = "my_routine_id";
RoutineId routineId = RoutineId.of(projectId, datasetId, routineId);
boolean deleted = bigquery.delete(routineId);
if (deleted) {
// the routine was deleted
} else {
// the routine was not found
}
true if routine was deleted, false if it was not
foundBigQueryException - upon failureboolean delete(JobId jobId)
true if job was deleted, false if it was not foundBigQueryException - upon failureDataset update(DatasetInfo datasetInfo, BigQuery.DatasetOption... options)
Example of updating a dataset by changing its description.
{
@code
// String datasetName = "my_dataset_name";
// String tableName = "my_table_name";
// String newDescription = "new_description";
Table beforeTable = bigquery.getTable(datasetName, tableName);
TableInfo tableInfo = beforeTable.toBuilder().setDescription(newDescription).build();
Table afterTable = bigquery.update(tableInfo);
}
BigQueryException - upon failureTable update(TableInfo tableInfo, BigQuery.TableOption... options)
Example of updating a table by changing its description.
{
@code
String datasetName = "my_dataset_name";
String tableName = "my_table_name";
String newDescription = "new_description";
Table beforeTable = bigquery.getTable(datasetName, tableName);
TableInfo tableInfo = beforeTable.toBuilder().setDescription(newDescription).build();
Table afterTable = bigquery.update(tableInfo);
}
Example of updating a table by changing its expiration.
{
@code
String datasetName = "my_dataset_name";
String tableName = "my_table_name";
Table beforeTable = bigquery.getTable(datasetName, tableName);
// Set table to expire 5 days from now.
long expirationMillis = DateTime.now().plusDays(5).getMillis();
TableInfo tableInfo = beforeTable.toBuilder().setExpirationTime(expirationMillis).build();
Table afterTable = bigquery.update(tableInfo);
}
BigQueryException - upon failureModel update(ModelInfo modelInfo, BigQuery.ModelOption... options)
Example of updating a model by changing its description.
{
@code
String datasetName = "my_dataset_name";
String modelName = "my_model_name";
String newDescription = "new_description";
Model beforeModel = bigquery.getModel(datasetName, modelName);
ModelInfo modelInfo = beforeModel.toBuilder().setDescription(newDescription).build();
Model afterModel = bigquery.update(modelInfo);
}
Example of updating a model by changing its expiration.
{
@code
String datasetName = "my_dataset_name";
String modelName = "my_model_name";
Model beforeModel = bigquery.getModel(datasetName, modelName);
// Set model to expire 5 days from now.
long expirationMillis = DateTime.now().plusDays(5).getMillis();
ModelInfo modelInfo = beforeModel.toBuilder().setExpirationTime(expirationMillis).build();
Model afterModel = bigquery.update(modelInfo);
}
BigQueryException - upon failureRoutine update(RoutineInfo routineInfo, BigQuery.RoutineOption... options)
BigQueryException - upon failureTable getTable(String datasetId, String tableId, BigQuery.TableOption... options)
null if not found.
Example of getting a table.
{
@code
String datasetName = "my_dataset_name";
String tableName = "my_table_name";
Table table = bigquery.getTable(datasetName, tableName);
}
BigQueryException - upon failureTable getTable(TableId tableId, BigQuery.TableOption... options)
null if not found.
Example of getting a table.
{
@code
String projectId = "my_project_id";
String datasetName = "my_dataset_name";
String tableName = "my_table_name";
TableId tableId = TableId.of(projectId, datasetName, tableName);
Table table = bigquery.getTable(tableId);
}
BigQueryException - upon failureModel getModel(String datasetId, String modelId, BigQuery.ModelOption... options)
null if not found.BigQueryException - upon failureModel getModel(ModelId tableId, BigQuery.ModelOption... options)
null if not found.
Example of getting a model.
{
@code
String projectId = "my_project_id";
String datasetName = "my_dataset_name";
String modelName = "my_model_name";
ModelId modelId = ModelId.of(projectId, datasetName, tableName);
Model model = bigquery.getModel(modelId);
}
BigQueryException - upon failureRoutine getRoutine(String datasetId, String routineId, BigQuery.RoutineOption... options)
null if not found.BigQueryException - upon failureRoutine getRoutine(RoutineId routineId, BigQuery.RoutineOption... options)
null if not found.BigQueryException - upon failurecom.google.api.gax.paging.Page<Routine> listRoutines(String datasetId, BigQuery.RoutineListOption... options)
com.google.api.gax.paging.Page<Routine> listRoutines(DatasetId datasetId, BigQuery.RoutineListOption... options)
com.google.api.gax.paging.Page<Table> listTables(String datasetId, BigQuery.TableListOption... options)
TableInfo.getTableId(), TableInfo.getFriendlyName(),
TableInfo.getGeneratedId() and type, which is part of
TableInfo.getDefinition()). To get complete information use either
getTable(TableId, TableOption...) or
getTable(String, String, TableOption...).
Example of listing the tables in a dataset, specifying the page size.
{
@code
String datasetName = "my_dataset_name";
Page