001 /* 002 // $Id: //open/mondrian/src/main/mondrian/olap/fun/StdevFunDef.java#4 $ 003 // This software is subject to the terms of the Common Public License 004 // Agreement, available at the following URL: 005 // http://www.opensource.org/licenses/cpl.html. 006 // Copyright (C) 2006-2007 Julian Hyde 007 // All Rights Reserved. 008 // You must accept the terms of that agreement to use this software. 009 */ 010 package mondrian.olap.fun; 011 012 import mondrian.olap.FunDef; 013 import mondrian.olap.Evaluator; 014 import mondrian.olap.Dimension; 015 import mondrian.calc.Calc; 016 import mondrian.calc.ExpCompiler; 017 import mondrian.calc.ListCalc; 018 import mondrian.calc.impl.ValueCalc; 019 import mondrian.calc.impl.AbstractDoubleCalc; 020 import mondrian.mdx.ResolvedFunCall; 021 022 import java.util.List; 023 024 /** 025 * Definition of the <code>Stdev</code> builtin MDX function, and its alias 026 * <code>Stddev</code>. 027 * 028 * @author jhyde 029 * @version $Id: //open/mondrian/src/main/mondrian/olap/fun/StdevFunDef.java#4 $ 030 * @since Mar 23, 2006 031 */ 032 class StdevFunDef extends AbstractAggregateFunDef { 033 static final ReflectiveMultiResolver StdevResolver = new ReflectiveMultiResolver( 034 "Stdev", 035 "Stdev(<Set>[, <Numeric Expression>])", 036 "Returns the standard deviation of a numeric expression evaluated over a set (unbiased).", 037 new String[]{"fnx", "fnxn"}, 038 StdevFunDef.class); 039 040 static final ReflectiveMultiResolver StddevResolver = new ReflectiveMultiResolver( 041 "Stddev", 042 "Stddev(<Set>[, <Numeric Expression>])", 043 "Alias for Stdev.", 044 new String[]{"fnx", "fnxn"}, 045 StdevFunDef.class); 046 047 public StdevFunDef(FunDef dummyFunDef) { 048 super(dummyFunDef); 049 } 050 051 public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) { 052 final ListCalc listCalc = 053 compiler.compileList(call.getArg(0)); 054 final Calc calc = call.getArgCount() > 1 ? 055 compiler.compileScalar(call.getArg(1), true) : 056 new ValueCalc(call); 057 return new AbstractDoubleCalc(call, new Calc[] {listCalc, calc}) { 058 public double evaluateDouble(Evaluator evaluator) { 059 List memberList = evaluateCurrentList(listCalc, evaluator); 060 return (Double)stdev(evaluator.push(), memberList, calc, false); 061 } 062 063 public boolean dependsOn(Dimension dimension) { 064 return anyDependsButFirst(getCalcs(), dimension); 065 } 066 }; 067 } 068 } 069 070 // End StdevFunDef.java