Skip to content

Instantly share code, notes, and snippets.

@tamtam180
Created February 11, 2012 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamtam180/1797071 to your computer and use it in GitHub Desktop.
Save tamtam180/1797071 to your computer and use it in GitHub Desktop.
hive ticket draft1
----- 手直ししたバージョン -----
summary:
utc_from_timestamp and utc_to_timestamp returns incorrect results.
detail:
how to reproduce:
{noformat}
$ echo "2011-12-25 09:00:00.123456" > /tmp/data5.txt
hive> create table ts1(t1 timestamp);
hive> load data local inpath '/tmp/data5.txt' overwrite into table ts1;
hvie> select t1, from_utc_timestamp(t1, 'JST'), from_utc_timestamp(t1, 'JST') from ts1 limit 1;
{noformat}
The following result is expected:
2011-12-25 09:00:00.123456 2011-12-25 18:00:00.123456 2011-12-25 18:00:00.123456
However, the above query return incorrect result like this:
2011-12-26 03:00:00.492456 2011-12-26 03:00:00.492456 2011-12-26 03:00:00.492456
This is because GenericUDFFromUtcTimestamp.applyOffset() does setTime() improperly.
On evaluating query, timestamp argument always returns the same instance.
GenericUDFFromUtcTimestamp.applyOffset() does setTime() on the instance.
That means it adds all offsets in the query.
attached is the patch which fixes this issue
----- ここまで -----
----- 最初のバージョン -----
summary:
utc_from_timestamp and utc_to_timestamp returns incorrect results.
detail:
utc_from_timestamp and utc_to_timestamp returns incorrect results.
reproduce a bug
1. ready test data:
>cat /tmp/data5.txt
2011-12-25 09:00:00.123456
2. create table and load:
create table ts1(t1 timestamp);
load data local inpath '/tmp/data5.txt' overwrite into table ts1;
3. execute query:
select
t1,
from_utc_timestamp(t1, 'JST'),
t1,
from_utc_timestamp(t1, 'JST')
from ts1
limit 1;
This query should return:
2011-12-25 09:00:00.123456 2011-12-25 18:00:00.123456 2011-12-25 09:00:00.123456 2011-12-25 18:00:00.123456
but its returned:
2011-12-26 03:00:00.492456 2011-12-26 03:00:00.492456 2011-12-26 03:00:00.492456 2011-12-26 03:00:00.492456
It seems to refer to the same Timestamp object for every column. ~
and set a value to same Timestamp object in GenericUDFFromUtcTimestamp.applyOffset method.
I attached the patch.~
Hope this helps.
http://mt.orz.at/archives/HIVE-xxxx.1.patch.txt (チケットに添付する)
-----
@shiumachi
Copy link

参考までに、「返す値が違う」系のチケットにはこんなのがあります。
https://issues.apache.org/jira/browse/HIVE-1723
https://issues.apache.org/jira/browse/HIVE-72
https://issues.apache.org/jira/browse/HIVE-2782

summary:
多分問題ないと思います

detail:
再現方法は how to reproduce: ぐらいでいいと思います。
{query} ... {query} で囲っておけばより見やすいかと。
参考: https://issues.apache.org/jira/browse/MAPREDUCE-3845

再現方法の中身はもっと簡潔に書いても通じます。

$ echo "2011-12-25 09:00:00.123456" > /tmp/data5.txt
hive> create table ts1(t1 timestamp);
hive> load data local inpath '/tmp/data5.txt' overwrite into table ts1;
hvie> select t1, from_utc_timestamp(t1, 'JST'), t1, from_utc_timestamp(t1, 'JST') from ts1 limit 1;

あと、2つ目の t1 は必要ないと思います。

その次の結果の説明についてはこんか感じでどうでしょう。
The following result is expected:
2011-12-25 09:00:00.123456 2011-12-25 18:00:00.123456 2011-12-25 09:00:00.123456 2011-12-25 18:00:00.123456
However, the above query returns incorrect result like this:
2011-12-26 03:00:00.492456 2011-12-26 03:00:00.492456 2011-12-26 03:00:00.492456 2011-12-26 03:00:00.492456

最後のところは、ブログの文章を正確に訳した方がいいです。
「行を評価中、timestamp変数は同じインスタンスを毎回返してきます。そのインスタンスに対してapplyOffsetでsetTimeしちゃってます。つまり、その行を評価中はt1は同じインスタンスを使い回してしまいます。なのでSELECT句に書いたOffset値全てが計算された結果が出力されるわけです。」
という文章なので、
This is because GenericUDFFromUtcTimestamp.applyOffset() does setTime() improperly.
On evaluating query, timestamp argument always returns the same instance.
GenericUDFFromUtcTimestamp.applyOffset() does setTime() on the instance.
That means it adds all offsets in the query.

ぐらいですかね(ちょっと適当な英語ですけど)

最後は attached is the patch which fixes this issue ぐらいでしょうか。
attached はそのまま「添付したもの」という名詞的な使い方をします。

HTH はいらないような気がします。あれは何か困っている人に対して使うようなニュアンスがある気がするので。
(例えば私が今書いてるこのコメントは、英語なら最後に HTH ってつけてる気がします)
この辺は私も自身がないのでどちらでもいいです。

細かい話ですが、パッチ名は HIVE-xxx.patch あるいは HIVE-xxx.txt で統一した方がいいです。間に番号を入れると日付順にソートしてくれないので観る側がたまに混乱します。
この辺も趣味でいいです。
ちなみに私は txt 形式の方が好きです(ブラウザで直接見れるから)

あと、パッチを投稿する前に trunk バージョンで現象が再現することと、そのパッチを当てたら解決したことを再確認してください。

他にもわからないことがありましたらいつでも聞いてください。

HTH :)

@tamtam180
Copy link
Author

ありがとうございます!本当に助かります。
手直ししてみました。&後でブログにまとめます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment