You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a table with numerous nullable fields but when using the Java api to get the data from a row I've found that instead of simply getting null instead of a string the code throws an exception.
* @throws ClassCastException if the field is not a primitive type
* @throws NullPointerException if {@link #isNull()} returns {@code true}
*/
@SuppressWarnings("unchecked")
publicStringgetStringValue() {
checkNotNull(value);
return (String) value;
}
As users are likely to want to map all results from a query regardless of whether the field was null or not it would be better if the methods for getting a String or Long handled null gracefully. Or at least provide an alternative method where the caller can provide a default value or null if the fields value is null.
Fortunately as I'm using Kotlin I can work around this for now with an extension function on FieldValueList:
fun FieldValueList.getNullable(name: String): FieldValue? = if (this.get(name).isNull) null else this.get(name)
which in turn means I can simply do row.getNullable("my_nullable_column")?.stringValue when mapping the FieldValueList to an object.
If getStringValue() had on overloaded method that takes an arg that's used as a default I could have done something like:
I have a table with numerous nullable fields but when using the Java api to get the data from a row I've found that instead of simply getting null instead of a string the code throws an exception.
java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/FieldValue.java
Lines 107 to 121 in 45c5096
As users are likely to want to map all results from a query regardless of whether the field was null or not it would be better if the methods for getting a String or Long handled null gracefully. Or at least provide an alternative method where the caller can provide a default value or null if the fields value is null.
Fortunately as I'm using Kotlin I can work around this for now with an extension function on FieldValueList:
which in turn means I can simply do
row.getNullable("my_nullable_column")?.stringValue
when mapping the FieldValueList to an object.If
getStringValue()
had on overloaded method that takes an arg that's used as a default I could have done something like:which would be convenient. Also this could be added without breaking the existing API.
The text was updated successfully, but these errors were encountered: