Hive读取HDFS上面的数据和使用Squirrel客户端连接Hive

一、把数据从HDFS导入到hive的表里

前面已经测试了利用Sqoop把数据从SQL Server导入到hdfs中,但是分成了好多小文件,正在思考如何把很多小文件一起导入到hive里面,突然想到可以用*来代替啊。

1.建表

在hive里面建立好对应的表格

 create table sites(xxx int,xxx string,xxx  timestamp)
    row format delimited fields terminated by ','
    lines terminated by '\n' stored as textfile;

2.导数

load data inpath 'hdfs://192.168.116.10:9000/sqoop/hdfs/*'into table sites;

(如果是在本地的,load data local inpath '/usr/local/src/xxx.txt' into table xxx)

3.查询看看,有数据了

上面虽然成功的查到有数据已经导入了,但是我想看看有多少数据,在使用select count(1) from sites;

的时候报错了。Job Submission failed with exception 'java.lang.IllegalArgumentException(Wrong FS: file://=/usr/local/src/apache-hive-1.2.1-bin/lib/*, expected: file:///)'
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask

百度和谷歌了一天都没结果,后来在这里找到了答案,原来时候配置问题,需要引入第三方jar。我改成,这里不能有空格各种,如果没有hbase的jar,就去hbase里面复制到这里来。

 <property>
    <name>hive.aux.jars.path</name>
    <value>file:///usr/local/src/apache-hive-1.2.1-bin/lib/hive-hbase-handler-1.2.1.jar,file:///usr/local/src/apache-hive-1.2.1-bin/lib/protobuf-java-2.5.0.jar,file:///usr/local/
src/apache-hive-1.2.1-bin/lib/zookeeper-3.4.6.jar,file:///usr/local/src/apache-hive-1.2.1-bin/lib/guava-14.0.1.jar,file:///usr/local/src/apache-hive-1.2.1-bin/lib/hbase-client-1.
2.6.jar,file:///usr/local/src/apache-hive-1.2.1-bin/lib/hbase-common-1.2.6.jar</value>
    <description>The location of the plugin jars that contain implementations of user defined functions and serdes.</description>
  </property>

改完还是报错,最后才发现原来是配置hive-env.sh的时候,多写了一个等号。。。。。。。。。,泪目,,原来我之前就已经引入第三方jar包了。。

二、使用squirrel客户端连接hive

这里下载squirrel客户端,下载下来是jar格式的,直接点击下一步,一步步安装就行。前提是电脑已经安装好java8环境了。

到Linux里面检查hiveserver2是否开启,在客户端输入hiveserver2,弹出OK即可。

打开squirrel客户端,添加连接:

这里的增加把Hadoop的share里面lib和hive里面的lib文件夹下面的jar包都添加进去,放到本地电脑新建的一个目录里。

可以测试一下是否成功

现在可以大方使用了

猜你喜欢

转载自blog.csdn.net/lbship/article/details/84070895