Skip to content

Commit a7ffacf

Browse files
slilichenkoPhongChuonggcf-owl-bot[bot]
authored
chore: change row and column variable names in SimpleQuery example (#3059)
* Changed the names of the row and column variables to make their purpose clear. * Changed the code sample to reflect the real life usage * Updated the query and column names * Attempt to fix formatting. * Modified the IT test to match the query in the sample. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: PhongChuong <[email protected]> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 645ff9c commit a7ffacf

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

samples/snippets/src/main/java/com/example/bigquery/SimpleQuery.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.example.bigquery;
1818

1919
// [START bigquery_query]
20+
2021
import com.google.cloud.bigquery.BigQuery;
2122
import com.google.cloud.bigquery.BigQueryException;
2223
import com.google.cloud.bigquery.BigQueryOptions;
@@ -27,7 +28,9 @@ public class SimpleQuery {
2728

2829
public static void main(String[] args) {
2930
// TODO(developer): Replace this query before running the sample.
30-
String query = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
31+
String query =
32+
"SELECT corpus, count(*) as corpus_count "
33+
+ "FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
3134
simpleQuery(query);
3235
}
3336

@@ -44,7 +47,14 @@ public static void simpleQuery(String query) {
4447
TableResult result = bigquery.query(queryConfig);
4548

4649
// Print the results.
47-
result.iterateAll().forEach(rows -> rows.forEach(row -> System.out.println(row.getValue())));
50+
result
51+
.iterateAll()
52+
.forEach(
53+
row -> {
54+
System.out.print("corpus:" + row.get("corpus").getStringValue());
55+
System.out.print(", count:" + row.get("corpus_count").getLongValue());
56+
System.out.println();
57+
});
4858

4959
System.out.println("Query ran successfully");
5060
} catch (BigQueryException | InterruptedException e) {

samples/snippets/src/test/java/com/example/bigquery/SimpleQueryIT.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public void tearDown() {
5151

5252
@Test
5353
public void testSimpleQuery() {
54-
String query = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
54+
String query =
55+
"SELECT corpus, count(*) as corpus_count "
56+
+ "FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
5557

5658
SimpleQuery.simpleQuery(query);
5759
assertThat(bout.toString()).contains("Query ran successfully");

0 commit comments

Comments
 (0)