Skip to content

Commit f150bce

Browse files
chore: update SimpleApp sample code to use stackoverflow public dataset (#2523)
* chore: update SimpleApp sample code to use stackoverflow public dataset * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * sample checkstyle fix * chore: rename SimpleApp to App * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: revert file name change * chore: revert filename changes * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent e431c17 commit f150bce

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ If you are using Maven without BOM, add this to your dependencies:
5252
If you are using Gradle 5.x or later, add this to your dependencies:
5353

5454
```Groovy
55-
implementation platform('com.google.cloud:libraries-bom:26.7.0')
55+
implementation platform('com.google.cloud:libraries-bom:26.8.0')
5656
5757
implementation 'com.google.cloud:google-cloud-bigquery'
5858
```

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ public static void main(String... args) throws Exception {
3939
// [START bigquery_simple_app_query]
4040
QueryJobConfiguration queryConfig =
4141
QueryJobConfiguration.newBuilder(
42-
"SELECT commit, author, repo_name "
43-
+ "FROM `bigquery-public-data.github_repos.commits` "
44-
+ "WHERE subject like '%bigquery%' "
45-
+ "ORDER BY subject DESC LIMIT 10")
42+
"SELECT CONCAT('https://stackoverflow.com/questions/', "
43+
+ "CAST(id as STRING)) as url, view_count "
44+
+ "FROM `bigquery-public-data.stackoverflow.posts_questions` "
45+
+ "WHERE tags like '%google-bigquery%' "
46+
+ "ORDER BY view_count DESC "
47+
+ "LIMIT 10")
4648
// Use standard SQL syntax for queries.
4749
// See: https://cloud.google.com/bigquery/sql-reference/
4850
.setUseLegacySql(false)
@@ -72,15 +74,9 @@ public static void main(String... args) throws Exception {
7274
// Print all pages of the results.
7375
for (FieldValueList row : result.iterateAll()) {
7476
// String type
75-
String commit = row.get("commit").getStringValue();
76-
// Record type
77-
FieldValueList author = row.get("author").getRecordValue();
78-
String name = author.get("name").getStringValue();
79-
String email = author.get("email").getStringValue();
80-
// String Repeated type
81-
String repoName = row.get("repo_name").getRecordValue().get(0).getStringValue();
82-
System.out.printf(
83-
"Repo name: %s Author name: %s email: %s commit: %s\n", repoName, name, email, commit);
77+
String url = row.get("url").getStringValue();
78+
String viewCount = row.get("view_count").getStringValue();
79+
System.out.printf("%s : %s views\n", url, viewCount);
8480
}
8581
// [END bigquery_simple_app_print]
8682
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ public void tearDown() {
5858
public void testQuickstart() throws Exception {
5959
SimpleApp.main();
6060
String got = bout.toString();
61-
assertThat(got).contains("Repo name:");
61+
assertThat(got).contains("https://stackoverflow.com/questions/");
6262
}
6363
}

0 commit comments

Comments
 (0)