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) 2006-2011 Pentaho 008// All Rights Reserved. 009*/ 010package mondrian.olap.fun; 011 012import mondrian.calc.*; 013import mondrian.calc.impl.AbstractBooleanCalc; 014import mondrian.mdx.ResolvedFunCall; 015import mondrian.olap.*; 016 017/** 018 * Definition of the <code>IS</code> MDX function. 019 * 020 * @see IsNullFunDef 021 * @author jhyde 022 * @since Mar 23, 2006 023 */ 024class IsFunDef extends FunDefBase { 025 static final ReflectiveMultiResolver Resolver = 026 new ReflectiveMultiResolver( 027 "IS", 028 "<Expression> IS <Expression>", 029 "Returns whether two objects are the same", 030 new String[] {"ibmm", "ibll", "ibhh", "ibdd", "ibtt"}, 031 IsFunDef.class); 032 033 public IsFunDef(FunDef dummyFunDef) { 034 super(dummyFunDef); 035 } 036 037 public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) { 038 final int category = call.getArg(0).getCategory(); 039 switch (category) { 040 case Category.Tuple: 041 final TupleCalc tupleCalc0 = compiler.compileTuple(call.getArg(0)); 042 final TupleCalc tupleCalc1 = compiler.compileTuple(call.getArg(1)); 043 return new AbstractBooleanCalc( 044 call, new Calc[] {tupleCalc0, tupleCalc1}) 045 { 046 public boolean evaluateBoolean(Evaluator evaluator) { 047 Member[] o0 = tupleCalc0.evaluateTuple(evaluator); 048 Member[] o1 = tupleCalc1.evaluateTuple(evaluator); 049 return equalTuple(o0, o1); 050 } 051 }; 052 default: 053 assert category == call.getArg(1).getCategory(); 054 final Calc calc0 = compiler.compile(call.getArg(0)); 055 final Calc calc1 = compiler.compile(call.getArg(1)); 056 return new AbstractBooleanCalc(call, new Calc[] {calc0, calc1}) { 057 public boolean evaluateBoolean(Evaluator evaluator) { 058 Object o0 = calc0.evaluate(evaluator); 059 Object o1 = calc1.evaluate(evaluator); 060 return o0.equals(o1); 061 } 062 }; 063 } 064 } 065} 066 067// End IsFunDef.java