4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Hiveの様にimpalaでパーティションを取れるようにしてみる

Last updated at Posted at 2019-10-16

テーブルのパーティションがdate/hourな複数階層ある場合に、パーティションの状況を確認したいときって無いですか?

例えば、あるテーブルの1日分が溜まったら実行開始したいけど、非同期で完全に疎結合なバッチを組みたいとか。 そこで、対象日にすべての時間パーティションがあればOKとかで判定したなど。

TL;DR

HiveとImpalaでは、SHOW PARTITIONS の仕様が違い、Impalaでは、PARTITIONSでフィルタ出来ない。

実行環境

CDH v5.14

  • hive-1.1.0-cdh5.14.4
  • impalad version 2.11.0-cdh5.14.4

Hiveの場合

Hiveテーブルの場合は、以下のSQLで任意のパーティション以下のパーティションを確認出来ます。

SHOW PARTITIONS log_db.hoge_tbl PARTITION(dt='20191013');

dt=20191013/hour=01
dt=20191013/hour=02
dt=20191013/hour=03
dt=20191013/hour=04
dt=20191013/hour=05
dt=20191013/hour=06
dt=20191013/hour=07
dt=20191013/hour=08
dt=20191013/hour=09
dt=20191013/hour=10
dt=20191013/hour=11
dt=20191013/hour=12
dt=20191013/hour=13
dt=20191013/hour=14
dt=20191013/hour=15
dt=20191013/hour=16
dt=20191013/hour=17
dt=20191013/hour=18
dt=20191013/hour=19
dt=20191013/hour=20
dt=20191013/hour=21
dt=20191013/hour=22
dt=20191013/hour=23

なので、後は、このSQLをbeelineで実行してその結果を使って件数数えるとかする。

Impalaの場合

一方、Impalaの場合はちょっと厄介。

SHOW [RANGE] PARTITIONS [database_name.]table_name

上記の通り、HiveQLの様に PARTITION でフィルタ出来ない。

また、

SHOW FILES IN [database_name.]table_name [PARTITION (key_col_expression [, key_col_expression]]

の様にすれば PARTITION でフィルタ出来るものの、指定したパーティション以下のすべてのファイルを出力してしまうので、同じ結果にならない(子階層のパーティションだけ出せない)。

そこで、impala-shellを使ってワンライナーで解決

impala-shell --quiet -i impala-host -Q "request_pool=root" -r -V -q "show partitions log_db.hoge_tbl;" | grep "dt=20191013" | grep -o dt=[0-9]*/hour=[0-2][0-9] | sort | uniq

まとめ

HiveとImpalaでは、 SHOW PARTITIONS の仕様が違う。
Impalaは、PARTITIONSで任意の子パーティション以下をフィルタして参照出来ない。

補足

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?