メッセージが発生したときに、Hive CLI から stderr にメッセージをフラッシュできるかどうか疑問に思っていました。現在、私は多段階クエリを実行しようとしています (実際のサンプルではありません):
SELECT COUNT(*) FROM (
SELECT user from users
where datetime = 05-10-2013
UNION ALL
SELECT user from users
where datetime = 05-10-2013
) a
これにより 3 つのジョブが起動されますが、ジョブ 1 が強制終了されたために失敗した場合、ジョブ 2 を実行したくありません。エラーを返します。
def execute_hive_query(query):
return_code = None
cmd = ["hive", "-e", query]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while return_code is None:
out = proc.stdout.read()
error = proc.stderr.read()
handle_hive_exception(out,error)
time.sleep(10)
return_code = proc.poll()
def handle_hive_exception(stdout,stderr):
if stderr != '':
raise Exception(stderr)
ありがとう!