在win10 python3用pyhive连接hive

文章目录


需要在两个部分分别进行设置

Hive部分

在虚拟机端安装使用hive时,初始是没有设置用户名和密码,
在我们使用pyhive连接hive时需要用到用户名和密码
此时,我们就要启用hive的自定义用户名密码验证

  • 第一步:根据hiveServer2服务提供的接口,实现他

To implement custom authentication for HiveServer2, create a custom Authenticator class derived from the following interface:

从这段话看出来我们要实现一个接口:PasswdAuthenticationProvider (org.apache.hive.service.auth.PasswdAuthenticationProvider)我们来看看这个接口
发现有一个方法要实现,实现了这个接口就可以自定义验证用户名密码了

public interface PasswdAuthenticationProvider {
     
  /** 
   * The Authenticate method is called by the HiveServer2 authentication layer 
   * to authenticate users for their requests. 
   * If a user is to be granted, return nothing/throw nothing. 
   * When a user is to be disallowed, throw an appropriate {
   @link AuthenticationException}. 
   * 
   * For an example implementation, see {
   @link LdapAuthenticationProviderImpl}. 
   * 
   * @param user - The username received over the connection request 
   * @param password - The password received over the connection request 
   * @throws AuthenticationException - When a user is found to be 
   * invalid by the implementation 
   */  
  void Authenticate(String user, String password) throws AuthenticationException;  
}  

接口实现代码:
将代码打包为jar包,放在hive根目录的lib目录下

package org.apache.hadoop.hive.contrib.auth;
 
 
import javax.security.sasl.AuthenticationException;
 
 
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hive.conf.HiveConf;
import org.slf4j.Logger;
 
 
public class CustomPasswdAuthenticator implements org.apache.hive.service.auth.PasswdAuthenticationProvider{
   
	
	private Logger LOG = org.slf4j.LoggerFactory.getLogger(CustomPasswdAuthenticator.class);
	
	private static final String HIVE_JDBC_PASSWD_AUTH_PREFIX="hive.jdbc_passwd.auth.%s
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值