use of org.apache.geode.cache.query.internal.aggregate.MaxMin in project geode by apache.
the class CompiledAggregateFunction method evaluate.
@Override
public Object evaluate(ExecutionContext context) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
boolean isPRQueryNode = context.getIsPRQueryNode();
boolean isBucketNode = context.getBucketList() != null;
switch(this.aggFuncType) {
case OQLLexerTokenTypes.SUM:
if (isPRQueryNode) {
return this.distinctOnly ? new SumDistinctPRQueryNode() : new Sum();
} else {
return this.distinctOnly ? (isBucketNode ? new DistinctAggregator() : new SumDistinct()) : new Sum();
}
case OQLLexerTokenTypes.MAX:
return new MaxMin(true);
case OQLLexerTokenTypes.MIN:
return new MaxMin(false);
case OQLLexerTokenTypes.AVG:
if (isPRQueryNode) {
return this.distinctOnly ? new AvgDistinctPRQueryNode() : new AvgPRQueryNode();
} else {
return this.distinctOnly ? (isBucketNode ? new DistinctAggregator() : new AvgDistinct()) : (isBucketNode ? new AvgBucketNode() : new Avg());
}
case OQLLexerTokenTypes.COUNT:
if (isPRQueryNode) {
return this.distinctOnly ? new CountDistinctPRQueryNode() : new CountPRQueryNode();
} else {
return this.distinctOnly ? (isBucketNode ? new DistinctAggregator() : new CountDistinct()) : new Count();
}
default:
throw new UnsupportedOperationException("Aggregate function not implemented");
}
}
use of org.apache.geode.cache.query.internal.aggregate.MaxMin in project geode by apache.
the class CompiledAggregateFunctionJUnitTest method testMaxMin.
@Test
public void testMaxMin() throws Exception {
CompiledAggregateFunction caf1 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.MAX);
ExecutionContext context1 = new ExecutionContext(null, cache);
Aggregator agg = (Aggregator) caf1.evaluate(context1);
assertTrue(agg instanceof MaxMin);
MaxMin maxMin = (MaxMin) agg;
Class maxMinClass = MaxMin.class;
Field findMax = maxMinClass.getDeclaredField("findMax");
findMax.setAccessible(true);
assertTrue((Boolean) findMax.get(maxMin));
CompiledAggregateFunction caf2 = new CompiledAggregateFunction(null, OQLLexerTokenTypes.MIN);
ExecutionContext context2 = new ExecutionContext(null, cache);
Aggregator agg1 = (Aggregator) caf2.evaluate(context1);
assertTrue(agg1 instanceof MaxMin);
MaxMin maxMin1 = (MaxMin) agg1;
assertFalse((Boolean) findMax.get(maxMin1));
}
Aggregations