Class BigqueryClient
java.lang.Object
org.apache.beam.sdk.io.gcp.testing.BigqueryClient
A wrapper class to call Bigquery API calls.
Example:
Get a new Bigquery client:
[
BigqueryClient client = BigqueryClient.getNewBigqueryClient(applicationName);
]
Execute a query with retries:
[
QueryResponse response = client.queryWithRetries(queryString, projectId);
]
Create a new dataset in one project:
[
client.createNewDataset(projectId, datasetId);
]
Delete a dataset in one project, included its all tables:
[
client.deleteDataset(projectId, datasetId);
]
Create a new table
[
client.createNewTable(projectId, datasetId, newTable)
]
Insert data into table
[
client.insertDataToTable(projectId, datasetId, tableName, rows)
]-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateNewDataset(String projectId, String datasetId) Creates a new dataset.voidcreateNewDataset(String projectId, String datasetId, @Nullable Long defaultTableExpirationMs) Creates a new dataset with defaultTableExpirationMs.voidcreateNewDataset(String projectId, String datasetId, @Nullable Long defaultTableExpirationMs, @Nullable String location) Creates a new dataset with defaultTableExpirationMs and in a specified location (GCP region).voidcreateNewTable(String projectId, String datasetId, com.google.api.services.bigquery.model.Table newTable) voiddeleteDataset(String projectId, String datasetId) voiddeleteTable(String projectId, String datasetId, String tableName) static BigqueryClientstatic com.google.api.services.bigquery.BigquerygetNewBigqueryClient(String applicationName) com.google.api.services.bigquery.model.TablegetTableResource(String projectId, String datasetId, String tableId) voidinsertDataToTable(String projectId, String datasetId, String tableName, List<Map<String, Object>> rows) Inserts rows to a table using a BigQuery streaming write.List<com.google.api.services.bigquery.model.TableRow> queryUnflattened(String query, String projectId, boolean typed, boolean useStandardSql) Performs a query without flattening results.List<com.google.api.services.bigquery.model.TableRow> queryUnflattened(String query, String projectId, boolean typed, boolean useStandardSql, @Nullable String location) Performs a query without flattening results.com.google.api.services.bigquery.model.QueryResponsequeryWithRetries(String query, String projectId) com.google.api.services.bigquery.model.QueryResponsequeryWithRetries(String query, String projectId, boolean typed) com.google.api.services.bigquery.model.QueryResponsequeryWithRetriesUsingStandardSql(String query, String projectId) voidupdateTableSchema(String projectId, String datasetId, String tableId, com.google.api.services.bigquery.model.TableSchema newSchema)
-
Constructor Details
-
BigqueryClient
-
-
Method Details
-
getNewBigqueryClient
public static com.google.api.services.bigquery.Bigquery getNewBigqueryClient(String applicationName) -
getClient
-
queryWithRetries
@Nonnull public com.google.api.services.bigquery.model.QueryResponse queryWithRetries(String query, String projectId) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
queryWithRetriesUsingStandardSql
@Nonnull public com.google.api.services.bigquery.model.QueryResponse queryWithRetriesUsingStandardSql(String query, String projectId) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
queryUnflattened
@Nonnull public List<com.google.api.services.bigquery.model.TableRow> queryUnflattened(String query, String projectId, boolean typed, boolean useStandardSql) throws IOException, InterruptedException Performs a query without flattening results.- Throws:
IOExceptionInterruptedException
-
queryUnflattened
@Nonnull public List<com.google.api.services.bigquery.model.TableRow> queryUnflattened(String query, String projectId, boolean typed, boolean useStandardSql, @Nullable String location) throws IOException, InterruptedException Performs a query without flattening results. May choose a location (GCP region) to perform this operation in.- Throws:
IOExceptionInterruptedException
-
queryWithRetries
@Nonnull public com.google.api.services.bigquery.model.QueryResponse queryWithRetries(String query, String projectId, boolean typed) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
createNewDataset
public void createNewDataset(String projectId, String datasetId) throws IOException, InterruptedException Creates a new dataset.- Throws:
IOExceptionInterruptedException
-
createNewDataset
public void createNewDataset(String projectId, String datasetId, @Nullable Long defaultTableExpirationMs) throws IOException, InterruptedException Creates a new dataset with defaultTableExpirationMs.- Throws:
IOExceptionInterruptedException
-
createNewDataset
public void createNewDataset(String projectId, String datasetId, @Nullable Long defaultTableExpirationMs, @Nullable String location) throws IOException, InterruptedException Creates a new dataset with defaultTableExpirationMs and in a specified location (GCP region).- Throws:
IOExceptionInterruptedException
-
deleteTable
-
deleteDataset
-
createNewTable
public void createNewTable(String projectId, String datasetId, com.google.api.services.bigquery.model.Table newTable) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
insertDataToTable
public void insertDataToTable(String projectId, String datasetId, String tableName, List<Map<String, Object>> rows) throws IOException, InterruptedExceptionInserts rows to a table using a BigQuery streaming write.- Throws:
IOExceptionInterruptedException
-
getTableResource
public com.google.api.services.bigquery.model.Table getTableResource(String projectId, String datasetId, String tableId) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
updateTableSchema
public void updateTableSchema(String projectId, String datasetId, String tableId, com.google.api.services.bigquery.model.TableSchema newSchema) throws IOException - Throws:
IOException
-