Pyhive로 python-hive 연결(install sasl 해결)

설치할 라이브러리는 아래와 같다.

# OS에 sasl 설치
yum install libsasl2-dev

# 파이썬 패키지 설치
pip install sasl
pip install thrift
pip install thrift-sasl
pip install PyHive

library들을 설치하던 중 sasl 설치에서 문제가 생겼다.

sasl이 pip으로 설치가 되지 않는다.

sasl은 버전별로 지원하는 library가 다르다. 현재는 python3.7까지만 지원한다. 때문에 https://www.lfd.uci.edu/~gohlke/pythonlibs/#sasl 다음 링크에서 각 버전에 맞는 whl 파일을 받아서 설치해준다.

(후에 바뀌면 계속 업데이트 할 예정)

python 코드는 아래와 같다.

# 연결
from pyhive import hive
conn = hive.Connection(host="hive server ip", port=port, username="ID")

# 사용
cursor = conn.cursor()
cursor.execute("SELECT 칼럼 FROM 테이블")
for result in cursor.fetchall():
  use_result(result)

or

import pandas as pd
df = pd.read_sql("SELECT cool_stuff FROM hive_table", conn)

Leave a comment