1

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

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.