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 32 class StdevFunDef extends AbstractAggregateFunDef { 33 static final ReflectiveMultiResolver StdevResolver = new ReflectiveMultiResolver( 34 "Stdev", 35 "Stdev(<Set>[, <Numeric Expression>])", 36 "Returns the standard deviation of a numeric expression evaluated over a set (unbiased).", 37 new String []{"fnx", "fnxn"}, 38 StdevFunDef.class); 39 40 static final ReflectiveMultiResolver StddevResolver = new ReflectiveMultiResolver( 41 "Stddev", 42 "Stddev(<Set>[, <Numeric Expression>])", 43 "Alias for Stdev.", 44 new String []{"fnx", "fnxn"}, 45 StdevFunDef.class); 46 47 public StdevFunDef(FunDef dummyFunDef) { 48 super(dummyFunDef); 49 } 50 51 public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) { 52 final ListCalc listCalc = 53 compiler.compileList(call.getArg(0)); 54 final Calc calc = call.getArgCount() > 1 ? 55 compiler.compileScalar(call.getArg(1), true) : 56 new ValueCalc(call); 57 return new AbstractCalc(call) { 58 public Object evaluate(Evaluator evaluator) { 59 List memberList = evaluateCurrentList(listCalc, evaluator); 60 return stdev(evaluator.push(), memberList, calc, false); 61 } 62 63 public Calc[] getCalcs() { 64 return new Calc[] {listCalc, calc}; 65 } 66 67 public boolean dependsOn(Dimension dimension) { 68 return anyDependsButFirst(getCalcs(), dimension); 69 } 70 }; 71 } 72 } 73 74 | Popular Tags |