我正在尝试使用以下方法为luigi任务建立一个简单的表存在测试 luigi.hive.HiveTableTarget
我在蜂巢中创建一个简单的表只是为了确保它在那里:
create table test_table (a int);
接下来,我用luigi设置目标:
from luigi.hive import HiveTableTarget
target = HiveTableTarget(table='test_table')
>>> target.exists()
True
太好了,接下来,我尝试使用一个我不知道的表来确保它返回false。
target = HiveTableTarget(table='test_table_not_here')
>>> target.exists()
并引发一个异常:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/luigi/hive.py", line 344, in exists
return self.client.table_exists(self.table, self.database)
File "/usr/lib/python2.6/site-packages/luigi/hive.py", line 117, in table_exists
stdout = run_hive_cmd('use {0}; describe {1}'.format(database, table))
File "/usr/lib/python2.6/site-packages/luigi/hive.py", line 62, in run_hive_cmd
return run_hive(['-e', hivecmd], check_return_code)
File "/usr/lib/python2.6/site-packages/luigi/hive.py", line 56, in run_hive
stdout, stderr)
luigi.hive.HiveCommandError: ('Hive command: hive -e use default; describe test_table_not_here
failed with error code: 17', '', '\nLogging initialized using configuration in
jar:file:/opt/cloudera/parcels/CDH-5.2.0-1.cdh5.2.0.p0.36/jars/hive-common-0.13.1-
cdh5.2.0.jar!/hive-log4j.properties\nOK\nTime taken: 0.822 seconds\nFAILED:
SemanticException [Error 10001]: Table not found test_table_not_here\n')
编辑格式以便清晰
我不明白该异常的最后一行。当然,找不到该表,这就是存在检查的全部要点。这是预期的行为,还是我需要解决一些配置问题?
好的,看起来这可能是最新的标记发行版(1.0.19)中的错误,但已在master分支上修复。负责的代码是这一行:
stdout = run_hive_cmd('use {0}; describe {1}'.format(database, table))
return not "does not exist" in stdout
在母版中更改为:
stdout = run_hive_cmd('use {0}; show tables like "{1}";'.format(database, table))
return stdout and table in stdout
后者工作正常,而前者抛出HiveCommandError
。
如果您需要解决方案而不必更新到master分支,则可以轻松创建自己的目标类:
from luigi.hive import HiveTableTarget, run_hive_cmd
class MyHiveTarget(HiveTableTarget):
def exists(self):
stdout = run_hive_cmd('use {0}; show tables like "{1}";'.format(self.database, self.table))
return self.table in stdout
这将产生所需的输出。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句