如何在python函数中有效地查询impala sql

4uqofj5v  于 2021-06-26  发布在  Impala
关注(0)|答案(0)|浏览(158)

基本上,我的公司使用ApacheImpala进行数据集市,我想这与非HadoopSQL没有什么不同
连接参数在之前定义,连接定义为 conn = connect(host=host_name, port=port, user=user, password=password, database=database) 每次我需要一个表的时候,我都需要调用这样的函数

def impala_connection(host, port, user, password, database):
    conn = connect(host=host_name, port=port, user=user, password=password, database=database)
    cursor = conn.cursor()
    cursor.execute('SELECT * from table1')
    results = cursor.fetchall()
    return results
table1 = pd.DataFrame(impala_connection(host_name, port, user,password, database))

对于另一张table,我也这样做

def impala_connection(host, port, user, password, database):
    conn = connect(host=host_name, port=port, user=user, password=password, database=database)
    cursor = conn.cursor()
    cursor.execute('SELECT * from table2')
    results = cursor.fetchall()
    return results
table2 = pd.DataFrame(impala_connection(host_name, port, user,password, database))

等。
有没有更“优雅”的方法来做这个,我尝试了多种方法来减少函数的重复,这是我的最大结果。因为函数被设计成一次调用多次使用,而不是相反。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题