通过HSFabric的用户名密码认证实现查询HetuEngine SQL任务
通过HSFabric方式连接到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:29903,192.168.37.61:29903/hive/default?serviceDiscoveryMode=hsfabric" 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://HSFabric1_IP:HSFabric1_Port,HSFabric2_IP:HSFabric2_Port,HSFabric3_IP:HSFabric3_Port/catalog/schema?serviceDiscoveryMode=hsfabric |
user |
访问HetuServer的用户名,即在集群中创建的“人机”用户的用户名。 |
tenant |
指定访问HetuEngine计算实例的租户资源队列。 |
jdbc_location |
导入并配置HetuEngine Python3样例工程中获取的hetu-jdbc-XXX.jar包的完整路径。
|