1

In a Java UDF I want to determine whether a Variant value is a JSON null but it seems the only way to do it is to convert it to a Json String and compare it to the string "null". Since I am working with values that may be very large, converting the value to a json string just to check for null seems wasteful. Is there not a better way?

// Current
boolean isNull = variant.asJsonString().equals("null");
 
// Preferred
boolean isNull = variant.isNull();

It looks like Variants contain a Jackson JsonNode instance internally. Could there be a pass-thru that calls JsonNode.isNull() ?

From https://community.snowflake.com/s/question/0D5Do00000D7rgsKAB/how-best-to-determine-json-null-variant-in-a-java-udf.

Felipe Hoffa
  • 54,922
  • 16
  • 151
  • 325
  • Deleting my answer, as it doesn't satisfy for a JSON null, as in `select java_variant_isnull(parse_json('{"a":null}'))` – Felipe Hoffa Jan 31 '23 at 04:48

0 Answers0