簡體   English   中英

運行 Hive 查詢的 Python 腳本

[英]Python script to run Hive queries

任何人都可以指導我如何使用 Python 運行 .hql 查詢。 嘗試過 Hiveutils lib,但它不存在於開發環境中。 任何其他方式來執行查詢?

您可以使用PyHive :PyHive 是用於 Presto 和 Hive 的 Python DB-API 和 SQLAlchemy 接口的集合。

示例:

from pyhive import hive
cursor = hive.connect('localhost').cursor()
cursor.execute('SELECT * FROM my_awesome_data LIMIT 10')
print(cursor.fetchone())
print(cursor.fetchall())

您可以嘗試使用 pyhs2,嘗試像下面給出的示例一樣工作

    import pyhs2
    with pyhs2.connect(host='localhost',
           port=10000,
           authMechanism="PLAIN",
           user='your_user',
           password='your_password',
           database='your_default_db') as conn:
        with conn.cursor() as cur:
            print cur.getDatabases()
            cur.execute("select * from table")
            #Return info from query
            print cur.getSchema()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM