hive null

逸卿發表於2014-11-24

from:http://blog.csdn.net/yfkiss/article/details/7943053


hive中NULL預設是以'\N'表示的
示例:
建表:
hive> create table null_test_1(id INT, name STRING) 
    > ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';

OK
Time taken: 0.275 seconds
插入資料:
$ cat /home/work/data/null_test.txt 
1       2
1       \N
1       3
hive> load data local inpath '/home/work/data/null_test.txt' into  table null_test_1;
Copying data from file:/home/work/data/null_test.txt
Copying file: file:/home/work/data/null_test.txt
Loading data to table default.null_test_1
OK
Time taken: 0.384 seconds
檢視資料:
hive> select * from null_test_1 ;
OK
1       2
1       NULL
1       3
hive> select * from null_test_1 where name is not null;
Total MapReduce jobs = 1
......
OK
1       2
1       3
Time taken: 32.729 seconds

可以通過ALTER TABLE table_name SET SERDEPROPERTIES('serialization.null.format' = '');修改空值描述符
示例:
hive> ALTER TABLE null_test_1 SET SERDEPROPERTIES('serialization.null.format' = '');
OK
Time taken: 0.137 seconds
hive> select * from null_test_1 where name is not null;
Total MapReduce jobs = 1
......
OK
1       2
1       \N
1       3
Time taken: 21.754 seconds

hive中分割槽欄位如果為NULL需注意
使用dynamic partition,如果分割槽欄位為NULL,資料會放到一個特殊的分割槽,這個分割槽由引數“hive.exec.default.partition.name”控制,預設為“__HIVE_DEFAULT_PARTITION__”。

相關文章