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, Table newTable) voiddeleteDataset(String projectId, String datasetId) voiddeleteTable(String projectId, String datasetId, String tableName) static BigqueryClientstatic BigquerygetNewBigqueryClient(String applicationName) getTableResource(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.queryUnflattened(String query, String projectId, boolean typed, boolean useStandardSql) Performs a query without flattening results.queryUnflattened(String query, String projectId, boolean typed, boolean useStandardSql, @Nullable String location) Performs a query without flattening results.queryWithRetries(String query, String projectId) queryWithRetries(String query, String projectId, boolean typed) queryWithRetriesUsingStandardSql(String query, String projectId) voidupdateTableSchema(String projectId, String datasetId, String tableId, TableSchema newSchema)
-
Constructor Details
-
BigqueryClient
-
-
Method Details
-
getNewBigqueryClient
-
getClient
-
queryWithRetries
@Nonnull public QueryResponse queryWithRetries(String query, String projectId) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
queryWithRetriesUsingStandardSql
@Nonnull public QueryResponse queryWithRetriesUsingStandardSql(String query, String projectId) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
queryUnflattened
@Nonnull public List<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<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 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, 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 Table getTableResource(String projectId, String datasetId, String tableId) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
updateTableSchema
public void updateTableSchema(String projectId, String datasetId, String tableId, TableSchema newSchema) throws IOException - Throws:
IOException
-