2

I am working on hive, reading some fields from JSON string through hive query. One field in JSON string is actually an array of string but stored as string like {... , 'arrText' : '["a","b","c"]',... }

I want to read this string as array of string in hive query itself.

hive (joshua)> 
              > select some_function('["a","b","c"]');
OK
["a","b","c"]
Time taken: 0.134 seconds, Fetched: 1 row(s)

Can I have something (hive built in) in place of some_function & get it done rather than writing UDF for it?

Thanks in advance

1 Answer 1

3

One way to do it without udf is use some pre-defined hive functions like split, regex extract etc

select split(regexp_extract('["a","b","c"]','^\\["(.*)\\"]$',1),'","');
=> ["a","b","c"]

Even it can handle intermediate commas

select split(regexp_extract('["a","b,c","d"]','^\\["(.*)\\"]$',1),'","');
=> ["a","b,c","d"]

Hop it helps

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.