1. 程式人生 > >hive匯入資料出現NULL

hive匯入資料出現NULL

在把hdfs上資料遷移到hive中的表時,若出現數據位NULL,是因為沒有指定列分隔符。

由於hive預設的分隔符是/u0001(Ctrl+A),為了平滑遷移,需要在建立表格時指定資料的分割符號,語法如下:

hive (default)> create external table et (time BIGINT, userid string, content string, urlrank int, urlnum int, url string)
              > partitioned by (filenum int) 
              > row format delimited fields terminated by '\t'; 

上面建立的是外部表,“匯入”資料時可以用load,但若不想進行移動資料,就用命令alter來進行指向:

alter table et add partition (filenum=1) location '/input/SogouQueryLog/file1';
注意location後面跟的地址必須是個目錄,若不是,可以用hdfs fs -mv src dest 進行移動資料:
hadoop fs -mv /input/SogouQueryLog/querylog_1 /input/SogouQueryLog/file1