Hive Word count

--https://github.com/slimandslam/pig-hive-wordcount/blob/master/wordcount.hql

DROP TABLE myinput;

DROP TABLE wordcount;

CREATE TABLE myinput (line STRING);

-- Load the text from the local (Linux) filesystem. This should be changed to HDFS

-- for any serious usage

LOAD DATA LOCAL INPATH ‘/home/username/mytext.txt‘ INTO TABLE myinput;

-- Create a table with the words cleaned and counted.

-- The Java regex removes all punctuation and control characters.

---reference http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html

CREATE TABLE wordcount AS

SELECT word, count(1) AS count

FROM (

SELECT EXPLODE(SPLIT(LOWER(REGEXP_REPLACE(line,‘[\\p{Punct},\\p{Cntrl}]‘,‘‘)),‘ ‘))

AS word FROM myinput

) words

GROUP BY word

-- Sort the output by count with the highest counts first

ORDER BY count DESC, word ASC;

-- Make the output look like the output of the Pig DUMP function

-- so that we can diff this output with the Pig wordcount output

SELECT CONCAT_WS(‘,‘, CONCAT("\(",word), CONCAT(count,"\)")) FROM wordcount;

--EXPLODE is a udtf function, used to convert each element in the array to a row.

时间: 2024-08-28 19:45:50

Hive Word count的相关文章

[Hive_add_6] Hive 实现 Word Count

0. 说明 1. Hive 实现 Word Count 方式一 1.1 思路 将每一行文本变为 Array 数组的一个元素 再通过 collection items terminated by ' ' 完成转换单行文本 最后通过表生成函数 explode 分裂 array 数组中的元素变成多行 1.2 实现 1. 创建表 wc create table wc(line array<string>) row format delimited collection items terminated

word count程序,以及困扰人的宽字符与字符

一个Word Count程序,由c++完成,有行数.词数.能完成路径下文件的遍历. 遍历文件部分的代码如下: void FindeFile(wchar_t *pFilePath) { CFileFind finder; CString Finddir; Finddir.Format(pFilePath); BOOL ret = finder.FindFile(Finddir); while (ret) { ret = finder.FindNextFile(); CString strPath

Hadoop AWS Word Count 样例

在AWS里用Elastic Map Reduce 开一个Cluster 然后登陆master node并编译下面程序: import java.io.IOException; import java.util.StringTokenizer; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import o

hive SQL count时的&#39;\N&#39;

Hive中有种假NULL,它看起来和NULL一摸一样,但是实际却不是NULL. 例如如下这个查询: hive> desc ljn004; OK a       string Time taken: 0.237 seconds hive> select a from ljn004; OK NULL Time taken: 46.232 seconds 看上去好像ljn004的a字段保存了一个 NULL, 但是换一个查询会发现它和NULL并不一样: hive> select a from l

Learn ZYNQ(10) &ndash; zybo cluster word count

1.配置环境说明 spark:5台zybo板,192.168.1.1master,其它4台为slave hadoop:192.168.1.1(外接SanDisk ) 2.单节点hadoop测试: 如果出现内存不足情况如下: 查看当前虚拟内存容量: free -m cd /mnt mkdir swap cd swap/ 创建一个swap文件 dd if=/dev/zero of=swapfile bs=1024 count=1000000 把生成的文件转换成swap文件 mkswap swapfi

软件工程第三个程序:“WC项目” —— 文件信息统计(Word Count ) 命令行程序

软件工程第三个程序:“WC项目” —— 文件信息统计(Word Count ) 命令行程序 格式:wc.exe [parameter][filename] 在[parameter]中,用户通过输入参数与程序交互,需实现的功能如下: 1.基本功能 支持 -c 统计文件字符数支持 -w 统计文件单词数支持 -l 统计文件总行数 2.拓展功能 支持 -a 返回高级选项(代码行 空行 注释行)支持 -s 递归处理符合条件的文件 3.高级功能 支持 -x 程序以图形界面与用户交互 [filename] 是

通过简单的Word Count讲解MapReduce原理以及Java实现

MapReduce原理: MapReduce采用"分而治之"的思想,把对大规模数据集的操作,分发给一个主节点管理下的各个分节点共同完成,然后通过整合各个节点的中间结果,得到最终结果.简单地说,MapReduce就是"任务的分解与结果的汇总". 在Hadoop中,用于执行MapReduce任务的机器角色有两个:一个是JobTracker:另一个是TaskTracker,JobTracker是用于调度工作的,TaskTracker是用于执行工作的.一个Hadoop集群中

Hadoop AWS Word Count 例子

在AWS里用Elastic Map Reduce 开一个Cluster 然后登陆master node并编译以下程序: import java.io.IOException; import java.util.StringTokenizer; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import o

c语言简单实现word count功能

c语言简单实现word count功能 一:源码参考  参考地址:https://home.cnblogs.com/u/sunbuqiao/ 二:阅读               代码主要思路是先选定文件,将文件中的字符读入数组,利用for循环分别统计字符数.单词数.空格数.行数.实现过程使用了fseek函数判断指针用于判断数据总长度,根据转移字符判断行数. 三:代码上传                    地址:https://github.com/meinumber1