Skip to content

Commit

Permalink
chore: update SimpleApp sample code to use stackoverflow public datas…
Browse files Browse the repository at this point in the history
…et (#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>
  • Loading branch information
Neenu1995 and gcf-owl-bot[bot] committed Feb 14, 2023
1 parent e431c17 commit f150bce
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -52,7 +52,7 @@ If you are using Maven without BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies:

```Groovy
implementation platform('com.google.cloud:libraries-bom:26.7.0')
implementation platform('com.google.cloud:libraries-bom:26.8.0')
implementation 'com.google.cloud:google-cloud-bigquery'
```
Expand Down
22 changes: 9 additions & 13 deletions samples/snippets/src/main/java/com/example/bigquery/SimpleApp.java
Expand Up @@ -39,10 +39,12 @@ public static void main(String... args) throws Exception {
// [START bigquery_simple_app_query]
QueryJobConfiguration queryConfig =
QueryJobConfiguration.newBuilder(
"SELECT commit, author, repo_name "
+ "FROM `bigquery-public-data.github_repos.commits` "
+ "WHERE subject like '%bigquery%' "
+ "ORDER BY subject DESC LIMIT 10")
"SELECT CONCAT('https://stackoverflow.com/questions/', "
+ "CAST(id as STRING)) as url, view_count "
+ "FROM `bigquery-public-data.stackoverflow.posts_questions` "
+ "WHERE tags like '%google-bigquery%' "
+ "ORDER BY view_count DESC "
+ "LIMIT 10")
// Use standard SQL syntax for queries.
// See: https://cloud.google.com/bigquery/sql-reference/
.setUseLegacySql(false)
Expand Down Expand Up @@ -72,15 +74,9 @@ public static void main(String... args) throws Exception {
// Print all pages of the results.
for (FieldValueList row : result.iterateAll()) {
// String type
String commit = row.get("commit").getStringValue();
// Record type
FieldValueList author = row.get("author").getRecordValue();
String name = author.get("name").getStringValue();
String email = author.get("email").getStringValue();
// String Repeated type
String repoName = row.get("repo_name").getRecordValue().get(0).getStringValue();
System.out.printf(
"Repo name: %s Author name: %s email: %s commit: %s\n", repoName, name, email, commit);
String url = row.get("url").getStringValue();
String viewCount = row.get("view_count").getStringValue();
System.out.printf("%s : %s views\n", url, viewCount);
}
// [END bigquery_simple_app_print]
}
Expand Down
Expand Up @@ -58,6 +58,6 @@ public void tearDown() {
public void testQuickstart() throws Exception {
SimpleApp.main();
String got = bout.toString();
assertThat(got).contains("Repo name:");
assertThat(got).contains("https://stackoverflow.com/questions/");
}
}

0 comments on commit f150bce

Please sign in to comment.