hive建表时对字段间分割符的限制

1、数据文件中,每一行的字段用@$_$@来区分,于是测试数据可以这样:

1<span style="font-size:24px;">@$_$@</span>xu<span style="font-size:24px;">@$_$@</span>30<span style="font-size:24px;">@$_$@</span>student

2、创建表的语句

CREATE EXTERNAL TABLE user_table (userid string,username string,age string,title string ) row format delimited  fields terminated by '@$_$@';

3、导入测试数据

load data local inpath /home/hadoop/xuguokun/test.txt into table user_table;

4、查看数据

hive> select * from user_table;
OK
1	$_$	xu	$_$
Time taken: 0.146 seconds, Fetched: 1 row(s)

5、结果不像预期的那样,显然是不正确的。


6、调整字段之间的分割符,并创建新表

CREATE EXTERNAL TABLE student_table (userid string,username string,age string,title string ) row format delimited  fields terminated by ',';

7、导入测试数据

load data local inpath /home/hadoop/xuguokun/test.txt into table student_table;

8、查看数据

hive> select * from student_table;
OK
1	xu	30	student
Time taken: 0.172 seconds, Fetched: 1 row(s)


9、怎么一回事呢?


10、调整字段之间的分割符,并创建新表

<span style="font-size:24px;">CREATE EXTERNAL TABLE teacher_table (userid string,username string,age string,title string ) row format delimited  fields terminated by ',,';</span>


11、 导入测试数据

<span style="font-size:24px;">load data local inpath /home/hadoop/xuguokun/test.txt into table </span><pre name="code" class="java"><span style="font-size: 24px;">teacher_table</span><span style="font-size: 24px; font-family: Arial, Helvetica, sans-serif;">;</span>

12、查看结果

hive> select * from teacher_table;
OK
1		xu	
Time taken: 0.111 seconds, Fetched: 1 row(s)

13、最终原因没能确定,难道是分隔符不能是多个字符的组合?


版权声明:本文为xuguokun1986原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。