【问题标题】:Read CSV file in Hive 0.13 without quotes and comma in data as well在 Hive 0.13 中读取 CSV 文件,数据中也没有引号和逗号
【发布时间】:2017-02-13 23:07:30
【问题描述】:

当数据本身包含逗号并且字段没有引号字符时,如何在 Hive 版本 0.13 中读取逗号分隔文件。例子 fname,lname,country, city, addr, dob 是列名,

tom, kate, USA,CA,los angeles,34 brad street 5thfloor, Jun/23/1975
russel,smith,USA, Tx, 763, grass street, 5th floor, dallas, Jan/31/1999 

第一行的数据中没有任何带逗号的列 地址字段中的第二行数据中有逗号 达拉斯草地街 5 楼 763 号

如何在 hive 0.13 版本中阅读此内容

谢谢 MX

【问题讨论】:

  • 它应该被正确地格式化为“FORMAT DELIMITED FIELDS”,否则它将不起作用。

标签: sql regex csv hive cloudera


【解决方案1】:

假设 addr 是唯一可能包含逗号的字段

create external table mydata
(
    fname       string
   ,lname       string
   ,country     string
   ,city        string
   ,addr        string
   ,dob         string
)
row format serde 'org.apache.hadoop.hive.serde2.RegexSerDe'
with serdeproperties ("input.regex" = "(.*?),(.*?),(.*?),(.*?),(.*),(.*)")
location '/user/hive/warehouse/mydata'
;

select * from mydata;

+--------------+--------------+----------------+-------------+--------------------------------------+-------------+
| mydata.fname | mydata.lname | mydata.country | mydata.city | mydata.addr                          | mydata.dob  |
+--------------+--------------+----------------+-------------+--------------------------------------+-------------+
| tom          | kate         | USA            | CA          | los angeles,34 brad street 5thfloor  | Jun/23/1975 |
+--------------+--------------+----------------+-------------+--------------------------------------+-------------+
| russel       | smith        | USA            | Tx          | 763, grass street, 5th floor, dallas | Jan/31/1999 |
+--------------+--------------+----------------+-------------+--------------------------------------+-------------+

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-28
    • 1970-01-01
    • 2017-09-28
    • 1970-01-01
    • 2019-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多