GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bq_update_dataset_description sample (#1779) · shinyay/java-docs-samples@65d9297

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • bigquery/cloud-client/src
    • main/java/com/example/bigquery
      • UpdateDatasetAccess.java
      • UpdateDatasetDescription.java
    • test/java/com/example/bigquery
      • UpdateDatasetDescriptionIT.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: bigquery/cloud-client/src/main/java/com/example/bigquery/UpdateDatasetAccess.java
+1-1Lines 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");
Collapse file

‎bigquery/cloud-client/src/main/java/com/example/bigquery/UpdateDatasetDescription.java‎

Copy file name to clipboard
+50Lines 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]
Collapse file

‎bigquery/cloud-client/src/test/java/com/example/bigquery/UpdateDatasetDescriptionIT.java‎

Copy file name to clipboard
+56Lines 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+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.