设为首页 加入收藏

TOP

Hive wordcount
2019-02-10 12:52:13 】 浏览:59
Tags:Hive wordcount

一 使用Hive CLI (old)命令行工具操作HiveQL

进入hive cli

[root@master /]# hive

创建统计表

hive> create table wctest(line,content string);

导入数据

可以将本地文本文件内容批量加载到Hive 表中,要求文本文件中的格式和Hive 表的定义一致,包括:字段个数、字段顺序、列分隔符都要一致。
这里的dealer_info 表的表定义是以\t 作为列分隔符,所以准备好数据后,将文本文件拷贝到hive 客户端机器上后,执行加载命令。load data local inpath '/home/hadoop/dealerinfodata.txt' overwrite into table dealer_info;

  • local 关键字表示源数据文件在本地,源文件可以在HDFS 上,如果在HDFS 上,则去掉local,inpath 后面的路径是类似”hdfs://namenode:9000/user/datapath”这样的HDFS 上文件的路径。
  • overwrite 关键字表示如果hive 表中存在数据,就会覆盖掉原有的数据。如果省略overwrite,则默认是追加数据。加载完成数据后,在HDFS 上就会看到加载的数据文件。
hive>load data inpath '/user/root/wordcount_in/wordcount' overwrite  into table wctest;

进行统计

hive>select a.word,count(*) from (select explode(split(wordcontent,' ')) word from wctest)a group by word;

退出Hive CLI

 hive> quit;
[root@master /]# 

mysql 中的hive数据库存储的是hive操作管理下的字段定义,以及hive数据文件的存储位置

mysql> show tables;

表名 标识
COLUMNS_V2 hive 表中的数据类型
DBS hive 上的数据库列表
SDS hive 表物理路径

二 使用Beeline CLI (new)命令行工具操作HiveQL

Beeline version 2.1.1 by Apache Hive

进入beenline

[root@master /]# beeline
beeline> 

链接

beeline> !connect jdbc:hive2://192.168.137.121:10000
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/tools/apache-hive-2.1.1-bin/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/hadoop-2.6.4/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Connecting to jdbc:hive2://192.168.137.121:10000
Enter username for jdbc:hive2://192.168.137.121:10000: root
Enter password for jdbc:hive2://192.168.137.121:10000: 
Connected to: Apache Hive (version 2.1.1)
Driver: Hive JDBC (version 2.1.1)
17/06/08 11:36:34 [main]: WARN jdbc.HiveConnection: Request to set autoCommit to false; Hive does not support autoCommit=false.
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://192.168.137.121:10000> 

操作同Hive CLI

退出beenline

 0: jdbc:hive2://192.168.137.121:10000> !quit
Closing: 0: jdbc:hive2://192.168.137.121:10000
[root@master /]# 
HiveQL 客户端SQuirrelSQLClient使用配置官网
enter description here

相关资源

Hive GettingStarted

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇hive:Access denied for user .. 下一篇Hive的访问接口 | Allen's Wo..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目