1 10 package mondrian.olap.fun; 11 12 import mondrian.olap.*; 13 import mondrian.calc.*; 14 import mondrian.calc.impl.AbstractCalc; 15 import mondrian.calc.impl.ValueCalc; 16 import mondrian.mdx.ResolvedFunCall; 17 18 import java.util.List ; 19 20 27 class AggregateFunDef extends AbstractAggregateFunDef { 28 static final ReflectiveMultiResolver resolver = 29 new ReflectiveMultiResolver( 30 "Aggregate", "Aggregate(<Set>[, <Numeric Expression>])", 31 "Returns a calculated value using the appropriate aggregate function, based on the context of the query.", 32 new String []{"fnx", "fnxn"}, 33 AggregateFunDef.class); 34 35 public AggregateFunDef(FunDef dummyFunDef) { 36 super(dummyFunDef); 37 } 38 39 public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) { 40 final ListCalc listCalc = compiler.compileList(call.getArg(0)); 41 final Calc calc = call.getArgCount() > 1 ? 42 compiler.compileScalar(call.getArg(1), true) : 43 new ValueCalc(call); 44 return new AbstractCalc(call) { 45 public Object evaluate(Evaluator evaluator) { 46 Aggregator aggregator = 47 (Aggregator) evaluator.getProperty( 48 Property.AGGREGATION_TYPE.name, null); 49 if (aggregator == null) { 50 throw newEvalException(null, "Could not find an aggregator in the current evaluation context"); 51 } 52 Aggregator rollup = aggregator.getRollup(); 53 if (rollup == null) { 54 throw newEvalException(null, "Don't know how to rollup aggregator '" + aggregator + "'"); 55 } 56 final List list = evaluateCurrentList(listCalc, evaluator); 57 return rollup.aggregate(evaluator.push(), list, calc); 58 } 59 60 public Calc[] getCalcs() { 61 return new Calc[] {listCalc, calc}; 62 } 63 64 public boolean dependsOn(Dimension dimension) { 65 return anyDependsButFirst(getCalcs(), dimension); 66 } 67 }; 68 } 69 } 70 71 | Popular Tags |