Python 不存在表的luigi目标

Python 不存在表的luigi目标,python,hadoop,hive,scheduler,Python,Hadoop,Hive,Scheduler,我正在尝试使用luigi.hive.HiveTableTarget为luigi任务设置一个简单的表存在性测试 我在hive中创建了一个简单的表,以确保它在那里: create table test_table (a int); 接下来,我用luigi设置目标: from luigi.hive import HiveTableTarget target = HiveTableTarget(table='test_table') >>> target.exists() True

我正在尝试使用
luigi.hive.HiveTableTarget为luigi任务设置一个简单的表存在性测试

我在hive中创建了一个简单的表,以确保它在那里:

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行,在
文件“/usr/lib/python2.6/site packages/luigi/hive.py”,第344行,存在于
返回self.client.table_存在(self.table,self.database)
文件“/usr/lib/python2.6/site packages/luigi/hive.py”,第117行,在表2中存在
stdout=run\u hive\u cmd('use{0};description{1}'。格式(数据库、表))
文件“/usr/lib/python2.6/site packages/luigi/hive.py”,第62行,在run\u hive\u cmd中
返回运行配置单元(['-e',hivecmd],检查返回代码)
文件“/usr/lib/python2.6/site packages/luigi/hive.py”,第56行,在run\u配置单元中
标准输出,标准输出)
luigi.hive.hiveCommand错误:('hive命令:hive-e使用默认值;在此处描述测试表
失败,错误代码:17','',\n使用中的配置初始化日志
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\n占用时间:0.822秒\n失败:
SemanticException[错误10001]:找不到表测试\u表\u不在这里\n')
为清晰起见,编辑了格式


我不明白例外的最后一行。当然,没有找到表,这就是存在性检查的全部要点。这是预期的行为还是我需要解决一些配置问题?

好的,所以看起来这可能是最新标记版本(1.0.19)中的一个错误,但在主分支上已修复。负责的代码如下所示:

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

如果您想要一个不必更新到主分支的解决方案,您可以用最少的努力创建自己的目标类:

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
这将产生所需的输出