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
4

2 回答 2

3

您可以通过指定\u0000为引号字符来实现此目的。由于quoteChar需要一个字符串,因此您应该使用NULL.

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

这个 unicode NULL\u0000CSV writer该类用作的值NO_QUOTE_CHARACTERhttp ://www.java2s.com/Code/Java/Development-Class/AverysimpleCSVwriterreleasedunderacommercialfriendlylicense.htm

于 2016-09-12T07:15:46.070 回答
0

出于某种原因,正如上面 Nirmal 的回答"quoteChar" = "\u0000"中所建议的那样,它对我不起作用。

在字段周围不带引号的情况下保存到文件时,我使用:

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

PS。我知道这不是要问的,而是关心ROW FORMAT SERDE而不是ROW FORMAT DELIMITED FIELDS.

于 2018-02-02T09:27:34.340 回答