在创建表进行数据清洗的过程中 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")

在这里插入图片描述
如图 字段不进行分割 不会再出现占用字段的情况。

Logo

永洪科技,致力于打造全球领先的数据技术厂商,具备从数据应用方案咨询、BI、AIGC智能分析、数字孪生、数据资产、数据治理、数据实施的端到端大数据价值服务能力。

更多推荐