I am using this library to interact with BigQuery API. Is there a way to convert the returned rows into a Java Object easily? Or do I have to work with the Schema and FieldValueList?
2 Answers
Yes, if you are using the Java BigQuery client (which is recommended), you would need to work with the Schema and FieldValueList since they are part of the manually written layer on top of the BigQuery API. You could iterate on the object and maybe construct a new object:
for (FieldValueList values : result.iterateAll()) {
for (FieldValue value : values) {
for (FieldValue record : value.getRecordValue()) {
// construct new object
}
}
If you wish to not use Schema and FieldValueList, you can use the auto-generated BigQuery Java client library.
Comments
Supposing that you want to parse it to list of map
List<Map<String, Object>> bqResult = new ArrayList<>();
Schema schema = result.getSchema();
for (FieldValueList row : result.iterateAll()) {
Map<String, Object> m = new HashMap<>();
for(Field field : schema.getFields()){
m.put(field.getName(), row.get(field.getName()).getStringValue());
}
bqResult.add(m);
}
SchemaandFieldValueList. They are manual written abstractions sitting on top of the discovery-based Java BigQuery API.