大数据基础之Hive——hive数据清洗过程csv表格字段出现分割符逗号的解决方案
在创建表进行数据清洗的过程中 csv表格字段中可能存在csv表格的分割符号 ,如图此时如果还是按照原来的写法:%hivecreate external table if not exists ext_transaction_details(transaction_id string,customer_id string,store_id string,price string,product st
·
在创建表进行数据清洗的过程中 csv表格字段中可能存在csv表格的分割符号 ,如图
此时如果还是按照原来的写法:
%hive
create external table if not exists ext_transaction_details(
transaction_id string,
customer_id string,
store_id string,
price string,
product string,
`date` string,
time string
)
row format serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
stored as textfile tblproperties("skip.header.line.count"="1")
则会出现字段占用下一字段的情况。
如图
此时就要进行重新建表 并且添加serde这个方法
删表重建:
%hive
create external table if not exists ext_transaction_details(
transaction_id string,
customer_id string,
store_id string,
price string,
product string,
`date` string,
time string
)
row format serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
with serdeproperties (
'separatorChar' = ',',
'quoteChar' = '\"',
'escapeChar' = '\\'
)
stored as textfile tblproperties("skip.header.line.count"="1")
'separatorChar' = ',',
:表示分割符是,'quoteChar' = '\"',
:表示引用符号的 " \是用来转义的'escapeChar' = '\\'
:表示无效字段
这几句话表示分割符号是,但是在引用符号""中间的字段是无效字段不进行,的分割。
此时重新创表查询
%hive
create external table if not exists ext_transaction_details(
transaction_id string,
customer_id string,
store_id string,
price string,
product string,
`date` string,
time string
)
row format serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
with serdeproperties (
'separatorChar' = ',',
'quoteChar' = '\"',
'escapeChar' = '\\'
)
stored as textfile tblproperties("skip.header.line.count"="1")
如图 字段不进行分割 不会再出现占用字段的情况。
更多推荐
所有评论(0)