博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hive进行词频统计
阅读量:6969 次
发布时间:2019-06-27

本文共 1223 字,大约阅读时间需要 4 分钟。

统计文件信息:

$ /opt/cdh-5.3.6/hadoop-2.5.0/bin/hdfs dfs -text /user/hadoop/wordcount/input/wc.input

hadoop spark
spark hadoop
oracle mysql postgresql
postgresql oracle mysql
mysql mongodb
hdfs yarn mapreduce
yarn hdfs
zookeeper

针对于以上文件使用hive做词频统计:

create table docs (line string);

load data inpath '/user/hadoop/wordcount/input/wc.input' into table docs;

create table word_counts as

select word,count(1) as count from
(select explode(split(line,' ')) as word from docs) word
group by word
order by word;

分段解释:

--使用split函数对表中行按空格进行分隔:

select split(line,' ') from docs;

["hadoop","spark",""]
["spark","hadoop"]
["oracle","mysql","postgresql"]
["postgresql","oracle","mysql"]
["mysql","mongodb"]
["hdfs","yarn","mapreduce"]
["yarn","hdfs"]
["zookeeper"]

--使用explode函数对split的结果集进行行拆列:

select explode(split(line,' ')) as word from docs;

word
hadoop
spark

spark

hadoop
oracle
mysql
postgresql
postgresql
oracle
mysql
mysql
mongodb
hdfs
yarn
mapreduce
yarn
hdfs
zookeeper

--以上输出内容已经满足对其做统计分析,这时通过sql对其进行分析:

select word,count(1) as count from

(select explode(split(line,' ')) as word from docs) word
group by word
order by word;

word    count

     1
hadoop    2
hdfs    2
mapreduce    1
mongodb    1
mysql    3
oracle    2
postgresql    2
spark    2
yarn    2
zookeeper    1

转载地址:http://uxisl.baihongyu.com/

你可能感兴趣的文章
网站的宣传推广极为重要
查看>>
给Metro风格RSS阅读器加个搜索
查看>>
mysql 主从同步
查看>>
使用WebStorm和Git开发Node.js应用
查看>>
TCP_Header
查看>>
加拿大退休金计划投资局CEO:关注雅虎出售
查看>>
Android应用程序组件Content Provider的启动过程源代码分析(2)
查看>>
构建LFS系统6.6版
查看>>
DNS显性+隐性URL转发原理
查看>>
Java 内存溢出(java.lang.OutOfMemoryError)的常见情况和处理方式总结
查看>>
RSA2012系列(5):虚拟化安全总揽
查看>>
日常数据文件自动入hive数据库
查看>>
关hbase安装的困惑整了两天了还是这个报错!
查看>>
一个完整的nginx生产配置示例
查看>>
SVG格式图片相关
查看>>
OrderLogic
查看>>
CISCO_3750升级IOS实例
查看>>
folder.htt等文件的问题
查看>>
成本管理的6个基本内容
查看>>
企业渠道管理的六大失误
查看>>