hive-0.14.0以后版本内置支持CSV Serde,以前的版本需要引入第三方库的jar包
引入第三方库
add jar /xx/yy/zz.jar;
csv
DROP TABLE `hr`.`table_xxx`;
CREATE TABLE `hr`.`table_xxx` (brand string,province string,ratio string)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
WITH SERDEPROPERTIES (
"separatorChar" = ",",
"quoteChar" = "'",
"escapeChar" = "\\"
)
STORED AS TEXTFILE;
--导入hdfs文件
load data inpath '/xx/yy/zz.csv' into table table_xxx;
TSV
DROP TABLE hr.table_xxx;
CREATE TABLE hr.table_xxx(member_num string, has_child string,has_old string,cluster_id string)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
WITH SERDEPROPERTIES (
"separatorChar" = "\t",
"quoteChar" = "'",
"escapeChar" = "\\"
)
STORED AS TEXTFILE;
--导入hdfs文件
load data inpath '/xx/yy/zz.tsv' into table hr.table_xxx;
separatorChar:字段之间的分隔符
quoteChar:包括字段的符号,比如单引号、双引号
escapeChar:不处理的字符