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.AbstractDoubleCalc; 20 import mondrian.mdx.ResolvedFunCall; 21 22 import java.util.List ; 23 24 31 class CorrelationFunDef extends AbstractAggregateFunDef { 32 static final ReflectiveMultiResolver Resolver = new ReflectiveMultiResolver( 33 "Correlation", 34 "Correlation(<Set>, <Numeric Expression>[, <Numeric Expression>])", 35 "Returns the correlation of two series evaluated over a set.", 36 new String []{"fnxn","fnxnn"}, 37 CorrelationFunDef.class); 38 39 public CorrelationFunDef(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 calc1 = 47 compiler.compileScalar(call.getArg(1), true); 48 final Calc calc2 = call.getArgCount() > 2 ? 49 compiler.compileScalar(call.getArg(2), true) : 50 new ValueCalc(call); 51 return new AbstractDoubleCalc(call, new Calc[] {listCalc, calc1, calc2}) { 52 public double evaluateDouble(Evaluator evaluator) { 53 List memberList = evaluateCurrentList(listCalc, evaluator); 54 return correlation(evaluator.push(), 55 memberList, calc1, calc2); 56 } 57 58 public boolean dependsOn(Dimension dimension) { 59 return anyDependsButFirst(getCalcs(), dimension); 60 } 61 }; 62 } 63 } 64 65 | Popular Tags |