2012-12-17 42 views
1

我創建了一個按日期分區的表。但是不能在where子句中使用分區。 下面是該過程步驟1 :蜂巢。無法引用where子句中的分區

 CREATE TABLE new_table (
      a string, 
      b string 
    ) 
    PARTITIONED BY (dt string); 

第二步:創建

 Insert overwrite table new_table partition (dt=$date) 
     Select a, b from my_table 
     where dt = '$date 

表。

  Describe new_table; 
      a string 
      b string 
      dt string 

問題

  select * from new_table where dt='$date' 

返回空集。

  select * from new_table 

返回一個,b和DT。

有誰知道這可能是什麼原因?

謝謝

+0

如果你運行'SHOW PARTITIONS NEW_TABLE會發生什麼插入;'? – dhore

+0

嘗試過,但無法重現您的問題;做了幾個排列,包括動態分區。正如已經建議的那樣,驗證你的查詢,檢查分區等。 – libjack

+1

我的不好,我在做; > hive -e'select * from new_table其中dt ='$ date'' 和單引號引起了問題。我花了3個小時看到這個:)謝謝你的答案 – sahara

回答

0

撒哈拉,分區where子句做的工作。你有什麼機會在你的謂詞的RHS中指定錯誤的值?

您可能還希望看到/user/hive/warehouse/new_table(默認情況下)中的數據,以查看那裏的數據是否看起來像您期望的那樣。

0

嘗試

Insert overwrite table new_table partition (dt=$date) 
    Select a, b, dt from my_table 
    where dt = '$date'