CR
EA
TE TABLE escape (id STRING, name STRING)
ROW FORMAT DELIM IT ED FIELDS TERMINATED BY '"';
LOAD DATA LOCAL INPATH '/home/tianzhao/book/escape.txt'
OVERWRITE INTO TABLE escape;
escape.txt的 内容 是:
Joe"2\"3333
Hank"2\"3333
表没有转义,那么两个“都会当作字段分隔符,查询结果是:
select * from escape;
Joe 2\
Hank 2\
ALTER TABLE escape SET SERDE PR OPERTIES ('escape.delim' = '\\'); 给表加上了转义字符\,\后面的字符会被转义,直接跳过,如果是分隔符不会被当作分隔符。查询结果是:
select * from escape;
Joe 2"3333
Hank 2"3333
CREATE TABLE escape2 (id STRING, name STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '"';
LOAD DATA LOCAL INPATH '/home/tianzhao/book/escape2.txt'
OVERWRITE INTO TABLE escape2;
escape2.txt 的内容是:
Joe"2"3333"44
Hank"2"3333"44
实际 数据 比表的字段要多。
select * from escape2;
Joe 2
Hank 2
ALTER TABLE escape2 SET SERDEPROPERTIES ('serialization.last.column.takes.rest' = 'true');
serialization.last.column.takes.rest 的意思是最后一个字段的内容是否包含那些多余的数据:
select * from escape2;
Joe 2"3333"44
Hank 2"3333"44
ROW FORMAT DELIM IT ED FIELDS TERMINATED BY '"';
LOAD DATA LOCAL INPATH '/home/tianzhao/book/escape.txt'
OVERWRITE INTO TABLE escape;
escape.txt的 内容 是:
Joe"2\"3333
Hank"2\"3333
表没有转义,那么两个“都会当作字段分隔符,查询结果是:
select * from escape;
Joe 2\
Hank 2\
ALTER TABLE escape SET SERDE PR OPERTIES ('escape.delim' = '\\'); 给表加上了转义字符\,\后面的字符会被转义,直接跳过,如果是分隔符不会被当作分隔符。查询结果是:
select * from escape;
Joe 2"3333
Hank 2"3333
CREATE TABLE escape2 (id STRING, name STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '"';
LOAD DATA LOCAL INPATH '/home/tianzhao/book/escape2.txt'
OVERWRITE INTO TABLE escape2;
escape2.txt 的内容是:
Joe"2"3333"44
Hank"2"3333"44
实际 数据 比表的字段要多。
select * from escape2;
Joe 2
Hank 2
ALTER TABLE escape2 SET SERDEPROPERTIES ('serialization.last.column.takes.rest' = 'true');
serialization.last.column.takes.rest 的意思是最后一个字段的内容是否包含那些多余的数据:
select * from escape2;
Joe 2"3333"44
Hank 2"3333"44