2014-07-13 47 views
0

我有一个CSV文件这样的:HIVE - quoteChar SERDE不起作用

“” 9998 “”, “” 714144 “”, “” frwiki-20131107-页面-元历史2。 xml“”;“”Ripchip Bot“” “”10000“”;“”195090“”;“”frwiki-20131107-pages-meta-history2.xml“”“;”“TXiKiBoT”“ ”“10002” “;” “265154” “” “frwiki-20131107-页面-元history2.xml” “” “Jimmy44””

我尝试创建一个外部表吧:

CREATE EXTERNAL TABLE titi(username string,id int, revisionid int, fileName string) row format serde 'com.bizo.hive.serde.csv.CSVSerde' 
    with serdeproperties("separatorChar" = "\;" 
    , "quoteChar" = "\"\"") 
    stored as textfile 
    LOCATION '/contributor'; 

但作为一个结果,我已经:

hive> select * from titi limit 10; 
OK 
��"9998""  ""714144""  ""frwiki-20131107-pages-meta-history2.xml""  ""Ripchip Bot"" 
     NULL NULL NULL 
"10000""  ""195090""  ""frwiki-20131107-pages-meta-history2.xml""  ""TXiKiBoT"" 
     NULL NULL NULL 
"10002""  ""265154""  ""frwiki-20131107-pages-meta-history2.xml""  ""Jimmy44"" 
     NULL NULL NULL 
"10004""  """" ""frwiki-20131107-pages-meta-history2.xml""  """" 
     NULL NULL NULL 
"10006""  ""1046395""  ""frwiki-20131107-pages-meta-history2.xml""  ""LoveBot"" 
     NULL NULL NULL 

我错了我的表的创建语法?

+0

你想让输出看起来像什么? – gobrewers14

+0

与结果相同,但没有引用。 –

回答

0

我已经复制您的问题,并可以确认它。

但在我看来,塞尔德按预期工作,并不能帮助你在那种情况下。由于quoteChar接受一个字符而不是一个字符串,它设法删除一个双引号,而不是第二个。

如果能够将一个字符串,而不是一个字符作为参数,那么你可以用它去除你的双引号。

我认为你将不得不使用Regex Serde来加载你的文件(see an example here),或者直接在Hive中进行清理后加载。

编辑:我刚刚开了票in GitHub在这个问题上

编辑2:我必须使用正则表达式SERDE的解决方案,而不是你会看到今天的最美丽的东西,但它的工作原理(只要你不必在你的字符串双引号):

CREATE TABLE titi (
    field1 STRING, 
    field2 STRING, 
    field3 STRING, 
    field4 STRING 
) 
ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe' 
WITH SERDEPROPERTIES (
"input.regex" = "\"\"([^\"]*)\"\"\;\"\"([^\"]*)\"\"\;\"\"([^\"]*)\"\"\;\"\"([^\"]*)\"\"", 
"output.format.string" = "%1$s %2$s %3$s %4$s" 
) 
STORED AS TEXTFILE; 

它使用正则表达式如下(不逃逸卡拉科特): “”([^ “] )” “” “([^”])“”;“”([^“] )”“;”“([^”])“”