hive 运行impala-shell从木星笔记本

jmp7cifd  于 2023-10-18  发布在  Hive
关注(0)|答案(1)|浏览(159)

我正在尝试运行impala从jupyter-notebook如下--

  1. from impala.dbapi import connect
  2. conn = connect(host='xx-xx-xx.xx.com',
  3. port=21000,
  4. auth_mechanism="PLAIN",
  5. user='xxxx',
  6. password='xxxx',
  7. )
  8. cursor = conn.cursor()

但我得到了这个错误

  1. TTransportException Traceback (most recent call last)
  2. <ipython-input-28-6c858acffc1b> in <module>
  3. .
  4. .
  5. TTransportException: Bad status: 3 (b'Unsupported mechanism type PLAIN')

在尝试了许多不起作用的东西后,我想运行impala命令作为python subprocess.run,但我没有得到输出(返回代码1)--

  1. r = subprocess.run(['impala-shell', '-q', "select xxx...xxx"],
  2. stdout=subprocess.PIPE)
  3. print(r.stdout.decode()) # returncode=1

另外,jupyter中的!impala-shell给出了此错误

  1. File "/opt/xxxx/xxxx/xxxx/impala-shell/impala_shell.py", line 262
  2. print "Query options (defaults shown in []):"
  3. ^
  4. SyntaxError: invalid syntax

谁能告诉我这个问题,并指导我如何解决这个问题?

fykwrbwg

fykwrbwg1#

这是因为Python版本。
Impala与python 2.7.5版本兼容,你很可能会使用python 3或更高版本。
为了解决这个问题

  • 要么你可以降级你的python,
  • 或者可以使用Python 2创建一个虚拟环境,并从该虚拟环境中运行impala。

要创建虚拟环境,请执行以下步骤:

  1. virtualenv venv -p python2
  2. cd venv
  3. source bin/activate
  4. (venv) impala-shell

相关问题