Aditi Hegde
Aditi Hegde

Reputation: 13

Hive: String split based on backslash \

I have a table with column named path which contains values with backslash:

\ModuleCalData\ComputerName
\ModuleCalData\StartTime
\ModuleCalData\EndTime
\ModuleCalData\SummaryParameters\TextMeasured\Value
\ModuleCalDataSummaryParameters\TextMeasured\Name

I'm trying to split and access each element separately. The query is

select split(path,'\\')[0] from test_data_tag;

This query is erroring out

Failed with exception
java.io.IOException:org.apache.hadoop.hive.ql.metadata.HiveException:
Error evaluating split(path, '\')[0]

Can anyone help how to split the string on \ in hive?

Upvotes: 1

Views: 2116

Answers (1)

David דודו Markovitz
David דודו Markovitz

Reputation: 44921

select path
      ,split(path,'\\\\')   as split_path

from   mytable
;

+-----------------------------+-------------------------------------+
|             path            |              split_path             |
+-----------------------------+-------------------------------------+
| \ModuleCalData\ComputerName | ["","ModuleCalData","ComputerName"] |
+-----------------------------+-------------------------------------+

Upvotes: 2

Related Questions