--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.

Hive Word count的更多相关文章

  1. [Hive_add_6] Hive 实现 Word Count

    0. 说明 Hive 通过 explode()函数 和 split()函数 实现 WordConut 1. Hive 实现 Word Count 方式一 1.1 思路 将每一行文本变为 Array 数 ...

  2. mac上eclipse上运行word count

    1.打开eclipse之后,建立wordcount项目 package wordcount; import java.io.IOException; import java.util.StringTo ...

  3. MapReduce工作机制——Word Count实例(一)

    MapReduce工作机制--Word Count实例(一) MapReduce的思想是分布式计算,也就是分而治之,并行计算提高速度. 编程思想 首先,要将数据抽象为键值对的形式,map函数输入键值对 ...

  4. Word Count作业

    Word Count作业 一.个人Gitee地址:https://gitee.com/Changyu-Guo 二.项目简介 该项目主要是模拟Linux上面的wc命令,基本要求如下: 命令格式: wc. ...

  5. Word Count

    Word Count 一.个人Gitee地址:https://gitee.com/godcoder979/(该项目完整代码在这里) 二.项目简介: 该项目是一个统计文件字符.单词.行数等数目的应用程序 ...

  6. Mac下hadoop运行word count的坑

    Mac下hadoop运行word count的坑 Word count体现了Map Reduce的经典思想,是分布式计算中中的hello world.然而博主很幸运地遇到了Mac下特有的问题Mkdir ...

  7. [MapReduce_1] 运行 Word Count 示例程序

    0. 说明 MapReduce 实现 Word Count 示意图 && Word Count 代码编写 1. MapReduce 实现 Word Count 示意图 1. Map:预 ...

  8. 【2016.3.22】作业 Word count 小程序

    今天更下word count程序的设计思路及实现方法. 我的程序贴在coding里,这里就先不贴出来了, 我的coding地址:https://coding.net/u/holy_angel/p/wo ...

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

    软件工程第三个程序:“WC项目” —— 文件信息统计(Word Count ) 命令行程序 格式:wc.exe [parameter][filename] 在[parameter]中,用户通过输入参数 ...

随机推荐

  1. Python基础:函数式编程

    一.概述 Python是一门多范式的编程语言,它同时支持过程式.面向对象和函数式的编程范式.因此,在Python中提供了很多符合 函数式编程 风格的特性和工具. 以下是对 Python中的函数式编程 ...

  2. 重新想象 Windows 8 Store Apps (66) - 后台任务: 下载和上传

    [源码下载] 重新想象 Windows 8 Store Apps (66) - 后台任务: 下载和上传 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 后台任务 后台 ...

  3. Urlencode and Urldecode 命令行

    由于经常使用,简单记录之 $ alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.ar ...

  4. LGLSearchBar

    平时我们都是用UITextFeild 来写搜索框, 最近有时间就自己重新封装了UISearchBar, 他可以自行修改里面的属性来达到我们使用的要求. 源代码下载地址:https://github.c ...

  5. 将HTML5封装成android应用APK文件的几种方法(转)

    作为下一代的网页语言,HTML5拥有很多让人期待已久的新特性.HTML5的优势之一在于能够实现跨平台游戏编码移植,现在已经有很多公司在移动 设备上使用HTML5技术.随着HTML5跨平台支持的不断增强 ...

  6. android的Project has no default.properties file! Edit the project properties to set one. 的解决

    网上找来这种方法基本解决: 在我们导入Android工程时,有时候会出现如题所述的错误,打开工程目录可以看到,目录下的default.properties文件没有了或者多出了一个project.pro ...

  7. [Tool] 使用StyleCop验证命名规则

    [Tool] 使用StyleCop验证命名规则 前言 微软的MSDN上,有提供了一份微软的命名方针,指引开发人员去建立风格一致的程序代码. http://msdn.microsoft.com/zh-t ...

  8. 帝吧出征FB:这李毅吧的“爆吧”文化是如何形成的

    声明:本文不对爆吧行为及其涉及的事件进行是非判断,只探讨帝吧文化本身,欢迎拍砖.更正和补充. 一.“帝吧FB出征”事件梳理 继上次全网集体骂 “薯片”事件后,昨日(1月20日)晚7点,又发生了一次互联 ...

  9. Atitit.病毒木马程序的感染 传播扩散 原理

    Atitit.病毒木马程序的感染 传播扩散 原理 1. 从木马的发展史考虑,木马可以分为四代 1 2. 木马有两大类,远程控制  vs  自我复制传播1 3. 自我复制2 3.1. 需要知道当前cpu ...

  10. 实验12:Problem J: 动物爱好者

    #define null ""是用来将字符串清空的 #define none -1是用来当不存在这种动物时,返回-1. 其实这种做法有点多余,不过好理解一些. Home Web B ...