通过azure上的python连接hive和hdinsight

cvxl0en2  于 2021-05-27  发布在  Hadoop
关注(0)|答案(1)|浏览(446)

我想用python脚本将hive与hdinsight cluster连接起来,但是由于访问问题,无法访问cluster dashboard,它将为我提供jdbc url信息,这有助于建立与hive的连接。
有谁能帮我推荐一下用python连接hive和hdinsight集群的方法吗。

import jaydebeapi
conn = jaydebeapi.connect("org.apache.hive.jdbc.HiveDriver",
       "jdbc:hive2://16.4.5.492:451/default/;ssl=true;transportMode=http;httpPath=/hive2", 
       ['Username', 'Password'],
       ["/jdbc/hive-jdbc-1.2.1-standalone.jar",
        "/jdbc/httpclient-4.4.jar",
        "/jdbc/httpcore-4.4.4.jar"])
von4xj4u

von4xj4u1#

webhcat是hcatalog的restapi,是apachehadoop的表和存储管理层。在hdinsight集群上默认启用webhcat,并由各种工具用于提交作业、获取作业状态等,而无需登录集群。简而言之,您可以使用webhcat在python中运行配置单元ql。
附加参考:
https://cwiki.apache.org/confluence/display/hive/webhcathttps用法:/social.msdn.microsoft.com/forums/en-us/b8026143-975f-46c9-b937-99f604e3b757/在基于Linux的远程服务器上使用python应用程序连接到hdinsight中的配置单元?forum=hdinsight
此外,您还可以参考以下文档,使其与jdbc驱动程序一起工作:
https://github.com/uglide/azure-content/blob/master/articles/hdinsight/hdinsight-connect-hive-jdbc-driver.md
我没有尝试过这个,但是一旦配置完成,您应该可以使用下面的代码进行查询。

import jaydebeapi
conn = jaydebeapi.connect("org.apache.hive.jdbc.HiveDriver",
       "jdbc:hive2://my_ip_or_url:443/;ssl=true;transportMode=http;httpPath=/hive2", 
       [username, password],
       "/jdbc/hive-jdbc-1.2.1.jar")

希望有帮助。

相关问题