通过HSFabric的KeyTab认证实现查询HetuEngine SQL任务
通过HSFabric实现KeyTab文件认证方式连接到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.43.244:29902/hive/default?serviceDiscoveryMode=hsfabric" user = "YourUserName" KerberosPrincipal = "YourUserName" tenant = "YourTenant" KerberosConfigPath = "Your file path of krb5.conf" KerberosKeytabPath = "Your file path of user.keytab" jdbc_location = "Your file path of the jdbc jar" sql = "show tables" if __name__ == '__main__': conn = jaydebeapi.connect(driver, url, {'user': user, 'SSL': "true", 'KerberosPrincipal': KerberosPrincipal, 'KerberosConfigPath': KerberosConfigPath, 'KerberosRemoteServiceName': "HTTP", "KerberosKeytabPath": KerberosKeytabPath, "tenant": tenant, 'deploymentMode': "on_yarn", "ZooKeeperSaslClientConfig": "Client"}, [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 |
访问HetuEngine的用户名,即在集群中创建的“人机”用户的用户名。 |
KerberosPrincipal |
KerberosKeytabPath指定的keytab对应的用户名。 |
tenant |
指定访问HetuEngine计算实例的租户资源队列 |
KerberosConfigPath |
访问数据源用户的krb5配置文件,参考配置HetuEngine应用安全认证获取。 |
KerberosKeytabPath |
访问数据源用户的keytab配置文件,参考配置HetuEngine应用安全认证获取。 |
jdbc_location |
导入并配置HetuEngine Python3样例工程中获取的hetu-jdbc-XXX.jar包的完整路径。
|