Class BigqueryClient
- java.lang.Object
-
- org.apache.beam.sdk.io.gcp.testing.BigqueryClient
-
@Internal public class BigqueryClient extends java.lang.ObjectA 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 Constructor Description BigqueryClient(java.lang.String applicationName)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcreateNewDataset(java.lang.String projectId, java.lang.String datasetId)Creates a new dataset.voidcreateNewDataset(java.lang.String projectId, java.lang.String datasetId, @Nullable java.lang.Long defaultTableExpirationMs)Creates a new dataset with defaultTableExpirationMs.voidcreateNewDataset(java.lang.String projectId, java.lang.String datasetId, @Nullable java.lang.Long defaultTableExpirationMs, @Nullable java.lang.String location)Creates a new dataset with defaultTableExpirationMs and in a specified location (GCP region).voidcreateNewTable(java.lang.String projectId, java.lang.String datasetId, com.google.api.services.bigquery.model.Table newTable)voiddeleteDataset(java.lang.String projectId, java.lang.String datasetId)voiddeleteTable(java.lang.String projectId, java.lang.String datasetId, java.lang.String tableName)static BigqueryClientgetClient(java.lang.String applicationName)static com.google.api.services.bigquery.BigquerygetNewBigqueryClient(java.lang.String applicationName)com.google.api.services.bigquery.model.TablegetTableResource(java.lang.String projectId, java.lang.String datasetId, java.lang.String tableId)voidinsertDataToTable(java.lang.String projectId, java.lang.String datasetId, java.lang.String tableName, java.util.List<java.util.Map<java.lang.String,java.lang.Object>> rows)Inserts rows to a table using a BigQuery streaming write.java.util.List<com.google.api.services.bigquery.model.TableRow>queryUnflattened(java.lang.String query, java.lang.String projectId, boolean typed, boolean useStandardSql)Performs a query without flattening results.java.util.List<com.google.api.services.bigquery.model.TableRow>queryUnflattened(java.lang.String query, java.lang.String projectId, boolean typed, boolean useStandardSql, @Nullable java.lang.String location)Performs a query without flattening results.com.google.api.services.bigquery.model.QueryResponsequeryWithRetries(java.lang.String query, java.lang.String projectId)com.google.api.services.bigquery.model.QueryResponsequeryWithRetries(java.lang.String query, java.lang.String projectId, boolean typed)com.google.api.services.bigquery.model.QueryResponsequeryWithRetriesUsingStandardSql(java.lang.String query, java.lang.String projectId)voidupdateTableSchema(java.lang.String projectId, java.lang.String datasetId, java.lang.String tableId, com.google.api.services.bigquery.model.TableSchema newSchema)
-
-
-
Method Detail
-
getNewBigqueryClient
public static com.google.api.services.bigquery.Bigquery getNewBigqueryClient(java.lang.String applicationName)
-
getClient
public static BigqueryClient getClient(java.lang.String applicationName)
-
queryWithRetries
@Nonnull public com.google.api.services.bigquery.model.QueryResponse queryWithRetries(java.lang.String query, java.lang.String projectId) throws java.io.IOException, java.lang.InterruptedException- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
queryWithRetriesUsingStandardSql
@Nonnull public com.google.api.services.bigquery.model.QueryResponse queryWithRetriesUsingStandardSql(java.lang.String query, java.lang.String projectId) throws java.io.IOException, java.lang.InterruptedException- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
queryUnflattened
@Nonnull public java.util.List<com.google.api.services.bigquery.model.TableRow> queryUnflattened(java.lang.String query, java.lang.String projectId, boolean typed, boolean useStandardSql) throws java.io.IOException, java.lang.InterruptedExceptionPerforms a query without flattening results.- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
queryUnflattened
@Nonnull public java.util.List<com.google.api.services.bigquery.model.TableRow> queryUnflattened(java.lang.String query, java.lang.String projectId, boolean typed, boolean useStandardSql, @Nullable java.lang.String location) throws java.io.IOException, java.lang.InterruptedExceptionPerforms a query without flattening results. May choose a location (GCP region) to perform this operation in.- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
queryWithRetries
@Nonnull public com.google.api.services.bigquery.model.QueryResponse queryWithRetries(java.lang.String query, java.lang.String projectId, boolean typed) throws java.io.IOException, java.lang.InterruptedException- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
createNewDataset
public void createNewDataset(java.lang.String projectId, java.lang.String datasetId) throws java.io.IOException, java.lang.InterruptedExceptionCreates a new dataset.- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
createNewDataset
public void createNewDataset(java.lang.String projectId, java.lang.String datasetId, @Nullable java.lang.Long defaultTableExpirationMs) throws java.io.IOException, java.lang.InterruptedExceptionCreates a new dataset with defaultTableExpirationMs.- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
createNewDataset
public void createNewDataset(java.lang.String projectId, java.lang.String datasetId, @Nullable java.lang.Long defaultTableExpirationMs, @Nullable java.lang.String location) throws java.io.IOException, java.lang.InterruptedExceptionCreates a new dataset with defaultTableExpirationMs and in a specified location (GCP region).- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
deleteTable
public void deleteTable(java.lang.String projectId, java.lang.String datasetId, java.lang.String tableName)
-
deleteDataset
public void deleteDataset(java.lang.String projectId, java.lang.String datasetId)
-
createNewTable
public void createNewTable(java.lang.String projectId, java.lang.String datasetId, com.google.api.services.bigquery.model.Table newTable) throws java.io.IOException, java.lang.InterruptedException- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
insertDataToTable
public void insertDataToTable(java.lang.String projectId, java.lang.String datasetId, java.lang.String tableName, java.util.List<java.util.Map<java.lang.String,java.lang.Object>> rows) throws java.io.IOException, java.lang.InterruptedExceptionInserts rows to a table using a BigQuery streaming write.- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
getTableResource
public com.google.api.services.bigquery.model.Table getTableResource(java.lang.String projectId, java.lang.String datasetId, java.lang.String tableId) throws java.io.IOException, java.lang.InterruptedException- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
updateTableSchema
public void updateTableSchema(java.lang.String projectId, java.lang.String datasetId, java.lang.String tableId, com.google.api.services.bigquery.model.TableSchema newSchema) throws java.io.IOException- Throws:
java.io.IOException
-
-