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;Level&gt;.Dimension</code>
019 * MDX builtin function.
020 *
021 * @author jhyde
022 * @since Jul 20, 2009
023 */
024class LevelDimensionFunDef extends FunDefBase {
025    public static final FunDefBase INSTANCE = new LevelDimensionFunDef();
026
027    public LevelDimensionFunDef() {
028        super(
029            "Dimension",
030            "Returns the dimension that contains a specified level.", "pdl");
031    }
032
033    public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler)
034    {
035        final LevelCalc levelCalc =
036            compiler.compileLevel(call.getArg(0));
037        return new AbstractDimensionCalc(call, new Calc[] {levelCalc}) {
038            public Dimension evaluateDimension(Evaluator evaluator) {
039                Level level =  levelCalc.evaluateLevel(evaluator);
040                return level.getDimension();
041            }
042        };
043    }
044}
045
046// End LevelDimensionFunDef.java