0

I can type cast NULL as a string. How can I type cast an empty array as an empty array of strings? I need to solve it inside the SQL query. The following snippet throws a ValueError: Some of types cannot be determined after inferring

df = spark.sql("select Array()").collect()

display(df)

2 Answers 2

1

I only found a somewhat roundabout way of doing this only with SQL:

select from_json("[]", "array<string>")
Sign up to request clarification or add additional context in comments.

Comments

-1

I think just keeping quotes should have empty string array

df = spark.sql("select array('')").collect()

display(df)

1 Comment

This gives an array with one element (an empty string). I want an empty array that is typed as an array of strings

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.