0
B = GROUP A BY state;
C = FOREACH B {                          
   DA = ORDER A BY population DESC;                
   DB = LIMIT DA 5;                         
   GENERATE FLATTEN(group), FLATTEN(DB.name), FLATTEN(DB.population);
}

问题是我得到了 5 次而不是 1 次城市的名称。我得到如下信息:

(ALASKA,M,27257)
(ALASKA,M,23696)
(ALASKA,M,19949)
(ALASKA,M,19926)
(ALASKA,M,19833)
(ALASKA,H,27257)
(ALASKA,H,23696)
(ALASKA,H,19949)
(ALASKA,H,19926)
(ALASKA,H,19833)

我需要的输出是:

(ALASKA,M,27257)
(ALASKA,H,23696)
4

1 回答 1

1

2个展平:展平(DB.name),展平(DB.population);在 2 个袋子之间造成 Cartezian 产品,用一个替换它

B = GROUP A BY state;
C = FOREACH B {                          
   DA = ORDER A BY population DESC;                
   DB = LIMIT DA 5;                         
   GENERATE FLATTEN(group), FLATTEN(DB.(name, population));
}

或者当 GROUP BY 创建的包携带所有原始元组和所有列时,您可以这样做:

B = GROUP A BY state;
C = FOREACH B {                          
   DA = ORDER A BY population DESC;                
   DB = LIMIT DA 5;                         
   GENERATE FLATTEN(DB);
}
于 2012-12-04T09:21:06.020 回答