Repository navigation
Closed
Labels
api: bigqueryIssues related to the BigQuery API.Issues related to the BigQuery API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-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.‘Nice-to-have’ improvement, new feature or different behavior or design.
Description
The code for processing the results of a query is a bit convoluted.
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
Reacted by Łukasz Byjoś and Oliver Hausler
Metadata
Metadata
Assignees
Labels
api: bigqueryIssues related to the BigQuery API.Issues related to the BigQuery API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-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.‘Nice-to-have’ improvement, new feature or different behavior or design.
Activity
mziccard commentedon Nov 4, 2016
@tswast yeah this would be nice to have. It's in the roadmap but we haven't had time to work on it yet.
danoscarmike commentedon Aug 9, 2017
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.
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
deps: update dependency com.google.cloud:google-cloud-logging to v3.2…
chore: remove obsolete release job configs (#1370)
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
chore: remove obsolete release job configs (#1370)
deps: update dependency com.google.cloud:google-cloud-spanner-bom to …
chore(main): release 2.13.3 (googleapis#1368)
chore(main): release 0.127.14 (#1370)
chore(main): release 0.127.14 (#1370)
deps: update dependency com.google.protobuf:protobuf-java-util to v3.…
deps: update dependency com.google.protobuf:protobuf-java-util to v3.…
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
feat: Support Cloud Bigtable Changestream (googleapis#1569)