2019년 1월 9일 수요일

ppc64le Redhat 서버에서 x86 hadoop cluster에 대해 PyHive로 query 수행하기

지난 포스팅에 이어 이번에는  x86 hadoop cluster에 대해 ppc64le Redhat 서버에서 PyHive를 이용하여 query를 수행하는 방법을 정리했습니다. 

이 방법의 장점은 ppc64le 서버에 hadoop이나 hive 등을 설치하지 않아도 된다는 것이고, 나쁜 점은 PyHive를 설치해야 한다는 점입니다.  PyHive를 설치하기 위해서는 (언제나 그렇듯이) 인터넷이 연결되어 있거나 사내에 private repository가 구성되어 있어야 합니다.

먼저, PyHive 설치를 위해서 cyrus-sasl-devel을 yum 명령으로 설치합니다.

[bsyu@redhat74 ~]$ sudo yum install cyrus-sasl-devel

이걸 미리 설치하지 않으면 pip로 sasl 설치할 때 아래와 같은 error 발생하므로 꼭 설치하셔야 합니다.
   sasl/saslwrapper.h:22:10: fatal error: sasl/sasl.h: No such file or directory
   #include <sasl/sasl.h>
            ^~~~~~~~~~~~~
  compilation terminated.
  error: command 'gcc' failed with exit status 1

이어서 pip로 필요 python package들을 설치합니다.

[bsyu@redhat74 ~]$ pip install sasl thrift thrift-sasl PyHive
...
Installing collected packages: thrift-sasl, future, PyHive
Successfully installed sasl-0.2.1 PyHive-0.6.1 future-0.17.1 thrift-sasl-0.3.0

이제 python(여기서는 python2를 씁니다)으로 다음과 같이 pyhive로 query를 날려봅니다.   (여기서 10.10.14.71이 hive 서버입니다.)

[bsyu@redhat74 ~]$ python
Python 2.7.15 |Anaconda, Inc.| (default, May  1 2018, 23:32:32)
[GCC 7.2.0] on linux2

>>> from pyhive import hive
>>> conn = hive.Connection(host="10.10.14.71", port=10000, username="hive", database="default")
>>> cursor = conn.cursor()
>>> cursor.execute("SELECT * FROM pokes")
>>> cursor.fetchall()
[(u'1 ', u'"i love donut"'), (u'2 ', u'you love pretzel'), (u'3 ', u'"she loves bagel"'), (u'1 ', u'"i love donut"'), (u'2 ', u'you love pretzel'), (u'3 ', u'"she loves bagel"'), (u'1 ', u'"i love donut"'), (u'2 ', u'you love pretzel'), (u'3 ', u'"she loves bagel"')]

지난번 포스팅의 hive나 beeline에서처럼 예쁘게 정리되어 나오지는 않지만 분명히 제대로 data를 다 가져오는 것을 보실 수 있습니다.

그런데 문제가 하나 있습니다.  원래 이 PyHive는 python2만 지원합니다.  그래서 python3를 사용하셔야 하는 경우 다음과 같은 error가 발생하게 됩니다.

>>> cursor.execute("select * from pokes", conn)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/bsyu/anaconda3/lib/python3.7/site-packages/pyhive/hive.py", line 354, in execute
    sql = operation % _escaper.escape_args(parameters)
  File "/home/bsyu/anaconda3/lib/python3.7/site-packages/pyhive/common.py", line 210, in escape_args
    raise exc.ProgrammingError("Unsupported param format: {}".format(parameters))
pyhive.exc.ProgrammingError: Unsupported param format: <pyhive.hive.Connection object at 0x3fff7dc86630>

이걸 해결하는 방법이 또 있습니다 !  아래 URL에 나온 방법입니다만, x86 Cloudera cluster의 hive 서버의 hive-site.xml에 다음과 같이 NOSASL property를 추가하면 됩니다.

https://community.hortonworks.com/questions/107481/how-to-enable-a-pyhive-connection-with-python-35-s.html

[root@powervc131 ~]# vi /etc/hive/conf.dist/hive-site.xml
...
<property>
  <name>hive.server2.authentication</name>
  <value>NOSASL</value>
</property>

이걸 수정하고 나서 x86 Cloudera cluster를 재구동하거나 할 필요는 없고, 단지 ppc64le 서버에서 python 세션만 다시 시작하시면 됩니다.   다음과 같이 python3에서도 data를 잘 가져오는 것을 보실 수 있습니다.

[bsyu@redhat74 files]$ python
Python 3.7.0 (default, Jun 28 2018, 13:02:24)
[GCC 7.2.0] :: Anaconda, Inc. on linux

>>> from pyhive import hive
>>> conn = hive.Connection(host="10.10.14.71", port=10000, username="hive", database="default")
>>> cursor = conn.cursor()
>>> cursor.execute("SELECT * FROM pokes")
>>> cursor.fetchall()
[('1 ', '"i love donut"'), ('2 ', 'you love pretzel'), ('3 ', '"she loves bagel"'), ('1 ', '"i love donut"'), ('2 ', 'you love pretzel'), ('3 ', '"she loves bagel"'), ('1 ', '"i love donut"'), ('2 ', 'you love pretzel'), ('3 ', '"she loves bagel"')]

댓글 없음:

댓글 쓰기