Hive中提供了类似于SQL语言的查询语言——HiveQL,可以通过 HiveQL语句快速实现简单的 MapReduce统计, Hive 自身可以将 HiveQL 语句快速转换成 MapReduce 任务进行运行,而不必开发专门的 MapReduce 应用程序,因而十分适合数据仓库的统计分析。 通过一个简单的词频统计来初步认识hive
1.本地创建两个文本文件
/usr/local/hadoop/input “hello world” file1.txt
“hello hadoop” file2.txt
2.将文件上传至hdfs中(因为hive的的操作是基于hdfs文件系统)
./bin/hdfs dfs -mkdir -p /wordcount/input./bin/hdfs dfs -put /usr/local/hadoop/input/*.txt /wordcount/input
3.在hive下通过如下HiveQL语句实现统计功能
create table wordcountline string //表有一个string类型的字段load data inpath overwrite into table wordcount //把数据导入到wordcount表
create table word_count as
word,count as count from
select explodesplitline, as word from wordcount w //通过explode函数把wordcount表变成字段为word的w表
group by word
order by word
4.查找结果
* from word_count
还没有评论,来说两句吧...