Skip to content

Instantly share code, notes, and snippets.

@wyukawa
Created July 9, 2012 06:48
Show Gist options
  • Save wyukawa/3074672 to your computer and use it in GitHub Desktop.
Save wyukawa/3074672 to your computer and use it in GitHub Desktop.
サブクエリで書いた方が良いクエリ
from (
select
...
from
aaa a
left outer join
bbb b
on
a.id=b.id
and
a.partition_key=b.partition_key
and
a.partition_key=123
and
b.partition_key=123
)tab
insert overwrite table ccc partition ( partition_key )
select
tab...
とするとテーブルaaaのパーティション数が多い場合に非常に時間がかかる。
パーティションキーであるpartition_keyで絞り込めてない感じ。
idは結合キー
ジョブのログを見ると
aaaのパーティション数分だけ
INFO org.apache.hadoop.hive.ql.exec.MapOperator: Adding alias ... work list for file ...
が出ている。
INFO org.apache.hadoop.mapred.MapTask: Spilling map output: record full = true
もいっぱい出ている。
ジョブのmap数, reduce数は少ないのにテーブルaaaの全パーティション見てそう。
from (
select
...
from
(select ... from aaa where partition_key = 123) a
left outer join
bbb b
on
a.id=b.id
and
a.partition_key=b.partition_key
and
a.partition_key=123
and
b.partition_key=123
)tab
insert overwrite table ccc partition ( partition_key )
select
tab...
とサブクエリで書けば大丈夫
やや不思議なのは上記2つのクエリを実行した場合のmap数とreduce数は変わらない。ただ上のクエリを実行するとmap処理で異常に時間がかかる。処理が終わるかどうかは未確認。
バージョンはCDH3u0同梱のHive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment