hadoop - hive - Regex in Split function not giving output -
input :
[a,b], [c,d], [e,f] select split(col,'\\,') table_1;
with above query, able split on every comma. (inside , outside braces)
i need split on commas outside braces. changed query below.
select split(col,',(?=\[)') table_1;
regex used correct knowledge not able output.
output required:
"[a,b]","[c,d]","[e,f]"
it looks there space in between data, try regex instead:
,\\s(?=\\[)
edit:
so, not sure if have spaces or not in column, here both:
case 1: without spaces in column
hive> describe a; ok t string hive> select * a; ok [a,b],[c,d],[e,f] time taken: 0.089 seconds, fetched: 1 row(s) hive> select split(t, ',(?=\\[)') a; ok ["[a,b]","[c,d]","[e,f]"] time taken: 0.081 seconds, fetched: 1 row(s)
case 2: spaces in column
hive> describe b; ok t string hive> select * b; ok [a,b], [c,d], [e,f] time taken: 0.084 seconds, fetched: 1 row(s) hive> select split(t, ',\\s(?=\\[)') b; ok ["[a,b]","[c,d]","[e,f]"] time taken: 0.082 seconds, fetched: 1 row(s)
Comments
Post a Comment