<!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> </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 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> </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> </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> static final FunDefBase
TUPLE_INSTANCE =<BR> new
IifFunDef(<BR>
"IIf",<BR>
"Returns one of two tuples determined by a logical
test.",<BR>
"ftbtt")<BR>
{<BR> public
Calc compileCall(ResolvedFunCall call, ExpCompiler compiler)
{<BR>
final BooleanCalc booleanCalc
=<BR>
compiler.compileBoolean(call.getArg(0));<BR>
final Calc calc1 =
compiler.compileTuple(call.getArg(1));<BR>
final Calc calc2 =
compiler.compileTuple(call.getArg(2));<BR>
return new GenericCalc(call)
{<BR>
public Object evaluate(Evaluator evaluator)
{<BR>
final boolean b
=<BR>
booleanCalc.evaluateBoolean(evaluator);<BR>
Calc calc = b ? calc1 :
calc2;<BR>
return
calc.evaluate(evaluator);<BR>
}<BR><BR>
public Calc[] getCalcs()
{<BR>
return new Calc[] {booleanCalc, calc1,
calc2};<BR>
}<BR>
};<BR>
}<BR> };<BR><BR><BR>By incrementing
conversion count for Numeric and value instance the
IIF(<expression>,<Tuple>,<Tuple>) 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> public Object
evaluate(Evaluator evaluator) {<BR>
final Member[] members =
tupleCalc.evaluateTuple(evaluator);<BR>
if (members == null)
{<BR> return
null;<BR>
}<BR> for (int i = 0; i <
members.length; i++)
{<BR>
savedMembers[i] =
evaluator.setContext(members[i]);<BR>
}<BR> final Object o =
evaluator.evaluateCurrent();<BR><BR> //Currently it is just
evaluator.setContext(savedMembers[i]);<BR>
for (int i = 0; i < members.length; i++)
{<BR>
evaluator.setContext(savedMembers[i]);<BR>
}<BR> return
o;<BR> }<BR><BR>Is there a better alternative to doing this
?<SPAN class=179110116-08022008><FONT face=Verdana color=#000080
size=2> </FONT></SPAN></DIV>
<DIV><SPAN class=179110116-08022008><FONT face=Verdana color=#000080
size=2></FONT></SPAN> </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> </DIV>
<DIV dir=ltr><SPAN class=179110116-08022008><FONT face=Verdana color=#000080
size=2><FONT face="Times New Roman" color=#000000
size=3> final Member[] members =
tupleCalc.evaluateTuple(evaluator);<BR>
if (members == null)
{<BR> return
null;<BR> }</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> Member[] savedMembers = new
Member[members.length];</FONT><BR> for
(int i = 0; i < members.length; i++)
{<BR>
savedMembers[i] =
evaluator.setContext(members[i]);<BR>
}</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(<expression>,<Member>,<Tuple>) and
IIF(<expression>,<Tuple>,<Member>),<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> </FONT></SPAN></DIV>
<DIV class=gmail_quote><SPAN
class=179110116-08022008></SPAN> </DIV></BLOCKQUOTE>
<DIV class=gmail_quote dir=ltr><SPAN class=179110116-08022008><FONT face=Verdana
color=#000080 size=2>I agree.</FONT> </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>
if (type instanceof TupleType)
{<BR>
TupleType tupleType = (TupleType)
type;<BR> if
(tupleType.elementTypes.length == 1)
{<BR>
return new TupleType(new Type[]
{type}).computeCommonType(tupleType,<BR>
conversionCount);<BR>
} else
{<BR>
return tupleType.computeCommonType(this,conversionCount); // Currently it
is:computeCommonType(tupleType.getValueType,
conversionCount);<BR>
}<BR>
}<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> </FONT></SPAN></DIV>
<DIV class=gmail_quote><SPAN class=179110116-08022008><FONT face=Verdana
color=#000080 size=2></FONT></SPAN> </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(<Boolean>, <Tuple>, <Tuple>) 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> </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> </FONT></SPAN></DIV></BLOCKQUOTE>
<DIV class=gmail_quote dir=ltr><SPAN class=179110116-08022008><FONT face=Verdana
color=#000080 size=2>Julian</FONT> </SPAN></DIV></BODY></HTML>