2015-06-20 96 views
0

我有兩個Hive表,其中一個包含Timestamp數據類型的日期值。如果我使用該鍵在一個特定記錄上查詢,它會正確顯示日期值。 從表1中選擇acct_key,account_open_date,其中acct_key = 1234;加入兩個表後的Hive時間戳值更改

acct_id account_open_date 
1234  1963-03-01 00:00:00 

但是與另一個表加入這個表時,返回的時間戳值2031 選擇a.acct_key,b.account_open_date 從TABLE_2換到價值在一年TABLE_1左外JOIN B 上。 acct_key = b.acct_key;

acct_id account_open_date 
1234  2031-03-19 00:00:00 

似乎這個問題只發生在Unix紀元時間(1970年)之前的日期值。任何建議?謝謝

回答

0

這裏有兩個問題,第一件事加入不與時間戳和時代時間戳工作。用你的最後一行,我假設連接正在爲其他時間戳返回正確的時間戳。糾正我,如果我錯了。因此,如果這是解決了,你可以看看here處理劃時代時間

0

我無法重現您所看到的,但仍然,你可以嘗試鑄造account_open_datestring

select a.acct_id 
    , b.new 
    , other_columns 
from db.table1 
left outer join (
    select * 
    , cast(account_open_date as string) new 
    from db.table2) b 
on a.acct_id=b.acct_id 
+0

感謝您的建議。想知道不是使用嵌套查詢,我可以直接將其轉換爲如下所示的字符串。這兩者有什麼區別?選擇a.acct_id ,cast(b.account_open_date as字符串)新的 ,other_columns from db.table1 a, left outer join db.table 2 b on a.acct_id = b.acct_id; –

+0

如上所述,我無法重現您所看到的內容,但我在'join'期間以某種方式假設時間戳列被更改。所以我做了'cast'然後'join'。如果這是你所擔心的,我認爲不會有太大的性能差異。 – gobrewers14

0

我試過了。在嵌套查詢中將時間戳記投射爲String,其工作方式如下。我也試過沒有嵌套查詢,但那不起作用。有人知道爲什麼

沒有工作版本:

選擇a.acct_id,澆鑄(b.account_open_date作爲字符串)新,從db.table1一個other_columns,左外連接db.table 2 B上a.acct_id = b.acct_id ;

工作版本:

選擇a.acct_id ,b.new ,other_columns 從db.table1 左外連接( 選擇* ,投(account_open_date作爲字符串)新 從db.table2 )b on a.acct_id = b.acct_id