猪参考 [英] Pig referencing

查看:24
本文介绍了猪参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 Hadoop pig,我总是坚持引用元素.请找到下面的例子.

I am learning Hadoop pig and I always stuck at referencing the elements.please find the below example.

groupwordcount: {group: chararray,words: {(bag_of_tokenTuples_from_line::token: chararray)}}

如果我们有嵌套的元组和包,谁能解释一下如何引用元素.

Can somebody please explain how to reference the elements if we have nested tuples and bags.

任何有助于更好地理解嵌套引用的链接都会有很大帮助.

Any Links for better understanding the nested referrencing would be great help.

推荐答案

我们来做一个简单的Demo来理解这个问题.

Let's do a simple Demonstration to understand this problem.

说一个文件 'a.txt' 存储在 HDFS 的 '/tmp/a.txt' 文件夹

say a file 'a.txt' stored at '/tmp/a.txt' folder in HDFS

A = LOAD '/tmp/a.txt' using PigStorage(',') AS (name:chararray,term:chararray,gpa:float);

转储 A;

(约翰,佛罗里达州,3.9)

(John,fl,3.9)

(约翰,佛罗里达州,3.7)

(John,fl,3.7)

(John,sp,4.0)

(John,sp,4.0)

(John,sm,3.8)

(John,sm,3.8)

(玛丽,佛罗里达州,3.8)

(Mary,fl,3.8)

(玛丽,佛罗里达州,3.9)

(Mary,fl,3.9)

(Mary,sp,4.0)

(Mary,sp,4.0)

(Mary,sm,4.0)

(Mary,sm,4.0)

现在让我们根据一些参数(例如名称和术语)按别名 'A' 分组

Now let's group by this Alias 'A' on the basis of some parameter say name and term

B = GROUP A BY (name,term);

转储 B;

((John,fl),{(John,fl,3.7),(John,fl,3.9)})

((John,fl),{(John,fl,3.7),(John,fl,3.9)})

((John,sm),{(John,sm,3.8)})

((John,sm),{(John,sm,3.8)})

((John,sp),{(John,sp,4.0)})

((John,sp),{(John,sp,4.0)})

((Mary,fl),{(Mary,fl,3.9),(Mary,fl,3.8)})

((Mary,fl),{(Mary,fl,3.9),(Mary,fl,3.8)})

((Mary,sm),{(Mary,sm,4.0)})

((Mary,sm),{(Mary,sm,4.0)})

((Mary,sp),{(Mary,sp,4.0)})

((Mary,sp),{(Mary,sp,4.0)})

描述 B;

B: {group: (name: chararray,term: chararray),A: {(name: chararray,term: chararray,gpa: float)}}

现在变成了你问的问题陈述.让我向您演示如何访问组元组的元素或 A 元组的元素或两者

now it has become the problem statement that you have asked. Let me demonstrate you how to access elements of group tuple or element of A tuple or both

C = foreach B 生成 group.name,group.term,A.name,A.term,A.gpa;

转储 C;

(John,fl,{(John),(John)},{(fl),(fl)},{(3.7),(3.9)})

(John,fl,{(John),(John)},{(fl),(fl)},{(3.7),(3.9)})

(John,sm,{(John)},{(sm)},{(3.8)})

(John,sm,{(John)},{(sm)},{(3.8)})

(John,sp,{(John)},{(sp)},{(4.0)})

(John,sp,{(John)},{(sp)},{(4.0)})

(Mary,fl,{(Mary),(Mary)},{(fl),(fl)},{(3.9),(3.8)})

(Mary,fl,{(Mary),(Mary)},{(fl),(fl)},{(3.9),(3.8)})

(Mary,sm,{(Mary)},{(sm)},{(4.0)})

(Mary,sm,{(Mary)},{(sm)},{(4.0)})

(Mary,sp,{(Mary)},{(sp)},{(4.0)})

(Mary,sp,{(Mary)},{(sp)},{(4.0)})

所以我们通过这种方式访问​​了所有元素.

So we accessed all elements by this way.

希望对您有所帮助

这篇关于猪参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