GoHive:支持SASL的go语言Hive客户端

简介

https://github.com/lwldcr/gohive

花了一周时间才调通,看log配合Hive的源码一步步debug相当费事,基本是按照pyhs2来实现的,支持SASL协议Plain模式,其他模式看后续是否需要酌情增加。客户端、查询操作返回数据还可以进一步封装,提供更便捷的使用,后面再更新吧。

欢迎试用、反馈。

GoHive

A hive client with SASL support based on thrift.

Usage
package main

import (
    "fmt"
    "tcliservice"
    "github.com/lwldcr/gohive"
    "os"
)

func main() {
    // first build a new transport
    // of course we c
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用UGI连接Hive客户端的Java代码示例: ``` import java.io.IOException; import java.security.PrivilegedExceptionAction; import java.util.List; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.authentication.util.KerberosName; import org.apache.hadoop.security.token.Token; import org.apache.hadoop.security.token.TokenIdentifier; import org.apache.hadoop.security.token.TokenSelector; import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSelector; import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager; import org.apache.hadoop.security.token.delegation.DelegationKey; import org.apache.hadoop.security.token.delegation.ZKDelegationTokenSecretManager; import org.apache.hadoop.security.token.delegation.ZKDelegationTokenSecretManager.ZKDTSMState; import org.apache.hadoop.security.token.delegation.web.DelegationTokenIdentifier; import org.apache.hadoop.security.token.delegation.web.DelegationTokenManager; import org.apache.hadoop.security.token.delegation.web.DelegationTokenManager.HttpUserGroupInformation; import org.apache.hadoop.security.token.delegation.web.DelegationTokenManager.KerberosDelegationTokenAuthenticator; import org.apache.hadoop.security.token.delegation.web.DelegationTokenManager.ZKDTSMKeyOp; import org.apache.hadoop.security.token.delegation.web.DelegationTokenManager.ZKSecretManagerState; import org.apache.hadoop.security.token.delegation.web.ZKDelegationTokenSecretManagerForTest; import org.apache.hadoop.security.token.delegation.web.ZKDelegationTokenSecretManagerForTest.ZKDTSMForTestState; import org.apache.hadoop.security.token.delegation.web.ZKDelegationTokenSecretManagerForTest.ZKDelegationTokenSecretManagerForTestImpl; import org.apache.hadoop.security.token.delegation.web.ZKDelegationTokenSecretManagerForTest.ZKDelegationTokenSecretManagerForTestState; import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.metastore.HiveMetaStoreClient; public class HiveClientWithUGI { public static void main(String[] args) throws Exception { final String user = "hiveuser"; final String keytabLocation = "/path/to/user.keytab"; final String krb5Location = "/path/to/krb5.conf"; // Set Hadoop and Hive configurations Configuration conf = new Configuration(); conf.set("hadoop.security.authentication", "Kerberos"); conf.set("hadoop.security.authorization", "true"); conf.set("hive.metastore.sasl.enabled", "true"); conf.set("hive.metastore.kerberos.principal", "hive/[email protected]"); conf.set("hive.metastore.sasl.qop", "auth-conf"); conf.set("hive.metastore.client.factory.class", "org.apache.hadoop.hive.metastore.hbase.HBaseMetaStoreClientFactory"); // Set Kerberos security System.setProperty("java.security.krb5.conf", krb5Location); UserGroupInformation.setConfiguration(conf); UserGroupInformation.loginUserFromKeytab(user, keytabLocation); // Create a Hive metastore client HiveConf hiveConf = new HiveConf(conf, HiveConf.class); HiveMetaStoreClient hiveClient = new HiveMetaStoreClient(hiveConf); // Get list of databases List<String> databases = hiveClient.getAllDatabases(); for (String database : databases) { System.out.println(database); } // Close the client hiveClient.close(); } } ``` 需要注意的是,代码中涉及到了Kerberos认证和安全配置,需要根据实际情况进行调整。同时,需要根据实际的Hive Metastore服务地址和端口进行设置。此外,代码中使用了UGI来进行Kerberos认证,需要提供对应的keytab文件和krb5.conf文件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值