Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

split string that includes semicolons in Hive

Tags:

hive

how can I achieve splitting a string field delimited by semicolons in hive?

select split(f1,";")[0] from table;
like image 485
jamborta Avatar asked Jun 20 '13 11:06

jamborta


People also ask

How split function works in hive?

Hive split(string A, string pattern) Function The split function splits the string around the pattern pat and returns an array of strings. You can also specify regular expressions as patterns.

How to split by comma in Java?

To split a string with comma, use the split() method in Java. str. split("[,]", 0);


3 Answers

You can write this way select split(f1,'\073')[0] from table;

like image 189
santhosh Avatar answered Oct 16 '22 09:10

santhosh


Wanted to re-iterate that this is indeed a Hue bug, but only in the Hortonworks version. The latest Cloudera version of the Hue runs this fine.

like image 24
Sayon M Avatar answered Oct 16 '22 09:10

Sayon M


The below command will work:

input table

 1;Neethu KV
  2;Ram KV

query 1:

select split(name,"\\;")[0],school from table_test, where name refers to your column name to be split.

output

1 KV
2 KV

Query 2 :

select split(name,"\\;")[1],school from table_test, where name refers to your column name to be split.

output

Neethu KV
Ram KV
like image 26
Neethu Lalitha Avatar answered Oct 16 '22 09:10

Neethu Lalitha