for (Evaluator e : selectItems) {
resultRow.put(e.getText(), e.evaluate(record));
}
output.addRecord(new ProcessDataRecord() {
Map<String, EvaluationResult> expandedRow = expandSelectAllAndResolveDuplicateName(resultRow);
@Override
public EvaluationResult lookup(String name) {
return expandedRow.get(name);
}
@Override
public Iterable<EvaluationResult> asIterable() {
return expandedRow.values();
}
@Override
public FileDownloadPath lookupFileReference(Integer index) {
throw new IllegalArgumentException();
}
});
}
}
// last batch finished, append group by clause
if (context.getStatus() == ResultStatus.FINISHED) {
// if a statement is finished, then append all group by results
for (final Map<String, Object> rowKey : this.groupByRecords) {
ProcessDataRecord record = new ProcessDataRecord() {
@Override
public EvaluationResult lookup(String name) {
// must resolve aggregators first, because count(1) is a valid property name in appengine
Map<AggregationEvaluator, Aggregator> aggMap = groupByTable.row(rowKey);
for (AggregationEvaluator e : aggMap.keySet()) {
if (e.getText().equals(name)) {
Aggregator agg = aggMap.get(e);
if (agg == null) {
// for aggregation ONLY query
// when there is no record, the empty group by function is still trying to resolve aggregator
return new EvaluationResult(null).withTitle(e.getText());
} else {
return new EvaluationResult(agg.getResult()).withTitle(e.getText());
}
}
}
// fallback with other evaluators
return new EvaluationResult(rowKey.get(name)).withTitle(name);
}
@Override
public Iterable<EvaluationResult> asIterable() {
return transform(rowKey.keySet(), new Function<String, EvaluationResult>(){
@Override
public EvaluationResult apply(String name) {
return new EvaluationResult(rowKey.get(name)).withTitle(name);
}
});
}
@Override
public FileDownloadPath lookupFileReference(Integer index) {
throw new IllegalArgumentException();
}
};
// process having clause
if (stmt.rejectedByHavingClause(record)) {
continue;
}
final Map<String, EvaluationResult> resultRow = newLinkedHashMap();
for (Evaluator e : selectItems) {
resultRow.put(e.getText(), e.evaluate(record));
}
output.addRecord(new ProcessDataRecord() {
Map<String, EvaluationResult> expandedRow = expandSelectAllAndResolveDuplicateName(resultRow);
@Override
public EvaluationResult lookup(String name) {
return expandedRow.get(name);