BigQuery Schema Parser
Google BigQuery Parser is a small librarary which allows you to transform usual BigQuery JSON schema (both its representations - String and JsonObject) or QueryResponse (Google BigQuery Java SDK) into List of usual JsonElements for further processing.
Each JsonElement object in result will contain all the fields and values of the given row and can be mapped to a POJO object (e.g. with the help of Gson library).
For example this kind of JSON:
{
"cacheHit" : false,
"etag" : "someEtag",
"jobComplete" : true,
"jobReference" : {
"jobId" : "someJobId",
"projectId" : "someProjectId"
},
"kind" : "bigquery#getQueryResultsResponse",
"rows" : [ {
"f" : [ {
"v" : "9.3.3"
}, {
"v" : "ios"
} ]
}, {
"f" : [ {
"v" : "4.4.4"
}, {
"v" : "android"
} ]
} ],
"schema" : {
"fields" : [ {
"mode" : "NULLABLE",
"name" : "version",
"type" : "STRING"
}, {
"mode" : "NULLABLE",
"name" : "platform",
"type" : "STRING"
} ]
},
"totalBytesProcessed" : "201954676",
"totalRows" : "2"
}
will be transformed to the List<JsonElement>
:
[{"version":"9.3.3","platform":"ios"}, {"version":"4.4.4","platform":"android"}]
Uses Java 8.
Maven dependency
<dependency>
<groupId>com.github.ailyenko</groupId>
<artifactId>bigquery-schema-parser</artifactId>
<version>1.0.1</version>
</dependency>
Gradle dependency
compile 'com.github.ailyenko:bigquery-schema-parser:1.0.1'
Examples
// from QueryResponse:
QueryResponse queryResponse = bigQuery.jobs().query(projectId, queryRequest).execute();
List<JsonElement> rows = BigQuerySchemaParser.parse(queryResponse);
// from JsonObject:
JsonObject jsonObject = queryResponseJsonElement.getAsJsonObject();
List<JsonElement> rows = BigQuerySchemaParser.parse(jsonObject);
// from String:
List<JsonElement> rows = BigQuerySchemaParser.parse(queryResponseJsonString);
Development
You're always welcome to contribute to the project!