hive转义字符

末小落 2000-02-16 02:31:01 热度:2888°C

CREATE TABLE escape (id STRING, name STRING)

ROW FORMAT DELIMITED FIELDS TERMINATED BY """;

LOAD DATA LOCAL INPATH "/home/tianzhao/book/escape.txt"

OVERWRITE INTO TABLE escape;

escape.txt的内容是:

Joe"2"3333

hive转义字符

Hank"2"3333

表没有转义,那么两个“都会当作字段分隔符,查询结果是:

select * from escape;

Joe 2

Hank 2

ALTER TABLE escape SET SERDEPROPERTIES ("escape.delim" = ""); 给表加上了转义字符,后面的字符会被转义,直接跳过,如果是分隔符不会被当作分隔符。查询结果是:

select * from escape;

hive转义字符

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 的内容是:

hive转义字符

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

相关阅读
推荐阅读