7

手册/文档广泛使用“内袋”和“外袋”的语言(比如: http: //pig.apache.org/docs/r0.11.1/basic.html ),但我还不能明确区分这些术语的精确定义。

例如,所有本质上都是相互关联的:

  • 如果我给你一个袋子“foo”,你需要知道什么才能将 foo 标记为“内袋”与“外袋”?
  • 不是最外层包的“任何包”是不是“内包”?
  • 内在和外在的标签总是排他的吗?
  • 在 PigLatin 中,所有的“包”都是“关系”——还是只是“最外层的包”是关系?(和内袋没有关系)

创建一个可讨论的示例:

grunt> dump A;      
(1,2,3)
(4,2,1)
(8,3,4)
(4,3,3)


grunt> W1 = GROUP A   ALL;         
grunt> W2 = GROUP W1  ALL;
grunt> W3 = GROUP W2  ALL;
grunt> W4 = GROUP W3  ALL;

grunt> describe W4;
W4: {group: chararray,W3: {(group: chararray,W2: {(group: chararray,W1: {(group: chararray,A: {(f1: int,f2: int,f3: int)})})})}}


grunt> illustrate W4;
(1,2,3)
---------------------------------------------------
| A     | f1:int      | f2:int      | f3:int      | 
---------------------------------------------------
|       | 1           | 2           | 3           | 
|       | 8           | 3           | 4           | 
---------------------------------------------------
------------------------------------------------------------------------------------------------
| W1     | group:chararray      | A:bag{:tuple(f1:int,f2:int,f3:int)}                          | 
------------------------------------------------------------------------------------------------
|        | all                  | {(1, 2, 3), (8, 3, 4)}                                       | 
------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------
| W2     | group:chararray      | W1:bag{:tuple(group:chararray,A:bag{:tuple(f1:int,f2:int,f3:int)})}                                         | 
-----------------------------------------------------------------------------------------------------------------------------------------------
|        | all                  | {(all, {(1, 2, 3), (8, 3, 4)})}                                                                             | 
-----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| W3     | group:chararray      | W2:bag{:tuple(group:chararray,W1:bag{:tuple(group:chararray,A:bag{:tuple(f1:int,f2:int,f3:int)})})}                                                        | 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|        | all                  | {(all, {(all, {(1, 2, 3), (8, 3, 4)})})}                                                                                                                   | 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| W4     | group:chararray      | W3:bag{:tuple(group:chararray,W2:bag{:tuple(group:chararray,W1:bag{:tuple(group:chararray,A:bag{:tuple(f1:int,f2:int,f3:int)})})})}                                                                       | 
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|        | all                  | {(all, {(all, {(all, {(1, 2, 3), (8, 3, 4)})})})}                                                                                                                                                         | 
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

grunt> dump W4;
(all,{(all,{(all,{(all,{(1,2,3),(4,2,1),(8,3,4),(4,3,3)})})})})

在袋子中——W1、W2、W3、W4——哪个是内部的,哪个是外部的?

4

1 回答 1

4

外袋其实是关系A。这有点奇怪,但一旦你知道什么是内袋,它就会变得清晰。让我们看一下W1,为了便于阅读,因为嵌套包不会改变答案。

架构和输出W1

W1: {group:chararray, A:bag{:tuple(f1:int,f2:int,f3:int)}}
(all,{(1, 2, 3), (8, 3, 4)})

我们可以看到他们是W1named中的一个字段,A它是一个包。这是一个内袋,因为袋是关系中的一个字段。

请记住,bag 只是一组无序的元组,我们可以看到这是W1. 现在,看一下关系的输出A

(1,2,3)
(4,2,1)
(8,3,4)
(4,3,3)

Pig 不保证这些元组的顺序(除非你ORDER或其他人)。所以,如果你仔细想想,关系A实际上只是一组无序的元组。这是一个外袋。

你可以在这里找到一些例子。

于 2013-10-08T09:13:07.247 回答