-2

给定表格:

Place(name, province, population, mayorid)

您将如何用 Pig Latin 编写以下查询?为每个省返回人口最多的地方。您的结果集应该包含省名、地名和该地的人口。

4

1 回答 1

0

没有测试过这个,但类似

places = LOAD 'placesInput' AS (name, province, population, mayorid);
placesProjected = FOREACH places GENERATE name,province,population;
placesGrouped = GROUP placesProjected by province;
biggestPlaces = FOREACH placesGrouped {
    sorted = ORDER placesProjected by population DESC;
    maxPopulation = LIMIT sorted 1;
    GENERATE group as province, FLATTEN(maxPopulation.name) as name, FLATTEN(maxPopulation.population) as population;
};

应该工作。

于 2013-04-15T07:50:13.447 回答