如何在猪中应用全局MAX()

时间:2018-04-17 10:07:28

标签: apache-pig

我是Pig Scripting的新手

我有一个数据集如下:

span

如何使用Pig Scripting获取最大年龄的记录?

我的输出应该是

$child = Program::whereIn('id', $programs_by_date)
                ->where('shareable', '=','1')
                ->whereRaw("( starting_date BETWEEN '".$new_start_date."' AND '".$new_end_date."' OR ending_date BETWEEN '".$new_start_date."' AND '".$new_end_date."' ")
                ->orderBy('starting_date')
                ->get();

1 个答案:

答案 0 :(得分:0)

您需要按年龄降序排序数据,并将数据限制为1以获取具有最大年龄的记录。像这样:

inputData = LOAD 'path' USING PigStorage('\t') AS (name:charray, age:long);
sortedInput = ORGER inputData BY age DESC;
topRecord = LIMIT sortedInput 1;
DUMP topRecord;

值得一提的是,这不是适合map-reduce的操作(通过这里的猪),因为ORDER和LIMIT都没有使用并行性,你的工作将由一个减速器瓶颈。