<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6001.17052" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=721302421-05022008><FONT face=Verdana 
color=#000080 size=2>A version of Iif that takes arguments of the form 
Iif(&lt;Boolean&gt;, &lt;Tuple&gt;, &lt;Tuple&gt;) is the right approach. You 
are noticing that a &lt;Tuple&gt; can implicitly be converted into a 
&lt;Scalar&gt;, and therefore any call to that form of Iif should also match a 
call to Iif(&lt;Boolean&gt;, &lt;Scalar&gt;, &lt;Scalar&gt;) but that conversion 
comes at a cost of increasing conversionCount, and therefore the validator 
should prefer the former form.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=721302421-05022008><FONT face=Verdana 
color=#000080 size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=721302421-05022008><FONT face=Verdana 
color=#000080 size=2>Maybe you need to make sure that the implicit conversion 
from Tuple to Scalar is incrementing conversionCount.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=721302421-05022008><FONT face=Verdana 
color=#000080 size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=721302421-05022008><FONT face=Verdana 
color=#000080 size=2>Also, you will need to change the rules so that given two 
tuple types (A, B) and (A, B, C) the common type is (A, B, C). More generally 
the common type for (A, B) and (B, C) is (A, B, C). You get the 
idea.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=721302421-05022008><FONT face=Verdana 
color=#000080 size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=721302421-05022008><FONT face=Verdana 
color=#000080 size=2>Why is this valid? Because the expression ([Gender].[F]) is 
equivalent to ([Gender].[F], [Measures].CurrentMember) -- it always returns the 
same result -- and therefore you can safely broaden a tuple 
type.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=721302421-05022008><FONT face=Verdana 
color=#000080 size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=721302421-05022008><FONT face=Verdana 
color=#000080 size=2>Julian</FONT></SPAN></DIV><BR>
<BLOCKQUOTE 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000080 2px solid; MARGIN-RIGHT: 0px">
  <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
  <HR tabIndex=-1>
  <FONT face=Tahoma size=2><B>From:</B> mondrian-bounces@pentaho.org 
  [mailto:mondrian-bounces@pentaho.org] <B>On Behalf Of </B>Harun 
  Pathan<BR><B>Sent:</B> Tuesday, February 05, 2008 3:21 AM<BR><B>To:</B> 
  mondrian@pentaho.org<BR><B>Subject:</B> [Mondrian] When iif has tupletypes 
  with unequal lengths asarguments, we get an exception<BR></FONT><BR></DIV>
  <DIV></DIV>Hi Julian,<BR>Sorry for creating a new post, I did not receive your 
  reply in my mailbox.<BR>Thanks for the quick review on the solution we came up 
  with.<BR>We totally agree that we need to put in the best solution to the 
  problem and not the one that works.After more detailed analysis we found that 
  it is a lot more <BR>involved and it would be extremely helpful if we could 
  get your insight on the points mentioned 
  below.<BR><BR>MDX:<BR><BR>WITH<BR>MEMBER [Gender].agg<BR>AS 
  'IIF(Measures.currentMember is [Measures].[Unit Sales], ([Store].[All 
  Stores],[Gender].[All Gender],measures.[unit sales]),<BR>([Store].[All 
  Stores],[Gender].[All Gender]) )', SOLVE_ORDER = 4<BR>SELECT {[Measures].[unit 
  sales]} ON 0,<BR>{{[Gender].[Gender].MEMBERS},{([Gender].agg)}} on 1 FROM 
  sales<BR><BR><BR>In the above MDX the common return type in the iif is a 
  TupleType.<BR>In the first tuple we have a measure and hence we know that the 
  tuple evaluates to a numeric value and we can compile it to yield a scalar 
  result in the IIF.<BR>In the second tuple we dont know the return type while 
  the iif is getting resolved.<BR><BR>When the iif is resolved it gets resolved 
  to <BR><BR>1) IIF(boolean,Numeric expression,Numeric expression) 
  currently<BR><BR>We tried adding a new IIF(boolean,Tuple,Tuple) definition 
  <BR><BR>static final FunDefBase TUPLE_INSTANCE 
  =<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new 
  IifFunDef(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  "IIf",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  "Returns one of two numeric values determined by a logical 
  test.",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  "ftbtt")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public 
  Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) 
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  final BooleanCalc booleanCalc 
  =<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  compiler.compileBoolean(call.getArg(0));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  final Calc calc1 = 
  compiler.compileTuple(call.getArg(1));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  final Calc calc2 = 
  compiler.compileTuple(call.getArg(2));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  return new GenericCalc(call) 
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  public Object evaluate(Evaluator evaluator) 
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  final boolean b 
  =<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  booleanCalc.evaluateBoolean(evaluator);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  Calc calc = b ? calc1 : 
  calc2;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  return 
  calc.evaluate(evaluator);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  }<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  public Calc[] getCalcs() 
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  return new Calc[] {booleanCalc, calc1, 
  calc2};<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  };<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<BR><BR>but we end up 
  resolving to two IIF definitions ( Numeric Instance and Tuple Instance ) and 
  hence errors out.<BR><BR>Would it be right to create a commontype between the 
  two tuples as TupleType(MemberType,MemberType ,ScalarType) wherein we assume 
  that the common types for the <BR>extra parameters in the larger tuple are 
  scalar types.But this still leaves us with the issue of two IIFs getting 
  resolved.<BR>We tried commenting out the numeric one and it 
works.<BR></BLOCKQUOTE></BODY></HTML>