Skip to content
Advertisement

BigQuery TableResult casting options

How can I cast the TableResult to the following format List<Map<String, Any>>

Map contains the columns and its value respectively. Multiple rows are added to the list.

I tried something like this, but it throws an error -> com.google.cloud.bigquery.TableResult cannot be cast to java.util.List

JavaScript

How can we replicate something similar to jdbc template. For example with jdbc template we can do this way

JavaScript

and this returns the result in specific rowMapper format. How can we achieve this using BigQuery?

Advertisement

Answer

If you want to have a similar to Spring’s API, you need to:

  1. Declare the same interface:
JavaScript
  1. Come up with some way to include RowMapper into the query result transformation pipeline. For instance, via extension method for TableResult class:
JavaScript

RowMapper implementation returning column names mapped to their values:

JavaScript

Usage:

JavaScript
Advertisement