6

Want to remove nulls from an array in hive/sql

for example : array is ['1',null] after converting to string values it should be '1' only.

to split the array I am using below:

concat_ws( ",", array_val)

this gives : 1,null

required output : 1

Thanks for the help!

1 Answer 1

2

Use regexp_replace to remove null from concatenated string:

hive> select regexp_replace('null,1,2,null,2,3,null','(,+null)|(^null,)','');
OK
1,2,2,3
Time taken: 6.006 seconds, Fetched: 1 row(s)
Sign up to request clarification or add additional context in comments.

Comments

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.