AbhilashNagilla
Databricks Employee
Databricks Employee

Your screenshot already uses TO_VARIANT_OBJECT; the VOID field inside the STRUCT is what causes the failure.

TO_VARIANT_OBJECT requires every field to be convertible to VARIANT, but VOID is not accepted in that nested path. Scalar CAST(PAYMENT_DATE AS VARIANT) works because untyped NULL can be cast directly to VARIANT.

  1. If the intended type is known, cast it at the source, for example CAST(NULL AS DATE), then use NAMED_STRUCT to preserve the field name.

  2. If the type is unknown, use TO_VARIANT_OBJECT(STRUCT(CAST(PAYMENT_DATE AS VARIANT) AS PAYMENT_DATE, TRANSACTION_DATE)).

  3. For unknown or wide schemas, PARSE_JSON(TO_JSON(STRUCT(*), map('ignoreNullFields', 'false'))) handles VOID fields, but converts DATE and TIMESTAMP values to strings.

View solution in original post