final List<String> fields = getRowType().getFieldNames();
/*
* E.g. { op: "segment", ref: "segment", exprs: ["deptId"] }, { op: "collapsingaggregate", within: "segment",
* carryovers: ["deptId"], aggregations: [ {ref: "c", expr: "count(1)"} ] }
*/
final ObjectNode segment = implementor.mapper.createObjectNode();
segment.put("op", "segment");
segment.put("input", inputId);
// TODO: choose different name for field if there is already a field
// called "segment"
segment.put("ref", "segment");
final ArrayNode exprs = implementor.mapper.createArrayNode();
segment.put("exprs", exprs);
for (int group : Util.toIter(groupSet)) {
exprs.add(childFields.get(group));
}
final int segmentId = implementor.add(segment);
final ObjectNode aggregate = implementor.mapper.createObjectNode();
aggregate.put("op", "collapsingaggregate");
aggregate.put("input", segmentId);
aggregate.put("within", "segment");
final ArrayNode carryovers = implementor.mapper.createArrayNode();
aggregate.put("carryovers", carryovers);
for (int group : Util.toIter(groupSet)) {
carryovers.add(childFields.get(group));
}
final ArrayNode aggregations = implementor.mapper.createArrayNode();
aggregate.put("aggregations", aggregations);
for (Ord<AggregateCall> aggCall : Ord.zip(aggCalls)) {
final ObjectNode aggregation = implementor.mapper.createObjectNode();
aggregation.put("ref", fields.get(groupSet.cardinality() + aggCall.i));
aggregation.put("expr", toDrill(aggCall.e, childFields));
aggregations.add(aggregation);
}
return implementor.add(aggregate);
}