Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit bd60bb7

Browse files
committed
feat(bigquery): Support Fine Grained ACLs for Datasets
1 parent e289390 commit bd60bb7

4 files changed

Lines changed: 71 additions & 13 deletions

File tree

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,40 @@ public String getSelector() {
7777
}
7878
}
7979

80+
enum DatasetView {
81+
FULL("full"),
82+
METADATA("metadata"),
83+
ACL("acl");
84+
85+
private final String view;
86+
87+
DatasetView(String view) {
88+
this.view = view;
89+
}
90+
91+
@Override
92+
public String toString() {
93+
return view.toUpperCase();
94+
}
95+
}
96+
97+
enum DatasetUpdateMode {
98+
UPDATE_FULL("update_full"),
99+
UPDATE_METADATA("update_metadata"),
100+
UPDATE_ACL("update_acl");
101+
102+
private final String updateMode;
103+
104+
DatasetUpdateMode(String updateMode) {
105+
this.updateMode = updateMode;
106+
}
107+
108+
@Override
109+
public String toString() {
110+
return updateMode.toUpperCase();
111+
}
112+
}
113+
80114
/**
81115
* Fields of a BigQuery Table resource.
82116
*
@@ -307,6 +341,22 @@ public static DatasetOption fields(DatasetField... fields) {
307341
public static DatasetOption accessPolicyVersion(Integer accessPolicyVersion) {
308342
return new DatasetOption(BigQueryRpc.Option.ACCESS_POLICY_VERSION, accessPolicyVersion);
309343
}
344+
345+
/**
346+
* Returns an option to specify the view that determines which dataset information is returned.
347+
* By default, metadata and ACL information are returned.
348+
*/
349+
public static DatasetOption datasetView(DatasetView datasetView) {
350+
return new DatasetOption(BigQueryRpc.Option.DATASET_VIEW, datasetView);
351+
}
352+
353+
/**
354+
* Returns an option to specify the fields of dataset that update/patch operation is targeting.
355+
* By default, both metadata and ACL fields are updated.
356+
*/
357+
public static DatasetOption updateMode(DatasetUpdateMode updateMode) {
358+
return new DatasetOption(BigQueryRpc.Option.DATASET_UPDATE_MODE, updateMode);
359+
}
310360
}
311361

