FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(bigquery): Support Fine Grained ACLs for Datasets by whuffman36 · Pull Request #3803 · googleapis/java-bigquery · GitHub

This repository was archived by the owner on Mar 23, 2026. It is now read-only.
/ java-bigquery Public archive
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
      • BigQuery.java
        • BigQueryRpc.java
        • HttpBigQueryRpc.java
      • ITBigQueryTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,42 @@ public String getSelector() {
}
}

enum DatasetView {
DATASET_VIEW_UNSPECIFIED("DATASET_VIEW_UNSPECIFIED"),
FULL("FULL"),
METADATA("METADATA"),
ACL("ACL");

private final String view;

DatasetView(String view) {
this.view = view;
}

@Override
public String toString() {
return view;
}
}

enum DatasetUpdateMode {
UPDATE_MODE_UNSPECIFIED("UPDATE_MODE_UNSPECIFIED"),
UPDATE_FULL("UPDATE_FULL"),
UPDATE_METADATA("UPDATE_METADATA"),
UPDATE_ACL("UPDATE_ACL");

private final String updateMode;

DatasetUpdateMode(String updateMode) {
this.updateMode = updateMode;
}

@Override
public String toString() {
return updateMode;
}
}

/**
* Fields of a BigQuery Table resource.
*
Expand Down Expand Up @@ -307,6 +343,22 @@ public static DatasetOption fields(DatasetField... fields) {
public static DatasetOption accessPolicyVersion(Integer accessPolicyVersion) {
return new DatasetOption(BigQueryRpc.Option.ACCESS_POLICY_VERSION, accessPolicyVersion);
}

/**
* Returns an option to specify the view that determines which dataset information is returned.
* By default, metadata and ACL information are returned.
*/
public static DatasetOption datasetView(DatasetView datasetView) {
return new DatasetOption(BigQueryRpc.Option.DATASET_VIEW, datasetView);
}

/**
* Returns an option to specify the fields of dataset that update/patch operation is targeting.
* By default, both metadata and ACL fields are updated.
*/
public static DatasetOption updateMode(DatasetUpdateMode updateMode) {
return new DatasetOption(BigQueryRpc.Option.DATASET_UPDATE_MODE, updateMode);
}
}

/** Class for specifying dataset delete options. */
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ enum Option {
TABLE_METADATA_VIEW("view"),
RETRY_OPTIONS("retryOptions"),
BIGQUERY_RETRY_CONFIG("bigQueryRetryConfig"),
ACCESS_POLICY_VERSION("accessPolicyVersion");
ACCESS_POLICY_VERSION("accessPolicyVersion"),
DATASET_VIEW("datasetView"),
DATASET_UPDATE_MODE("datasetUpdateMode");

private final String value;

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ public Dataset getDatasetSkipExceptionTranslation(
.get(projectId, datasetId)
.setFields(Option.FIELDS.getString(options))
.setPrettyPrint(false);
for (Map.Entry<Option, ?> entry : options.entrySet()) {
if (entry.getKey() == Option.ACCESS_POLICY_VERSION && entry.getValue() != null) {
bqGetRequest.setAccessPolicyVersion((Integer) entry.getValue());
}
if (options.containsKey(Option.ACCESS_POLICY_VERSION)) {
bqGetRequest.setAccessPolicyVersion((Integer) options.get(Option.ACCESS_POLICY_VERSION));
}
if (options.containsKey(Option.DATASET_VIEW)) {
bqGetRequest.setDatasetView(options.get(Option.DATASET_VIEW).toString());
}
return bqGetRequest.execute();
}
Expand Down Expand Up @@ -350,10 +351,11 @@ public Dataset patchSkipExceptionTranslation(Dataset dataset, Map<Option, ?> opt
.patch(reference.getProjectId(), reference.getDatasetId(), dataset)
.setPrettyPrint(false)
.setFields(Option.FIELDS.getString(options));
for (Map.Entry<Option, ?> entry : options.entrySet()) {
if (entry.getKey() == Option.ACCESS_POLICY_VERSION && entry.getValue() != null) {
bqPatchRequest.setAccessPolicyVersion((Integer) entry.getValue());
}
if (options.containsKey(Option.ACCESS_POLICY_VERSION)) {
bqPatchRequest.setAccessPolicyVersion((Integer) options.get(Option.ACCESS_POLICY_VERSION));
}
if (options.containsKey(Option.DATASET_UPDATE_MODE)) {
bqPatchRequest.setUpdateMode(options.get(Option.DATASET_UPDATE_MODE).toString());
}
return bqPatchRequest.execute();
}
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import com.google.cloud.bigquery.BigQuery.DatasetField;
import com.google.cloud.bigquery.BigQuery.DatasetListOption;
import com.google.cloud.bigquery.BigQuery.DatasetOption;
import com.google.cloud.bigquery.BigQuery.DatasetUpdateMode;
import com.google.cloud.bigquery.BigQuery.DatasetView;
import com.google.cloud.bigquery.BigQuery.JobField;
import com.google.cloud.bigquery.BigQuery.JobListOption;
import com.google.cloud.bigquery.BigQuery.JobOption;
Expand Down Expand Up @@ -1235,18 +1237,20 @@ public void testGetDatasetWithAccessPolicyVersion() throws IOException {
"requests after the year 2024",
"location");
Acl acl = Acl.of(user, role, condition);
DatasetOption datasetOption = DatasetOption.accessPolicyVersion(3);
DatasetOption accessPolicyOption = DatasetOption.accessPolicyVersion(3);
DatasetOption viewOption = DatasetOption.datasetView(DatasetView.FULL);

Dataset dataset =
bigquery.create(
DatasetInfo.newBuilder(accessPolicyDataset)
.setDescription("Some Description")
.setAcl(ImmutableList.of(acl))
.build(),
datasetOption);
accessPolicyOption);
assertThat(dataset).isNotNull();

Dataset remoteDataset = bigquery.getDataset(accessPolicyDataset, datasetOption);
Dataset remoteDataset =
bigquery.getDataset(accessPolicyDataset, accessPolicyOption, viewOption);
assertNotNull(remoteDataset);
assertEquals(dataset.getDescription(), remoteDataset.getDescription());
assertNotNull(remoteDataset.getCreationTime());
Expand Down Expand Up @@ -1355,14 +1359,16 @@ public void testUpdateDatabaseWithAccessPolicyVersion() throws IOException {
acls.add(acl);

DatasetOption datasetOption = DatasetOption.accessPolicyVersion(3);
DatasetOption updateModeOption = DatasetOption.updateMode(DatasetUpdateMode.UPDATE_FULL);
Dataset updatedDataset =
bigquery.update(
dataset.toBuilder()
.setDescription("Updated Description")
.setLabels(null)
.setAcl(acls)
.build(),
datasetOption);
datasetOption,
updateModeOption);
assertNotNull(updatedDataset);
assertEquals(updatedDataset.getDescription(), "Updated Description");
assertThat(updatedDataset.getLabels().isEmpty());
Expand Down

Back | FazBrowse Home | New Git URL