cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Differentiate null values in Variant Data type

vgautam
New Contributor

Hello, 

Based on the documentation here, in both scenarios below try_variant_get returns a null: 

  • If the object cannot be found
  • if the object cannot be cast 

How does one differentiate between the two scenarios?

 

1 REPLY 1

Alberto_Umana
Databricks Employee
Databricks Employee

Hi @vgautam,

In the try_variant_get function, NULL is returned in two scenarios:

  1. Object Not Found: If the specified path does not exist in the JSON object.
  2. Invalid Cast: If the object at the specified path cannot be cast to the target type.

To differentiate between these two scenarios, you would need to handle the cases separately in your SQL logic. Unfortunately, the try_variant_get function itself does not provide a direct way to distinguish between these two scenarios. You may need to use additional logic or checks to determine the exact cause of the NULL value

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group