1

I have a problem with split pattern in hive query.
sample string from the table:

['EN', 'FR', 'DE', 'IT', 'JA', 'RU', 'ZH', 'ES', 'ZH']

and now with the split function I would like to return this string in this way:

EN  
FR  
...  
ZH  

at first I tried this way: split(data.language, ',')[1]
I don't know how I can get rid of square brackets and quotation marks.

1 Answer 1

2

Use regexp_replace to replace [|]|' characters then split the string column then explode the array.

select explode(split(regexp_replace(sample,"[\\[|\\'|\\]]",""),",")) 
   from (
select string("['EN', 'FR', 'DE', 'IT', 'JA', 'RU', 'ZH', 'ES', 'ZH']")as sample
     )e;

--output
--+---+
--|col|
--+---+
--| EN|
--| FR|
--| DE|
--| IT|
--| JA|
--| RU|
--| ZH|
--| ES|
--| ZH|
--+---+
Sign up to request clarification or add additional context in comments.

1 Comment

If I have a poem that has a category and this word list, I can get that effect: --+---+-----------+ --|col|category | --+----------------+ --|EN| GAMES | --|FR| GAMES | ...

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.