Pig group用法举例
[hadoop@vm1 ~]$ cat orders.data
1 apple 30 x
2 apple 50 x
3 banana 30 y
4 pear 20 y
5 banana 10 y
[hadoop@vm1 ~]$
data = load '/orders.data' as (orderid:int, fruit:chararray, amount:int);
grpd = group data by fruit;
describe grpd;
grpd: {group: chararray,data: {(orderid: int,fruit: chararray,amount: int)}}
dump grpd;
(pear,{(4,pear,20)})
(apple,{(2,apple,50),(1,apple,30)})
(banana,{(5,banana,10),(3,banana,30)})
dump grpd;
(pear,{(4,pear,20)})
(apple,{(2,apple,50),(1,apple,30)})
(banana,{(5,banana,10),(3,banana,30)})
group data by $0+$1;
orders = load '/orders.data' as (orderid:int, fruit:chararray, amount:int, type:chararray);
grpd = group orders by (fruit, type);
describe grpd;
grpd: {group: (fruit: chararray,type: chararray),orders: {(orderid: int,fruit: chararray,amount: int,type: chararray)}}
dump grpd;
((pear,y),{(4,pear,20,y)})
((apple,x),{(2,apple,50,x),(1,apple,30,x)})
((banana,y),{(5,banana,10,y),(3,banana,30,y)})
sums = foreach grpd generate group, SUM(orders.amount);
dump sums;
((pear,y),20)
((apple,x),80)
((banana,y),40)
sums2 = foreach grpd generate group.$0, group.$1, SUM(orders.amount);
dump sums2;
(pear,y,20)
(apple,x,80)
(banana,y,40
grpd = group orders all;
describe grpd;
grpd: {group: chararray,orders: {(orderid: int,fruit: chararray,amount: int,type: chararray)}}
dump grpd;
(all,{(5,banana,10,y),(4,pear,20,y),(3,banana,30,y),(2,apple,50,x),(1,apple,30,x)})
A = LOAD 'data1' AS (owner:chararray,pet:chararray);
DUMP A;
(Alice,turtle)
(Alice,goldfish)
(Alice,cat)
(Bob,dog)
(Bob,cat)
B = LOAD 'data2' AS (friend1:chararray,friend2:chararray);
DUMP B;
(Cindy,Alice)
(Mark,Alice)
(Paul,Bob)
(Paul,Jane)
X = COGROUP A BY owner, B BY friend2;
DESCRIBE X;
X: {group: chararray,A: {owner: chararray,pet: chararray},B: {friend1: chararray,friend2: chararray}}
DUMP X;
(Alice,{(Alice,turtle),(Alice,goldfish),(Alice,cat)},{(Cindy,Alice),(Mark,Alice)})
(Bob,{(Bob,dog),(Bob,cat)},{(Paul,Bob)})
(Jane,{},{(Paul,Jane)})
A = LOAD 'input_data';
B = GROUP A BY $0 PARTITION BY org.apache.pig.test.utils.SimpleCustomPartitioner PARALLEL 2;
public class SimpleCustomPartitioner extends Partitioner <PigNullableWritable, Writable> {
//@Override
public int getPartition(PigNullableWritable key, Writable value, int numPartitions) {
if(key.getValueAsPigType() instanceof Integer) {
int ret = (((Integer)key.getValueAsPigType()).intValue() % numPartitions);
return ret;
}
else {
return (key.hashCode()) % numPartitions;
}
}
}
Pig group用法举例的更多相关文章
- Pig sample用法举例
some = sample data 0.1 遍历整个数据集,获取指定比例的行数的数据,获取的数据不确定,条数也不准确. 内部重写为filter data by random() <= ...
- Pig limit用法举例
lmt = limit data 10; 只获取指定条数的数据,不能保证每次得到的结果一致,先执行order再limit可以保证一致. 输入数据全部载入. 会触发reduce阶段 a ...
- Pig join用法举例
jnd = join a by f1, b by f2; join操作默认的是内连接,只有两边都匹配才会保留 需要用null补位的那边需要知道它的模式: 如果是左外连接,需要知道右边的数据集的 ...
- Pig foreach用法举例
foreach:一行一行的遍历数据,处理一行的数据,然后返回一个tuple. users = load '/users.data'; 1)别名引用 f = foreach users genera ...
- Pig load 用法举例
users = load '/users.data' using PigStorage() as (name:chararray, age:int, address:chararray); loa ...
- Pig distinct用法举例
dst = distinct data: DISTINCT只能对整个记录(整行)去重,不能在字段级别去重. 触发reduce阶段 data = load 'data'; distinct ...
- Pig store用法举例
store:将数据存储到HDFS等文件系统里 将数据保存到/data目录 store data into '/data'; 以逗号为分隔符 store data into '/data' usin ...
- Pig filter用法举例
filter:过滤数据,只有符合特定条件的数据才会被保留下来,然后进入下一个数据流. 1)等值比较 filter data by $0 == 1 filter data by $0 != 1 ...
- c++ stl容器set成员函数介绍及set集合插入,遍历等用法举例
c++ stl集合set介绍 c++ stl集合(Set)是一种包含已排序对象的关联容器.set/multiset会根据待定的排序准则,自动将元素排序.两者不同在于前者不允许元素重复,而后者允许. 1 ...
随机推荐
- (转) mysqldumpslow使用说明总结
原文:http://blog.csdn.net/langkeziju/article/details/49301993 mysqldumpslow使用说明mysqldumpslow --helpUsa ...
- docker registry push错误“server gave HTTP response to HTTPS client”
系统环境:centos7 docker版本: 1.12.3(注意版本,可能存在不同版本设置不同的情况) docker registry版本:2.4.1 问题: 成功安装docker registry, ...
- Java之集合(二)ArrayDeque
转载请注明源出处:http://www.cnblogs.com/lighten/p/7283928.html 1.前言 上章讲解了Java中的集合接口和相关实现抽象类,本章开始介绍一些具体的实现类,第 ...
- Java之IO(十二)CharArrayReader和CharArrayWriter
转载请注明源出处:http://www.cnblogs.com/lighten/p/7082668.html 1.前言 本章介绍字符数组流,作用和ByteArrayInputStream字节数组流相同 ...
- linux内核模块的安全
linux可以动态的加载内核模块,在很多场合可能需要确保加载内核的安全性.如果被攻击者加载恶意内核模块,将会使得内核变得极其危险. 当然,稳妥的做法就是给内核模块进行签名,内核只加载能正确验证的签名. ...
- 第11章—使用对象关系映射持久化数据—SpringBoot+SpringData+Jpa进行查询修改数据库
SpringBoot+SpringData+Jpa进行查询修改数据库 JPA由EJB 3.0软件专家组开发,作为JSR-220实现的一部分.但它又不限于EJB 3.0,你可以在Web应用.甚至桌面应用 ...
- 【转】使用SQL Server 2012的FileTable轻松管理文件
一 .FileStream和FileTable介绍 我们经常需要把结构化数据(int.Char等)和非结构化数据(如Varbinary(max))一起存储,那我们在怎么存储的呢? 1. 在SQL Se ...
- Ubuntukylin-14.04-desktop(带分区)安装步骤详解
不多说,直接上干货! 成功! Ubuntukylin-14.04-desktop( 不带分区)安装步骤详解 Ubuntukylin-14.04-desktop( 不带分区)安装步骤详解 Ubuntu1 ...
- windwos文档格式转换成unix格式
在工作学习中我们避免不了需要将一些脚本和命令记录在笔记里面,我使用的是有道云笔记,每当我将上次记录在有道云的脚本复制出来进行使用的时候,总会报一些奇怪的错误,要么是包含换行符,要么就是格式不对,但是我 ...
- vue cli+axios踩坑记录+拦截器使用,代理跨域proxy
1.首先axios不支持vue.use()方式声明使用,看了所有近乎相同的axios文档都没有提到这一点 建议方式 在main.js中如下声明使用 import axios from 'axios'; ...