<!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=179110116-08022008><FONT face=Verdana 
color=#000080 size=2>Harun,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=179110116-08022008><FONT face=Verdana 
color=#000080 size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=179110116-08022008><FONT face=Verdana 
color=#000080 size=2>You're approaching this exactly right. As you suspect, the 
common type between a member and tuple should be a tuple. That&nbsp;tuple can 
then be converted to a scalar, but at a conversion cost, so the system would 
prefer to keep it as a tuple.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=179110116-08022008><FONT face=Verdana 
color=#000080 size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=179110116-08022008><FONT face=Verdana 
color=#000080 size=2>See further comments inline.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=179110116-08022008><FONT face=Verdana 
color=#000080 size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=179110116-08022008><FONT face=Verdana 
color=#000080 size=2>Julian</FONT></SPAN></DIV><BR>
<BLOCKQUOTE dir=ltr 
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> Friday, February 08, 2008 5:15 AM<BR><B>To:</B> 
  mondrian@pentaho.org<BR><B>Subject:</B> [Mondrian] RE: When iif has tupletypes 
  with unequal lengthsasarguments, we get an exception<BR></FONT><BR></DIV>
  <DIV></DIV>
  <DIV class=gmail_quote>
  <DIV>Sorry for late reply. We have been working on this issue, and added a new 
  IIF Tuple instance as <BR><BR>&nbsp;&nbsp;&nbsp; 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 tuples 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><BR>By incrementing 
  conversion count for Numeric and value instance the 
  IIF(&lt;expression&gt;,&lt;Tuple&gt;,&lt;Tuple&gt;) version gets resolved as 
  the best match.<BR><BR>We have added a rule to create a commontype between two 
  tuples of unequal sizes as a larger tuple with scalar types for the extra 
  element types.<BR><BR>As the common tuple might be larger than the smaller 
  original one the savedMembers array in TupleValueCalc needs to be equal to the 
  size of the <BR>tuple evaluated by it.<BR><BR>&nbsp;&nbsp;&nbsp; public Object 
  evaluate(Evaluator evaluator) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  final Member[] members = 
  tupleCalc.evaluateTuple(evaluator);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  if (members == null) 
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 
  null;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; 
  members.length; i++) 
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  savedMembers[i] = 
  evaluator.setContext(members[i]);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; final Object o = 
  evaluator.evaluateCurrent();<BR><BR>&nbsp;&nbsp;&nbsp; //Currently it is just 
  evaluator.setContext(savedMembers[i]);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  for (int i = 0; i &lt; members.length; i++) 
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  evaluator.setContext(savedMembers[i]);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 
  o;<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>Is there a better alternative to doing this 
  ?<SPAN class=179110116-08022008><FONT face=Verdana color=#000080 
  size=2>&nbsp;</FONT></SPAN></DIV>
  <DIV><SPAN class=179110116-08022008><FONT face=Verdana color=#000080 
  size=2></FONT></SPAN>&nbsp;</DIV></DIV></BLOCKQUOTE>
<DIV dir=ltr><SPAN class=179110116-08022008><FONT face=Verdana color=#000080 
size=2>Making savedMembers a member of the class was a slight optimization that 
doesn't apply anymore. Make it a local variable, and it should just 
work:</FONT></SPAN></DIV>
<DIV dir=ltr><SPAN class=179110116-08022008><FONT face=Verdana color=#000080 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr><SPAN class=179110116-08022008><FONT face=Verdana color=#000080 
size=2><FONT face="Times New Roman" color=#000000 
size=3>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; final Member[] members = 
tupleCalc.evaluateTuple(evaluator);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
if (members == null) 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 
null;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</FONT></FONT></SPAN></DIV>
<DIV dir=ltr><SPAN class=179110116-08022008><FONT face=Verdana color=#000080 
size=2><FONT face="Times New Roman" color=#000000 size=3><FONT face=Verdana 
color=#000080 size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Member[] savedMembers = new 
Member[members.length];</FONT><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for 
(int i = 0; i &lt; members.length; i++) 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
savedMembers[i] = 
evaluator.setContext(members[i]);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
}</FONT><BR></DIV></FONT></SPAN>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000080 2px solid; MARGIN-RIGHT: 0px">
  <DIV class=gmail_quote>But this fix failed to work for 
  IIF(&lt;expression&gt;,&lt;Member&gt;,&lt;Tuple&gt;) and 
  IIF(&lt;expression&gt;,&lt;Tuple&gt;,&lt;Member&gt;),<BR>because in ealier fix 
  we returned a scalar type as a common type between member and a tuple. <BR>But 
  when these IIF gets resolved they gets resolved to TUPLE_INSTANCE, where in we 
  compile tuples and not scalars.<BR><BR>To fix this, we are thinking to change 
  the common type between a tuple of one Member and Tuple to a larger Tuple as 
  above.<SPAN class=179110116-08022008><FONT face=Verdana color=#000080 
  size=2>&nbsp;</FONT></SPAN></DIV>
  <DIV class=gmail_quote><SPAN 
