python에서 hive 사용
OS에 sasl 설치
yum install libsasl2-dev
파이선 패키지 설치
pip install sasl
pip install thrift
pip install thrift-sasl
pip install PyHive
연결
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)
=============================
pip install sasl
pip install thrift
pip install thrift-sasl
pip install pyhs2
import pyhs2
with pyhs2.connect(host='localhost',
port=10000,
authMechanism="PLAIN",
user='root',
password='test',
database='default') as conn:
with conn.cursor() as cur:
#Show databases
print cur.getDatabases()
#Execute query
cur.execute("select * from table")
#Return column info from query
print cur.getSchema()
#Fetch table results
for i in cur.fetch():
print i
yum install libsasl2-dev
파이선 패키지 설치
pip install sasl
pip install thrift
pip install thrift-sasl
pip install PyHive
연결
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)
=============================
pip install sasl
pip install thrift
pip install thrift-sasl
pip install pyhs2
import pyhs2
with pyhs2.connect(host='localhost',
port=10000,
authMechanism="PLAIN",
user='root',
password='test',
database='default') as conn:
with conn.cursor() as cur:
#Show databases
print cur.getDatabases()
#Execute query
cur.execute("select * from table")
#Return column info from query
print cur.getSchema()
#Fetch table results
for i in cur.fetch():
print i
댓글
댓글 쓰기