//Constructing the query structures by hand, quite ugly.
//group all
ArrayList<EvalSpec> groupFuncs = new ArrayList<EvalSpec>();
groupFuncs.add(new GenerateSpec(new ConstSpec("all")).getGroupBySpec());
quantileJob.groupFuncs = groupFuncs;
//find the quantiles in the reduce step
ArrayList<EvalSpec> argsList = new ArrayList<EvalSpec>();
argsList.add(new ConstSpec(Math.max(loSort.getRequestedParallelism()-1,1)));
//sort the first column of the cogroup output and feed it to the quantiles function
EvalSpec sortedSampleSpec = new ProjectSpec(1);
EvalSpec starSpec = new StarSpec();
starSpec.setComparatorName(loSort.getSortSpec().getComparatorName());
sortedSampleSpec = sortedSampleSpec.addSpec(new SortDistinctSpec(false, starSpec));
argsList.add(sortedSampleSpec);
EvalSpec args = new GenerateSpec(argsList);
EvalSpec reduceSpec = new FuncEvalSpec(pigContext, FindQuantiles.class.getName(), args);
reduceSpec.setFlatten(true);
quantileJob.addReduceSpec(new GenerateSpec(reduceSpec));
//a temporary file to hold the quantile data
String quantileFile = getTempFile(pigContext);
quantileJob.outputFileSpec = new FileSpec(quantileFile, BinStorage.class.getName());