如何避免线内脱粒

dced5bon  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(242)

首先,请原谅,如果这个问题是非常正常的,我是非常新的Hive和尝试我的手上。我需要在逗号(',')分隔符的帮助下将数据插入表列,下面是一个示例条目:
列标题: Name,status,location 样本数据: Arverne,closed,"312 Beach 54 Street Arverne,NY 11692 (40.59428994144626, -73.78442865540268)" 问题是当我尝试以“,”结尾的字段作为位置时,只能获取“312 beach 54 street arverne,ny 11692(40.59428994144626,-73.78442865540268)

create table library(name string,Location string) row format delimited
 fields terminated by ','  stored as TextFile;
tcomlyy6

tcomlyy61#

1.

tblproperty('serialization.last.column.takes.rest'='true')

create external table library (Name string,status string,location string)
row format delimited
fields terminated by ','
tblproperties ('serialization.last.column.takes.rest'='true')    
;
select * from library
;
+---------+--------+---------------------------------------------------------------------------------+
|  name   | status |                                    location                                     |
+---------+--------+---------------------------------------------------------------------------------+
| Arverne | closed | "312 Beach 54 Street Arverne,NY  11692 (40.59428994144626, -73.78442865540268)" |
+---------+--------+---------------------------------------------------------------------------------+

2.

OpenCSV服务器
https://cwiki.apache.org/confluence/display/hive/csv+serde
https://github.com/ogrodnek/csv-serde
默认serde属性

create external table library (Name string,status string,location string)
row format serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
stored as textfile
;
select * from library
;
+---------+--------+-------------------------------------------------------------------------------+
|  name   | status |                                   location                                    |
+---------+--------+-------------------------------------------------------------------------------+
| Arverne | closed | 312 Beach 54 Street Arverne,NY  11692 (40.59428994144626, -73.78442865540268) |
+---------+--------+-------------------------------------------------------------------------------+

显式serde属性

create external table library (Name string,status string,location string)
row format serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
with serdeproperties 
(
    'separatorChar' = ','
   ,'quoteChar'     = '"'
   ,'escapeChar'    = '\\'
)  
stored as textfile
;
select * from library
;
+---------+--------+-------------------------------------------------------------------------------+
|  name   | status |                                   location                                    |
+---------+--------+-------------------------------------------------------------------------------+
| Arverne | closed | 312 Beach 54 Street Arverne,NY  11692 (40.59428994144626, -73.78442865540268) |
+---------+--------+-------------------------------------------------------------------------------+

相关问题