1 10 package mondrian.olap.fun; 11 12 import mondrian.olap.FunDef; 13 import mondrian.olap.Evaluator; 14 import mondrian.olap.Dimension; 15 import mondrian.calc.Calc; 16 import mondrian.calc.ExpCompiler; 17 import mondrian.calc.ListCalc; 18 import mondrian.calc.impl.ValueCalc; 19 import mondrian.calc.impl.AbstractCalc; 20 import mondrian.mdx.ResolvedFunCall; 21 22 import java.util.List ; 23 24 31 class MedianFunDef extends AbstractAggregateFunDef { 32 static final ReflectiveMultiResolver Resolver = new ReflectiveMultiResolver( 33 "Median", 34 "Median(<Set>[, <Numeric Expression>])", 35 "Returns the median value of a numeric expression evaluated over a set.", 36 new String []{"fnx", "fnxn"}, 37 MedianFunDef.class); 38 39 public MedianFunDef(FunDef dummyFunDef) { 40 super(dummyFunDef); 41 } 42 43 public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) { 44 final ListCalc listCalc = 45 compiler.compileList(call.getArg(0)); 46 final Calc calc = call.getArgCount() > 1 ? 47 compiler.compileScalar(call.getArg(1), true) : 48 new ValueCalc(call); 49 return new AbstractCalc(call) { 50 public Object evaluate(Evaluator evaluator) { 51 List memberList = evaluateCurrentList(listCalc, evaluator); 52 return median(evaluator.push(), memberList, calc); 53 } 54 55 public Calc[] getCalcs() { 56 return new Calc[] {listCalc, calc}; 57 } 58 59 public boolean dependsOn(Dimension dimension) { 60 return anyDependsButFirst(getCalcs(), dimension); 61 } 62 }; 63 } 64 } 65 66 | Popular Tags |