1. 程式人生 > >hive使用技巧:使用MSCK匯入輸入到hive表

hive使用技巧:使用MSCK匯入輸入到hive表

1.使用MSCK命令匯入輸入到hive表

假設建立一個外部表,這個表在hdfs的order資料夾裡,但是這個資料夾現在是空的。所以用select * 是沒有資料的。

CREATE EXTERNAL TABLE order(
    order STRING
  , time  STRING
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
LOCATION '/hive/order';

我們通過hdfs dfs -put 方式把資料匯入到hdfs的order 資料夾下。

然後在hive裡面輸入命令 msck repair table order;

現在再select * 就有資料了。通過這種方式,可以很快匯入資料到表格裡面,而不用一個個alter ...add partition來匯入。

2.使用describe formatted order_creates;可以查看錶具體資訊,包括位置,分隔符等。formatted不寫就看簡單點的。

3.關閉動態分割槽模式

 如果insert語句報錯的時候Dynamic partition strict mode requires at least one static partition column. To turn this off set hive.exec.dynamic.partition.mode=nonstrict

可以先進行如下設定在操作。set hive.exec.dynamic.partition.mode=nonstrict;

有關動態分割槽表模式


    hive.exec.dynamic.partition=false  #預設不允許動態分割槽表
    hive.exec.dynamic.partition.mode=strict #設定動態分割槽模式
    hive.exec.max.dynamic.partitions.pernode=100  #動態分割槽在每個map、reducer裡面建立數量
    hive.exec.max.dynamic.partitions=1000         #動態分割槽被建立總數
    hive.exec.max.created.files=100000 #所有mapper建立最大HDFS檔案數           
    hive.error.on.empty.partition=false