通过HSBroker的用户名密码认证实现查询HetuEngine SQL任务
本章节适用于MRS 3.3.0及以后版本。
通过HSBroker方式连接到HetuEngine,组装对应的SQL发送到HetuEngine执行,完成对Hive数据源的增删改查操作。
import jaydebeapi driver = "io.XXX.jdbc.XXXDriver" # need to change the value based on the cluster information url = "jdbc:XXX://192.168.37.61:29861,192.168.37.62:29861/hive/default?serviceDiscoveryMode=hsbroker" user = "YourUserName" tenant = "YourTenant" jdbc_location = "Your file path of the jdbc jar" sql = "show catalogs" if __name__ == '__main__': conn = jaydebeapi.connect(driver, url, {"user": user, "SSL": "false", "tenant": tenant}, [jdbc_location]) curs = conn.cursor() curs.execute(sql) result = curs.fetchall() print(result) curs.close() conn.close()
上述代码中各参数说明如下表所示:
参数名称 |
参数说明 |
---|---|
url |
jdbc:XXX://HSBroker1_IP:HSBroker1_Port,HSBroker2_IP:HSBroker2_Port,HSBroker3_IP:HSBroker3_Port/catalog/schema?serviceDiscoveryMode=hsbroker
说明:
|
user |
访问HetuServer的用户名,即在集群中创建的“人机”用户的用户名。 |
tenant |
指定访问HetuEngine计算实例的租户资源队列。 |
jdbc_location |
导入并配置HetuEngine Python3样例工程中获取的hetu-jdbc-XXX.jar包的完整路径。
|