3

Since by default serde quotes fields by ", How can I not quote my fields using serde?

I tried:

row format serde "org.apache.hadoop.hive.serde2.OpenCSVSerde"
with serdeproperties(
"separatorChar" = ",",
"quoteChar" = "")

But i'm getting

FAILED: SemanticException java.lang.StringIndexOutOfBoundsException: String index out of range: 0
dtolnay
  • 9,621
  • 5
  • 41
  • 62
woshitom
  • 4,811
  • 8
  • 38
  • 62

2 Answers2

3

You could achieve this by specifying \u0000 as the quote character. Since quoteChar expects a string, you should use this unicode version of NULL.

ROW FORMAT SERDE
    "org.apache.hadoop.hive.serde2.OpenCSVSerde"
WITH SERDEPROPERTIES (
    "separatorChar" = ",",
    "quoteChar" = "\u0000")

This unicode NULL \u0000 is what used by the CSV writer class as value for NO_QUOTE_CHARACTER: http://www.java2s.com/Code/Java/Development-Class/AverysimpleCSVwriterreleasedunderacommercialfriendlylicense.htm

Nirmal
  • 9,391
  • 11
  • 57
  • 81
0

For some reason "quoteChar" = "\u0000" didn't work for me as suggested in Nirmal's answer above.

When saving to file without quotes around the fields, I use:

-- saving to file
INSERT OVERWRITE LOCAL DIRECTORY 'file:/home/sidazhou/temp' 
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' 
SELECT *
FROM temp_table
;

PS. I know this isn't what's being asked, which concerns ROW FORMAT SERDE instead of ROW FORMAT DELIMITED FIELDS.

Sida Zhou
  • 3,529
  • 2
  • 33
  • 48