Skip to content

Commit c50c17b

Browse files
authored
fix: Fix BigQuery#listDatasets to include dataset location in the response (#3238)
1 parent 75ea095 commit c50c17b

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public Dataset apply(DatasetList.Datasets datasetPb) {
9595
.setFriendlyName(datasetPb.getFriendlyName())
9696
.setId(datasetPb.getId())
9797
.setKind(datasetPb.getKind())
98+
.setLocation(datasetPb.getLocation())
9899
.setLabels(datasetPb.getLabels());
99100
}
100101
};

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,22 @@ public class BigQueryImplTest {
8181
Acl.of(Acl.Group.ofAllAuthenticatedUsers(), Acl.Role.READER),
8282
Acl.of(new Acl.View(TableId.of(PROJECT, "dataset", "table"))));
8383
private static final DatasetInfo DATASET_INFO =
84-
DatasetInfo.newBuilder(DATASET).setAcl(ACCESS_RULES).setDescription("description").build();
84+
DatasetInfo.newBuilder(DATASET)
85+
.setAcl(ACCESS_RULES)
86+
.setDescription("description")
87+
.setLocation(LOCATION)
88+
.build();
8589
private static final DatasetInfo DATASET_INFO_WITH_PROJECT =
8690
DatasetInfo.newBuilder(PROJECT, DATASET)
8791
.setAcl(ACCESS_RULES_WITH_PROJECT)
8892
.setDescription("description")
93+
.setLocation(LOCATION)
8994
.build();
9095
private static final DatasetInfo OTHER_DATASET_INFO =
9196
DatasetInfo.newBuilder(PROJECT, OTHER_DATASET)
9297
.setAcl(ACCESS_RULES)
9398
.setDescription("other description")
99+
.setLocation(LOCATION)
94100
.build();
95101
private static final TableId TABLE_ID = TableId.of(DATASET, TABLE);
96102
private static final TableId OTHER_TABLE_ID = TableId.of(PROJECT, DATASET, OTHER_TABLE);

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,20 @@ public class ITBigQueryTest {
775775

776776
private static final Set<String> PUBLIC_DATASETS =
777777
ImmutableSet.of("github_repos", "hacker_news", "noaa_gsod", "samples", "usa_names");
778+
private static final Map<String, String> PUBLIC_DATASETS_LOCATION =
779+
ImmutableMap.<String, String>builder()
780+
.put("github_repos", "US")
781+
.put("hacker_news", "US")
782+
.put("noaa_gsod", "US")
783+
.put("samples", "US")
784+
.put("usa_names", "US")
785+
// Dataset url:
786+
// https://console.cloud.google.com/bigquery?project=bigquery-public-data&ws=!1m4!1m3!3m2!1sbigquery-public-data!2sgnomAD_asiane1
787+
.put("gnomAD_asiane1", "asia-northeast1")
788+
// Dataset url:
789+
// https://console.cloud.google.com/bigquery?project=bigquery-public-data&ws=!1m4!1m3!3m2!1sbigquery-public-data!2sgnomAD_eu
790+
.put("gnomAD_eu", "EU")
791+
.build();
778792

779793
private static final String PUBLIC_PROJECT = "bigquery-public-data";
780794
private static final String PUBLIC_DATASET = "census_bureau_international";
@@ -1113,11 +1127,16 @@ public void testListDatasets() {
11131127
Page<Dataset> datasets = bigquery.listDatasets("bigquery-public-data");
11141128
Iterator<Dataset> iterator = datasets.iterateAll().iterator();
11151129
Set<String> datasetNames = new HashSet<>();
1130+
Map<String, String> datasetLocation = new HashMap<>();
11161131
while (iterator.hasNext()) {
1117-
datasetNames.add(iterator.next().getDatasetId().getDataset());
1132+
Dataset dataset = iterator.next();
1133+
String name = dataset.getDatasetId().getDataset();
1134+
datasetNames.add(name);
1135+
datasetLocation.put(name, dataset.getLocation());
11181136
}
11191137
for (String type : PUBLIC_DATASETS) {
11201138
assertTrue(datasetNames.contains(type));
1139+
assertEquals(PUBLIC_DATASETS_LOCATION.get(type), datasetLocation.get(type));
11211140
}
11221141
}
11231142

@@ -6759,11 +6778,16 @@ public void testUniverseDomainWithMatchingDomain() {
67596778
Page<Dataset> datasets = bigQuery.listDatasets("bigquery-public-data");
67606779
Iterator<Dataset> iterator = datasets.iterateAll().iterator();
67616780
Set<String> datasetNames = new HashSet<>();
6781+
Map<String, String> datasetLocation = new HashMap<>();
67626782
while (iterator.hasNext()) {
6763-
datasetNames.add(iterator.next().getDatasetId().getDataset());
6783+
Dataset dataset = iterator.next();
6784+
String name = dataset.getDatasetId().getDataset();
6785+
datasetNames.add(name);
6786+
datasetLocation.put(name, dataset.getLocation());
67646787
}
67656788
for (String type : PUBLIC_DATASETS) {
67666789
assertTrue(datasetNames.contains(type));
6790+
assertEquals(PUBLIC_DATASETS_LOCATION.get(type), datasetLocation.get(type));
67676791
}
67686792
}
67696793

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpcTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ public void testListToDataset() {
3535
.setId("project-id:dataset-id")
3636
.setFriendlyName("friendly")
3737
.setKind("bigquery#dataset")
38-
.setLabels(Collections.singletonMap("foo", "bar"));
38+
.setLabels(Collections.singletonMap("foo", "bar"))
39+
.setLocation("test-region-1");
3940
Dataset dataset = HttpBigQueryRpc.LIST_TO_DATASET.apply(listDataSet);
4041

4142
assertThat(dataset.getKind()).isEqualTo("bigquery#dataset");
4243
assertThat(dataset.getId()).isEqualTo("project-id:dataset-id");
4344
assertThat(dataset.getFriendlyName()).isEqualTo("friendly");
4445
assertThat(dataset.getDatasetReference()).isEqualTo(datasetRef);
4546
assertThat(dataset.getLabels()).containsExactly("foo", "bar");
47+
assertThat(dataset.getLocation()).isEqualTo("test-region-1");
4648
}
4749
}

0 commit comments

Comments
 (0)