Hive hiveserver2

来源:互联网 发布:卢松松博客模板php 编辑:程序博客网 时间:2024/05/18 04:51

1:运行

命令行模式:

hive --service hiveserver2 --hiveconf hive.server2.thrift.port=10001

服务模式:

hiveserver2 start

[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. [jifeng@feng01 conf]$ hive --service hiveserver2 --hiveconf hive.server2.thrift.port=10001  
  2. Starting HiveServer2  
  3. 15/03/05 16:59:33 WARN conf.HiveConf: DEPRECATED: hive.metastore.ds.retry.* no longer has any effect.  Use hive.hmshandler.retry.* instead  


2:权限问题

java jdbc连接报错:

[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. Exception in thread "main" java.sql.SQLException: Error while compiling statement: FAILED: RuntimeException Cannot make directory: hdfs://feng01:9000/tmp/hive-jifeng/hive_2015-03-05_17-04-43_349_5945847416346775092-3  
  2.     at org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:121)  
  3.     at org.apache.hive.jdbc.Utils.verifySuccessWithInfo(Utils.java:109)  
  4.     at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:231)  
  5.     at org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:355)  
  6.     at demo.test.Pretest.main(Pretest.java:28)  

服务端也看到错误
[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. FAILED: RuntimeException Cannot make directory: hdfs://feng01:9000/tmp/hive-jifeng/hive_2015-03-05_17-04-43_349_5945847416346775092-3  
无权限创建目录,修改为管理hadoop的用户和密码

修改后

3:For input string: "5000L"

JDBC连接报:

[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. Exception in thread "main" java.sql.SQLException: For input string: "5000L"  
  2.     at org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:121)  
  3.     at org.apache.hive.jdbc.Utils.verifySuccessWithInfo(Utils.java:109)  
  4.     at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:263)  
  5.     at org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:355)  
  6.     at demo.test.Pretest.main(Pretest.java:28)  
修改配置:

把hive-site.xml

这个配置文件里hive.server2.long.polling.timeout这个参数是5000L,改成5000

[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. [jifeng@feng01 conf]$ vi hive-site.xml   
  2.   
  3.   <name>hive.server2.long.polling.timeout</name>  
  4.   <value>5000</value>  
  5.   <description>Time in milliseconds that HiveServer2 will wait, before responding to asynchronous calls that  
  6.  use long polling</description>  
  7. </property>  
4:JDBC 连接HIVE OK

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. package demo.test;  
  2.   
  3. import java.sql.*;  
  4.   
  5. public class Pretest {  
  6.   
  7.   
  8.             public static void main( String args[] )  
  9.                 throws SQLException , ClassNotFoundException {  
  10.                 String jdbcdriver="org.apache.hive.jdbc.HiveDriver";  
  11.   
  12.                 String jdbcurl="jdbc:hive2://feng01:10001";  
  13.   
  14.                 String username="jifeng";  
  15.                 String password="jifeng";         
  16.                 Class.forName(jdbcdriver);  
  17.                 Connection c = DriverManager.getConnection(jdbcurl,username,password);   
  18.                 Statement st = c.createStatement();  
  19.                // select * from firewall where idauto=16600918"));//  
  20.                 print( "num should be 1 " , st.executeQuery("select * from course"));  
  21.                 //( "select id,name,vip from users order by id limit 5" ) );  
  22.                 // TODO indexing  
  23.             }  
  24.              static void print( String name , ResultSet res )  
  25.                         throws SQLException {  
  26.                         System.out.println( name);  
  27.                         ResultSetMetaData meta=res.getMetaData();                         
  28.                         //System.out.println( "\t"+res.getRow()+"条记录");  
  29.                         String  str="";  
  30.                         for(int i=1;i<=meta.getColumnCount();i++){  
  31.                             str+=meta.getColumnName(i)+"   ";  
  32.                             //System.out.println( meta.getColumnName(i)+"   ");  
  33.                         }  
  34.                         System.out.println("\t"+str);  
  35.                         str="";  
  36.                         while ( res.next() ){  
  37.                             for(int i=1;i<=meta.getColumnCount();i++){     
  38.                                 str+= res.getString(i)+"   ";                           }   
  39.                             System.out.println("\t"+str);  
  40.                             str="";  
  41.                         }  
  42.                     }         
  43. }  
运行结果:
[plain] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. course.id   course.c1   course.c2   course.c3   course.c4     
  2. 1   英语   中文   法文   日文     
  3. 2   中文   法文           
  4. 3   中文   法文   日文        
  5. 4   中文   法文   拉丁        
  6. 5   中文   法文   德文        
0 0
原创粉丝点击