hive中的null值

thamsyangsw發表於2014-03-27

在hive裡面預設的情況下會使用’/N’來表示null值,但是這樣的表示並不符合我們平時的習慣。
所以需要透過serialization.null.format的設定來修改表的預設的null表示方式。

測試表
hive> select * from sunwg00;
OK
NULL    mary
101     tom
Time taken: 0.058 seconds

建立普通表sunwg01,沒有指定serialization.null.format
hive> CREATE TABLE sunwg01 (id int,name STRING) STORED AS TEXTFILE;
OK
Time taken: 0.04 seconds
hive> insert overwrite table sunwg01 select * from sunwg00;
Loading data to table sunwg01
2 Rows loaded to sunwg01
OK
Time taken: 17.047 seconds

檢視sunwg01在hdfs的檔案
[hjl@sunwg src]$ hadoop fs -cat /hjl/sunwg01/attempt_201105020924_0011_m_000000_0
/Nmary
101tom

NULL值被轉寫成’/N’

建立表sunwg02,指定serialization.null.format

hive> CREATE TABLE sunwg02 (id int,name STRING)
    > ROW FORMAT SERDE ‘org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe’
> WITH SERDEPROPERTIES (
    >  ‘field.delim’='/t’,
    >  ‘escape.delim’='//’,
    >  ‘serialization.null.format’=”
> ) STORED AS TEXTFILE;
OK
Time taken: 0.046 seconds

hive> insert overwrite table sunwg02 select * from sunwg00;
Loading data to table sunwg02
2 Rows loaded to sunwg02
OK
Time taken: 18.756 seconds

檢視sunwg02在hdfs的檔案
[hjl@sunwg src]$ hadoop fs -cat /hjl/sunwg02/attempt_201105020924_0013_m_000000_0
        mary
101     tom

NULL值沒有被轉寫成’/N’,而是空字串。

 

本文轉自

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26613085/viewspace-1130850/,如需轉載,請註明出處,否則將追究法律責任。

相關文章