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