312362
/** Class for specifying dataset delete options. */

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/BigQueryRpc.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ enum Option {
6060
TABLE_METADATA_VIEW("view"),
6161
RETRY_OPTIONS("retryOptions"),
6262
BIGQUERY_RETRY_CONFIG("bigQueryRetryConfig"),
63-
ACCESS_POLICY_VERSION("accessPolicyVersion");
63+
ACCESS_POLICY_VERSION("accessPolicyVersion"),
64+
DATASET_VIEW("datasetView"),
65+
DATASET_UPDATE_MODE("datasetUpdateMode");
6466

6567
private final String value;
6668

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,11 @@ public Dataset getDatasetSkipExceptionTranslation(
149149
.get(projectId, datasetId)
150150
.setFields(Option.FIELDS.getString(options))
151151
.setPrettyPrint(false);
152-
for (Map.Entry<Option, ?> entry : options.entrySet()) {
153-
if (entry.getKey() == Option.ACCESS_POLICY_VERSION && entry.getValue() != null) {
154-
bqGetRequest.setAccessPolicyVersion((Integer) entry.getValue());
155-
}
152+
if (options.containsKey(Option.ACCESS_POLICY_VERSION)) {
153+
bqGetRequest.setAccessPolicyVersion((Integer) options.get(Option.ACCESS_POLICY_VERSION));
154+
}
155+
if (options.containsKey(Option.DATASET_VIEW)) {
156+
bqGetRequest.setDatasetView(options.get(Option.DATASET_VIEW).toString());
156157
}
157158
return bqGetRequest.execute();
158159
}
@@ -350,10 +351,11 @@ public Dataset patchSkipExceptionTranslation(Dataset dataset, Map<Option, ?> opt
350351
.patch(reference.getProjectId(), reference.getDatasetId(), dataset)
351352
.setPrettyPrint(false)
352353
.setFields(Option.FIELDS.getString(options));
353-
for (Map.Entry<Option, ?> entry : options.entrySet()) {
354-
if (entry.getKey() == Option.ACCESS_POLICY_VERSION && entry.getValue() != null) {
355-
bqPatchRequest.setAccessPolicyVersion((Integer) entry.getValue());
356-
}
354+
if (options.containsKey(Option.ACCESS_POLICY_VERSION)) {
355+
bqPatchRequest.setAccessPolicyVersion((Integer) options.get(Option.ACCESS_POLICY_VERSION));
356+
}
357+
if (options.containsKey(Option.DATASET_UPDATE_MODE)) {
358+
bqPatchRequest.setUpdateMode(options.get(Option.DATASET_UPDATE_MODE).toString());
357359
}
358360
return bqPatchRequest.execute();
359361
}

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import com.google.cloud.bigquery.BigQuery.DatasetField;
4949
import com.google.cloud.bigquery.BigQuery.DatasetListOption;
5050
import com.google.cloud.bigquery.BigQuery.DatasetOption;
51+
import com.google.cloud.bigquery.BigQuery.DatasetUpdateMode;
52+
import com.google.cloud.bigquery.BigQuery.DatasetView;
5153
import com.google.cloud.bigquery.BigQuery.JobField;
5254
import com.google.cloud.bigquery.BigQuery.JobListOption;
5355
import com.google.cloud.bigquery.BigQuery.JobOption;
@@ -1235,18 +1237,19 @@ public void testGetDatasetWithAccessPolicyVersion() throws IOException {
12351237
"requests after the year 2024",
12361238
"location");
12371239
Acl acl = Acl.of(user, role, condition);
1238-
DatasetOption datasetOption = DatasetOption.accessPolicyVersion(3);
1240+
DatasetOption accessPolicyOption = DatasetOption.accessPolicyVersion(3);
1241+
DatasetOption viewOption = DatasetOption.datasetView(DatasetView.FULL);
12391242

12401243
Dataset dataset =
12411244
bigquery.create(
12421245
DatasetInfo.newBuilder(accessPolicyDataset)
12431246
.setDescription("Some Description")
12441247
.setAcl(ImmutableList.of(acl))
12451248
.build(),
1246-
datasetOption);
1249+
accessPolicyOption);
12471250
assertThat(dataset).isNotNull();
12481251

1249-
Dataset remoteDataset = bigquery.getDataset(accessPolicyDataset, datasetOption);
1252+
Dataset remoteDataset = bigquery.getDataset(accessPolicyDataset, accessPolicyOption, viewOption);
12501253
assertNotNull(remoteDataset);
12511254
assertEquals(dataset.getDescription(), remoteDataset.getDescription());
12521255
assertNotNull(remoteDataset.getCreationTime());
@@ -1355,14 +1358,15 @@ public void testUpdateDatabaseWithAccessPolicyVersion() throws IOException {
13551358
acls.add(acl);
13561359

13571360
DatasetOption datasetOption = DatasetOption.accessPolicyVersion(3);
1361+
DatasetOption updateModeOption = DatasetOption.updateMode(DatasetUpdateMode.UPDATE_FULL);
13581362
Dataset updatedDataset =
13591363
bigquery.update(
13601364
dataset.toBuilder()
13611365
.setDescription("Updated Description")
13621366
.setLabels(null)
13631367
.setAcl(acls)
13641368
.build(),
1365-
datasetOption);
1369+
datasetOption, updateModeOption);
13661370
assertNotNull(updatedDataset);
13671371
assertEquals(updatedDataset.getDescription(), "Updated Description");
13681372
assertThat(updatedDataset.getLabels().isEmpty());

0 commit comments

Comments
 (0)