I have the following part of a Bigquery query:
(SELECT SUM(SAFE_CAST(JSON_VALUE(result.value[0]) AS NUMERIC) AS minutes
when running on bigquery it returns correct number for example 230, now when in Java I try to get this value from the same query like this (SchemaAndRecord
contains/is the result of the query):
@Override public KV<String, Integer> apply(SchemaAndRecord input) {
GenericRecord genericRecord = input.getRecord();
Integer minutes = Integer.valueOf(genericRecord.get("minutes").toString());
return KV.of("key", minutes);
}
I get the following error:
java.lang.NumberFormatException: For input string: "java.nio.HeapByteBuffer[pos=0 lim=16 cap=16]"
I logged the result of doing genericRecord.get("minutes").toString()
and it shows: java.nio.HeapByteBuffer[pos=0 lim=16 cap=16]
So im a little confused how to handle this? I managed to make it work by changing in the query like this:
(SELECT SUM(SAFE_CAST(JSON_VALUE(result.value[0]) AS INTEGER) AS minutes
but I do not understand what is wrong with the NUMERIC type in my case, would like to understand and also see if there is a way to make the java code work keeping NUMERIC in the query