HIVE --- Client介绍

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yangguosb/article/details/83870104

  HiveServer2支持多种类型的客户端,有Beeline、JDBC 、Python和Rubyd等客户端,下面介绍目前工作中用到的两种:Beeline和JDBC客户端;

Beeline

  Beeline是HiveServer2的命令行终端。下面介绍几个常用的命令:

  • 登录: beeline -u jdbc:hive2://<host>:<port>/<db> -n username -p password
    其它参数选项可查看官网
  • 配置项设置:set = (当前会话有效)比如:set hive.ddl.output.format=json;
  • 退出:!exit

JDBC

使用步骤

  1. 加载驱动
Class.forName("org.apache.hive.jdbc.HiveDriver");
  1. 建立连接
Connection cnct = DriverManager.getConnection("jdbc:hive2://<host>:<port>", "<user>", "<password>");
  1. 执行SQL
Statement stmt = cnct.createStatement();
ResultSet rset = stmt.executeQuery("SELECT foo FROM bar");
  1. 数据处理
  2. 关闭资源
rset.close();
stmt.close();
cnct.close();

Connection URL格式

格式:

jdbc:hive2://<host1>:<port1>,<host2>:<port2>/dbName;initFile=<file>;sess_var_list?hive_conf_list#hive_var_list
  • sess_var_list is a semicolon separated list of key=value pairs of session variables (e.g., user=foo;password=bar).
  • hive_conf_list is a semicolon separated list of key=value pairs of Hive configuration variables for this session
  • hive_var_list is a semicolon separated list of key=value pairs of Hive variables for this session.

参考:

  1. https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients#HiveServer2Clients-JDBC;

猜你喜欢

转载自blog.csdn.net/yangguosb/article/details/83870104