We have a requirement where we need to give access to a particular user group in a bigquery dataset that contains views created by java code. I found that datasets.patch method can help me do it but not able to find documentation of what needs to be passed in the http request.
1 Answers
You can find the complete documentation on how to update BigQuery dataset access controls in the documentation page linked. Given that you are already creating the views in your dataset programatically, I would advise that you use the BigQuery client library, which may be more convenient than performing the API call to the datasets.patch
method. In any case, if you are still interested in calling the API directly, you should provide the relevant portions of a dataset resource in the body of the request.
The first link I shared provides a good example of updating dataset access using the Java client libraries, but in short, this is what you should do:
public List<Acl> updateDatasetAccess(DatasetInfo dataset) {
// Make a copy of the ACLs in order to modify them (adding the required group)
List<Acl> previousACLs = dataset.getAcl();
ArrayList<Acl> ACLs = new ArrayList<>(previousACLs);
ACLs.add(Acl.of(new Acl.User("your_group@gmail.com"), Acl.Role.READER));
DatasetInfo.Builder builder = dataset.toBuilder();
builder.setAcl(ACLs);
bigquery.update(builder.build());
}
EDIT:
The way to define the dataset
object is the following one:
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
Dataset dataset = bigquery.getDataset(DatasetId.of("YOUR_DATASET_NAME"));
Take into account that if you do not specify credentials when constructing the client object bigquery
, the client library will look for credentials in the GOOGLE_APPLICATION_CREDENTIALS
environment variable.

- 7,864
- 2
- 33
- 50
-
Hi, Thanks for ypur response. I was trying the above mentioned steps beofre but the issue is the datasetinfo object always returns me null thats why i am not able to proceed with this. BigQuery bigQuery = BigQueryOptions.getDefaultInstance().getService(); DatasetId datasetId = DatasetId.of("fccr"); DatasetInfo datasetInfo = Dataset.of(datasetId); – Siddharth Chaurasia Jun 12 '18 at 11:36
-
You might be instantianting your `dataset` object incorrectly. Please have a look at my edit and make sure that you are using the correct credentials and also specifying a valid dataset name in `DatasetId.of("YOUR_DATASET_NAME")`. – dsesto Jun 12 '18 at 13:58
-
I am glad I could help! If the answer was useful for you, please consider [accepting and/or upvoting](https://stackoverflow.com/help/someone-answers) my answer so that the community sees it solved your issue. Thanks! – dsesto Jun 12 '18 at 15:58
-
Hi @dsesto i have another query if you can help there https://stackoverflow.com/questions/50820987/bigquery-iam-access-from-java really sorry for troubling. – Siddharth Chaurasia Jun 12 '18 at 17:20