hdfs需上传csv文件时hive表的DDL设计

This SerDe works for most CSV data, but does not handle embedded newlines. To use the SerDe, specify the fully qualified class name org.apache.hadoop.hive.serde2.OpenCSVSerde.  

Documentation is based on original documentation at https://github.com/ogrodnek/csv-serde.

Create table, specify CSV properties

CREATE TABLE my_table(a string, b string, ...)

ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'

WITH SERDEPROPERTIES (

   "separatorChar" "\t",

   "quoteChar"     "'",

   "escapeChar"    "\\"

)  

STORED AS TEXTFILE;

Default separator, quote, and escape characters if unspecified

DEFAULT_ESCAPE_CHARACTER \

DEFAULT_QUOTE_CHARACTER  "

DEFAULT_SEPARATOR        ,

For general information about SerDes, see Hive SerDe in the Developer Guide. Also see SerDe for details about input and output processing.

Versions

The CSVSerde has been built and tested against Hive 0.14 and later, and uses Open-CSV 2.3 which is bundled with the Hive distribution.

Hive Versions

Open-CSV Version

Hive 0.14 and later2.3

当我们上传csv文件到hdfs上时,如果hive表以此SerDe建表,可以识别正常的csv文件,比如csv文件内出现有逗号的字符串,是会用引号包括起来,类似"abc,12331",这样的数据hive表可以识别成一个整体,但是如果内容中有出现换行符需要先处理才能正常导入。

此SerDe默认的分隔符为 , 引号为 " 转义字符 \

CREATE TABLE my_table(a string, b string, ...)

ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'

WITH SERDEPROPERTIES (

   "separatorChar" = "\t",

   "quoteChar"     = "'",

   "escapeChar"    = "\\"

)  

STORED AS TEXTFILE;

   separatorChar:分隔符

   quoteChar:引号符

   escapeChar:转义字符
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值