【问题标题】:How to execute HQL file in pyspark using Hive warehouse connector如何使用 Hive 仓库连接器在 pyspark 中执行 HQL 文件
【发布时间】:2020-07-03 05:46:34
【问题描述】:

我有一个 hql 文件。我想使用带有 Hive 仓库连接器的 pyspark 运行它。有一个 executeQuery 方法来运行查询。我想知道是否可以这样运行 hql 文件。我们可以运行这样的复杂查询吗? 请提出建议。

谢谢

【问题讨论】:

  • 以下解决方案是否有效或您检查过

标签: apache-spark pyspark hiveql


【解决方案1】:

我有以下解决方案,我假设 hql 文件中会有多个查询。

HQL 文件:sample_query.hql

select * from schema.table;
select * from schema.table2;

代码:遍历每个查询。您可以在每次迭代中随心所欲地进行操作(就 HWC 操作而言)。

with open('sample_query.hql', 'r') as file:
    hql_file = file.read().rstrip()
    
for query in [x.lstrip().rstrip() for x in hql_file.split(";") if len(x) != 0] :
    hive.executeQuery("{0}".format(query))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多