【问题标题】:hive query csv Text-delimiter issue蜂巢查询 csv 文本分隔符问题
【发布时间】:2016-03-31 06:18:11
【问题描述】:

尝试在配置单元中导入低于data

姓名、电话、地址

Arverne,(718) 634-4784,"*312 Beach 54 Street 
Arverne, NY 11692
(40.59428994144626, -73.78442865540268)*"

Astoria,(718) 278-2220,"*14 01 Astoria Boulevard
Long Island City, NY 11102
(40.77152402451418, -73.92643545073543)*"

Auburndale,(718) 352-2027,"*25 55 Francis Lewis Boulevard
Flushing, NY 11358
(40.76035096822195, -73.79632645819947)*"

但是地址不正确,因此损坏了表数据 我猜想行终止的问题(默认情况下采用 \n,因为地址是 3-4 行),因为当我在示例数据下方运行时

a,b,"e,f"

x,y,"l,m"

以下查询

create table test(c1 string, c2 string, c3 string)
row format serde 'com.bizo.hive.serde.csv.CSVSerde'
with serdeproperties(
"separatorChar" = ",");

它工作正常:

test.c1 test.c2 test.c3

a   b   c,d

e   f   g,z

我该如何做到这一点?

【问题讨论】:

    标签: hadoop hive delimiter


    【解决方案1】:

    这就是我的工作方式。

    >>> CREATE TABLE Test(name string, phone string, address string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE;
    >>> load data inpath 'file.csv' into table Test;
    
    >>>  select name from hiveTest;
    +-------------+--+
    |    name     |
    +-------------+--+
    | Arverne     |
    | Astoria     |
    | Auburndale  |
    +-------------+--+
    >>> select address from hiveTest;
    +--------------------------------------------+--+
    |                  address                   |
    +--------------------------------------------+--+
    | "312 Beach 54 Street Arverne               |
    | "14 01 Astoria Boulevard Long Island City  |
    | "25 55 Francis Lewis Boulevard Flushing    |
    +--------------------------------------------+--+
    

    我想这会有所帮助。

    【讨论】:

    • 地址被截断。它应该是“312 Beach 54 Street Arverne, NY 11692 (40.59428994144626, -73.78442865540268)”
    • 试试这个:create table my_table(name string, phone string, address string) row format serde 'com.bizo.hive.serde.csv.CSVSerde' with serdeproperties ("separatorChar" ="\t ", "quoteChar" = "'", "escapeChar" = "\\") 存储为文本文件;根据要求更改 serdeproperties。
    • 已经尝试过使用这些选项 ("separatorChar" =",", "quoteChar" = "\"", "escapeChar" = "\n") ....再次不起作用..你可以从这个链接获取实际数据:nycopendata.socrata.com/Recreation/Queens-Library-Branches/…?
    • 试试这个。成功了:stackoverflow.com/questions/28049674/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-22
    相关资源
    最近更新 更多