Hive的图形化工具HWI

今天想使用一下Hive的图形化工具HWI,我的Hive是0.12.0版本。

该版本已经集成了HWI的JAR包,在$HIVE_HOME/lib下的hive-hwi-0.12.0.war。

配置文件也使用默认的即可,

hive-site.xml中默认的配置如下:
<property>
  <name>hive.hwi.listen.host</name>
  <value>0.0.0.0</value>
  <description>This is the host address the Hive Web Interface will listen on</description>
</property>
<property>
  <name>hive.hwi.listen.port</name>
  <value>9999</value>
  <description>This is the port the Hive Web Interface will listen on</description>
</property>
<property>
  <name>hive.hwi.war.file</name>
  <value>/usr/lib/hive/lib/hive_hwi.war</value>
  <description>This is the WAR file with the jsp content for Hive Web Interface</description>
</property>
现在要做的就是添加apache ant的编译工具,不安装则会报错

Problem accessing /hwi/. Reason:

    No Java compiler available
安装方法不做介绍了,网上很多。

安装完后需要设置path:

设置ANT_LIB路径
            export ANT_LIB=/usr/lib/apache-ant-1.9.0/lib
,但是这个方法不好使,需要把
  • ant-launcher.jar
  • ant.jar
这两个jar包拷贝到$HIVE_HOME/lib下,才能使用。

启动HWI命令:

hive --service hwi

然后访问:http://IP:9999/hwi/即可

-------------------------------------------------------------------------------------------------

想通过JAVA代码来访问hive,则需要开启service服务:hive --service hiveserver

简单的Java代码实现;

----通过Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");加载hive驱动

----通过Connection conn = DriverManager.getConnection("jdbc:hive://localhost:10000/default","","");建立与数据库的连接

eg:

package hive.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class HiveJdbcDriver {
    
    public static void main(String[] args) throws Exception {
        Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
        Connection conn = DriverManager.getConnection("jdbc:hive://localhost:1000/default","","");
        Statement stmt = conn.createStatement();
        String tablename = "u_data_new";
        String quary_sql = "select weekday,count(*) from " + tablename + " group by weekday";
        ResultSet rs = stmt.executeQuery(quary_sql);
        while(rs.next()){
            System.out.println("weekday: "+rs.getInt(1)+"count: "+rs.getInt(2));
        }
    }
}

result:

weekday: 2    count: 13579
weekday: 3    count: 14430
weekday: 4    count: 15114
weekday: 5    count: 14743
weekday: 6    count: 18229
weekday: 7    count: 11651

hive执行结果:

hive> select weekday,count(*) from  u_data_new  group by weekday;

-------------------------------------------------------------------------------------------------

HIVE表导入数据的方式:

http://flyingdutchman.iteye.com/blog/1868600


http://www.cnblogs.com/viviman/archive/2013/01/29/2881784.html

展开阅读全文

没有更多推荐了,返回首页