Skip to content

bigquery: support loading a POJO or Map like GSON does #1370

Closed

Description

@tswast

The code for processing the results of a query is a bit convoluted.

Example from https://github.com/GoogleCloudPlatform/java-docs-samples/blob/2e3f285b7dccfd978b14033f9869e728e8c13e56/bigquery/cloud-client/src/main/java/com/example/bigquery/SimpleApp.java#L53

    QueryResult result = response.result();

    while (result != null) {
      Iterator<List<FieldValue>> iter = result.iterateAll();

      while (iter.hasNext()) {
        List<FieldValue> row = iter.next();
        List<FieldValue> titles = row.get(0).repeatedValue();
        System.out.println("titles:");

        for (FieldValue titleValue : titles) {
          List<FieldValue> titleRecord = titleValue.recordValue();
          String title = titleRecord.get(0).stringValue();
          long uniqueWords = titleRecord.get(1).longValue();
          System.out.printf("\t%s: %d\n", title, uniqueWords);
        }

        long uniqueWords = row.get(1).longValue();
        System.out.printf("total unique words: %d\n", uniqueWords);
      }

      result = result.nextPage();

For a fixed query, I'd love to be able to fill in the object the way that I can in GSON. Then I'd be able to do something like:

    QueryResult result = response.result();

    while (result != null) {
      Iterator<List<FieldValue>> iter = result.iterateAll();

      while (iter.hasNext()) {
        List<FieldValue> row = iter.next();
        // I can't do this yet, but I'd love to be able to load an object
        // like I can with GSON.
        // I'm thinking maybe it only makes sense per-row rather than for
        // a whole query, due to paging.
        WordCounts counts = row.as(WordCounts.class);
        System.out.println("titles:");

        for (Title title : counts.getTitles()) {
          System.out.printf("\t%s: %d\n", title.getTitle(), title.getUniqueWords());
        }

        System.out.printf("total unique words: %d\n", counts.getTotalWords());
      }

      result = result.nextPage();

For context, here is a similar issue in the Go libraries: googleapis/google-cloud-go#399

Activity

  1. added
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    api: bigqueryIssues related to the BigQuery API.
    on Nov 3, 2016
  2. mziccard commented on Nov 4, 2016

    @mziccard
    Contributor

    @tswast yeah this would be nice to have. It's in the roadmap but we haven't had time to work on it yet.

  3. added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Jun 12, 2017
  4. danoscarmike commented on Aug 9, 2017

    @danoscarmike
    Contributor

    This has been added to our feature backlog: https://github.com/GoogleCloudPlatform/google-cloud-java/wiki/Feature-backlog. This issue will be closed but is linked in the backlog and can continue to be used for comment and discussion.

  5. added a commit that references this issue on Mar 30, 2026
  6. added a commit that references this issue on Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the BigQuery API.priority: p2Moderately-important priority. Fix may not be included in next release.triaged for GAtype: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions