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:ย 

Arrays of complex type always evaluate to ARRAY<STRING>?

pt-jake
New Contributor II

Arrays of complex types seemingly always evaluate to ARRAY<STRING>. Therefore, casting or attempting to load JSON data with empty array values fails. For example, attempting to cast a JSON value of {"likes": []...} on load to the following table schema fail with the following error:

Schema:

array<struct<gid:string,user:struct<gid:string,name:string,resource_type:string>>>

Error:

"Error copy: [DATATYPE_MISMATCH.CAST_WITHOUT_SUGGESTION] Cannot resolve "likes" due to data type mismatch: cannot cast "ARRAY<STRING>" to "ARRAY<STRUCT<gid: STRING, user: STRUCT<gid: STRING, name: STRING, resource_type: STRING>>>"

What is the best way to handle empty/null complex-typed arrays?

1 REPLY 1

Anonymous
Not applicable

Hi @Jake Neyerโ€‹ 

Thank you for posting your question in our community! We are happy to assist you.

To help us provide you with the most accurate information, could you please take a moment to review the responses and select the one that best answers your question?

This will also help other community members who may have similar questions in the future. Thank you for your participation and let us know if you need any further assistance! 

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