I am trying to load a csv with pipe delimiter to an hive external table. The pipe occurring within data fields are enclosed within quotes. Double quotes occurring within data are escaped with \ . When I configure external table, I see data with double quotes are not interpreted properly.
test.csv
id|name
105|"Test | pipe delim in field"
107|\" Test Escaped single double quote in HIVE
108|\" Test Escaped enclosed double quote in HIVE \"
109|\\" Test Escaped enclosed double quote in HIVE \"
110|\\" Test Escaped enclosed double quote in HIVE \\"
External table create statement
drop table test_schema.hive_test;
CREATE EXTERNAL TABLE test_schema.hive_test (id string, name string)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde' WITH SERDEPROPERTIES
(
"separatorChar" = "|",
"quoteChar" = "\"",
"escapeChar" = "\\"
)
LOCATION '/staging/test/hive'
tblproperties ("skip.header.line.count"="1");
Output
+---------------+-------------------------------------------------+
| hive_test.id | hive_test.name |
+---------------+-------------------------------------------------+
| 105 | Test | pipe delim in field |
| 107 | NULL |
| 108 | NULL |
| 109 | NULL |
| 110 | " Test Escaped enclosed double quote in HIVE \ |
+---------------+-------------------------------------------------+
Expected Output
+---------------+-------------------------------------------------+
| hive_test.id | hive_test.name |
+---------------+-------------------------------------------------+
| 105 | Test | pipe delim in field |
| 107 | " Test Escaped single double quote in HIVE |
| 108 | " Test Escaped enclosed double quote in HIVE " |
| 109 | NULL |
| 110 | NULL |
+---------------+-------------------------------------------------+
Open CSV version 2.3