Skip to content

Commit 371481f

Browse files
authored
Merge branch 'master' into master
2 parents 51513bb + cde2271 commit 371481f

File tree

16 files changed

+2010
-81
lines changed

16 files changed

+2010
-81
lines changed

bigquery/cloud-client/src/main/java/com/example/bigquery/UpdateDatasetAccess.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static void updateDatasetAccess(String datasetName) {
5050
ArrayList<Acl> acls = new ArrayList<>(dataset.getAcl());
5151
acls.add(newEntry);
5252

53-
//Update the dataset to use the new ACLs
53+
// Update the dataset to use the new ACLs
5454
try {
5555
bigquery.update(dataset.toBuilder().setAcl(acls).build());
5656
System.out.println("Dataset Access Control updated successfully");
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.bigquery;
18+
19+
// [START bigquery_update_dataset_description]
20+
import com.google.cloud.bigquery.BigQuery;
21+
import com.google.cloud.bigquery.BigQueryException;
22+
import com.google.cloud.bigquery.BigQueryOptions;
23+
import com.google.cloud.bigquery.Dataset;
24+
25+
public class UpdateDatasetDescription {
26+
27+
public static void runUpdateDatasetDescription() {
28+
// TODO(developer): Replace these variables before running the sample.
29+
String datasetName = "my-dataset-name";
30+
String newDescription = "this is the new dataset description";
31+
updateDatasetDescription(datasetName, newDescription);
32+
}
33+
34+
public static void updateDatasetDescription(String datasetName, String newDescription) {
35+
// Initialize client that will be used to send requests. This client only needs to be created
36+
// once, and can be reused for multiple requests.
37+
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
38+
39+
Dataset dataset = bigquery.getDataset(datasetName);
40+
41+
// Update dataset description
42+
try {
43+
bigquery.update(dataset.toBuilder().setDescription(newDescription).build());
44+
System.out.println("Dataset description updated successfully to " + newDescription);
45+
} catch (BigQueryException e) {
46+
System.out.println("Dataset description was not updated \n" + e.toString());
47+
}
48+
}
49+
}
50+
// [END bigquery_update_dataset_description]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.bigquery;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import com.google.cloud.bigquery.testing.RemoteBigQueryHelper;
22+
import java.io.ByteArrayOutputStream;
23+
import java.io.PrintStream;
24+
import org.junit.After;
25+
import org.junit.Before;
26+
import org.junit.Test;
27+
28+
public class UpdateDatasetDescriptionIT {
29+
private ByteArrayOutputStream bout;
30+
private PrintStream out;
31+
32+
@Before
33+
public void setUp() throws Exception {
34+
bout = new ByteArrayOutputStream();
35+
out = new PrintStream(bout);
36+
System.setOut(out);
37+
}
38+
39+
@After
40+
public void tearDown() {
41+
System.setOut(null);
42+
}
43+
44+
@Test
45+
public void updateDatasetDescription() {
46+
String generatedDatasetName = RemoteBigQueryHelper.generateDatasetName();
47+
String newDescription = "new description!";
48+
// Create a dataset in order to modify its description
49+
CreateDataset.createDataset(generatedDatasetName);
50+
51+
// Modify dataset's description
52+
UpdateDatasetDescription.updateDatasetDescription(generatedDatasetName, newDescription);
53+
assertThat(bout.toString())
54+
.contains("Dataset description updated successfully to " + newDescription);
55+
}
56+
}

bigtable/snippets/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
<version>4.13-beta-3</version>
3838
<scope>test</scope>
3939
</dependency>
40+
<dependency>
41+
<groupId>com.google.truth</groupId>
42+
<artifactId>truth</artifactId>
43+
<version>1.0</version>
44+
<scope>test</scope>
45+
</dependency>
4046
<!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-bigtable -->
4147
<dependency>
4248
<groupId>com.google.cloud</groupId>

0 commit comments

Comments
 (0)