class=179110116-08022008></SPAN>&nbsp;</DIV></BLOCKQUOTE>
<DIV class=gmail_quote dir=ltr><SPAN class=179110116-08022008><FONT face=Verdana 
color=#000080 size=2>I agree.</FONT>&nbsp;</SPAN></DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000080 2px solid; MARGIN-RIGHT: 0px"><SPAN 
  class=179110116-08022008><FONT face=Verdana color=#000080 
size=2></FONT></SPAN>
  <DIV 
  class=gmail_quote><BR><BR>MemberType:<BR><BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  if (type instanceof TupleType) 
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  TupleType tupleType = (TupleType) 
  type;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if 
  (tupleType.elementTypes.length == 1) 
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  return new TupleType(new Type[] 
  {type}).computeCommonType(tupleType,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  conversionCount);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  } else 
  {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  return tupleType.computeCommonType(this,conversionCount); // Currently it 
  is:computeCommonType(tupleType.getValueType, 
  conversionCount);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  }<BR><BR><BR>TupleType:<BR><BR>In TupleType, we create a new tupleType as the 
  commontype for the MemberType and follow the same logic which is used in case 
  of two tuples.<BR><BR>Is it valid?<SPAN class=179110116-08022008><FONT 
  face=Verdana color=#000080 size=2>&nbsp;</FONT></SPAN></DIV>
  <DIV class=gmail_quote><SPAN class=179110116-08022008><FONT face=Verdana 
  color=#000080 size=2></FONT></SPAN>&nbsp;</DIV></BLOCKQUOTE>
<DIV class=gmail_quote dir=ltr><SPAN class=179110116-08022008><FONT face=Verdana 
color=#000080 size=2>It should be valid. It might be possible to ONLY have a 
Iif(&lt;Boolean&gt;, &lt;Tuple&gt;, &lt;Tuple&gt;) and if one of the args was a 
member it would implicitly convert to tuple.</FONT></SPAN></DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000080 2px solid; MARGIN-RIGHT: 0px">
  <DIV class=gmail_quote><SPAN class=179110116-08022008>&nbsp;</SPAN>Or do you 
  think creating different IIF instances for <BR>IIF(Expression, Member, Tuple) 
  and IIF(Expression, Tuple, Member) is a good idea.<BR><BR><BR>We tried MDXs 
  with following IIFs and all are working with the fixes mentioned 
  above:<BR><BR>IIF(Expression, Member, Tuple)<BR>IIF(Expression, Tuple, 
  Member)<BR>IIF(Expression, Tuple, Tuple) // Tuples of same 
  length<BR>IIF(Expression, Tuple, Tuple) //Tuples of different 
  length<BR>IIF(Expression, Tuple, Tuple) //Tuples with different order of 
  element Types<SPAN class=179110116-08022008><FONT face=Verdana color=#000080 
  size=2>&nbsp;</FONT></SPAN></DIV></BLOCKQUOTE>
<DIV class=gmail_quote dir=ltr><SPAN class=179110116-08022008><FONT face=Verdana 
color=#000080 size=2>Julian</FONT>&nbsp;</SPAN></DIV></BODY></HTML>