Python:多处理 Hive 查询

Python: Multiprocessing Hive queries

我正在尝试通过从地图传递 table 名称来执行多个 Hive 查询,即

from pyhive import hive
from multiprocessing import Pool
from functools import partial
import pandas as pd

conn = hive.connect('hive_connection',99999,
                          username='user',
                          password='password',
                          auth='LDAP')

query = 'select * from hive_db.{hive_table_name} limit 500'.format(hive_table_name=hive_table_name)

def hivetable(hive_table_name):
    query = 'select * from hive_db.{hive_table_name} limit 10'.format(table_name=hive_table_name)
    result = pd.read_sql(query,conn)
    return result

if __name__ == "__main__" :
    p = Pool(5)
    print p.map(((hivetable, ['hive_table1','hive_table2','hive_table3'])))

但得到:

TypeError: map() takes at least 3 arguments (2 given)

如何在这里实现多处理并解决持续存在的问题? 尝试了其他参考资料,但找不到任何关于 SQL 的参考资料。

非常感谢任何帮助/建议。

问题是调用 map 函数时有太多额外的括号。

试试这个,它应该可以正常工作。

if __name__ == "__main__" :
    p = Pool(5)
    print p.map(hivetable, ['hive_table1','hive_table2','hive_table3'])

我正在考虑您要处理的实际 table 大于 3,否则在 3 table 上创建 5 个线程没有意义。