001/*
002// This software is subject to the terms of the Eclipse Public License v1.0
003// Agreement, available at the following URL:
004// http://www.eclipse.org/legal/epl-v10.html.
005// You must accept the terms of that agreement to use this software.
006//
007// Copyright (C) 2009-2009 Pentaho and others
008// All Rights Reserved.
009*/
010package mondrian.olap.fun;
011
012import mondrian.calc.*;
013import mondrian.calc.impl.AbstractDimensionCalc;
014import mondrian.mdx.ResolvedFunCall;
015import mondrian.olap.*;
016
017/**
018 * Definition of the <code>&lt;Measure&gt;.Dimension</code>
019 * MDX builtin function.
020 *
021 * @author jhyde
022 * @since Jul 20, 2009
023 */
024class MemberDimensionFunDef extends FunDefBase {
025    public static final FunDefBase INSTANCE = new MemberDimensionFunDef();
026
027    private MemberDimensionFunDef() {
028        super(
029            "Dimension",
030            "Returns the dimension that contains a specified member.", "pdm");
031    }
032
033    public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler)
034    {
035        final MemberCalc memberCalc =
036            compiler.compileMember(call.getArg(0));
037        return new AbstractDimensionCalc(call, new Calc[] {memberCalc})
038        {
039            public Dimension evaluateDimension(Evaluator evaluator) {
040                Member member = memberCalc.evaluateMember(evaluator);
041                return member.getDimension();
042            }
043        };
044    }
045}
046
047// End MemberDimensionFunDef.java