[Mondrian] when iif has a tuple and a member as its arguments we get an exception

Harun Pathan harunap at gmail.com
Thu Jan 31 09:53:53 EST 2008


When we run this mdx we get an error stacktrace for which is as below.

MEMBER [Gender].agg
AS 'IIF(1=1, ([Gender].[All Gender],measures.[unit
sales]),([Gender].[All Gender]) )', SOLVE_ORDER = 4
SELECT {[Measures].[unit sales]} ON 0,
{{[Gender].[Gender].MEMBERS},{([Gender].agg)}} on 1 FROM sales

Caused by: mondrian.olap.MondrianException: Mondrian Error:Internal
error: could not derive type
	at mondrian.resource.MondrianResource$_Def0.ex(MondrianResource.java:777)
	at mondrian.olap.Util.newInternal(Util.java:1333)
	at mondrian.olap.fun.FunDefBase.createCall(FunDefBase.java:245)
	at mondrian.mdx.UnresolvedFunCall.accept(UnresolvedFunCall.java:101)
	at mondrian.olap.Query$StackValidator.validate(Query.java:1229)
	at mondrian.olap.Formula.accept(Formula.java:131)
	at mondrian.olap.Query$StackValidator.validate(Query.java:1304)
	at mondrian.olap.Query.resolve(Query.java:571)
	at mondrian.olap.Query.resolve(Query.java:433)
	at mondrian.olap.Query.<init>(Query.java:217)
	at mondrian.olap.Query.<init>(Query.java:177)
	at mondrian.olap.Parser.makeQuery(Parser.java:850)
	at mondrian.olap.CUP$Parser$actions.CUP$Parser$do_action(Parser.java:1683)
	at mondrian.olap.Parser.do_action(Parser.java:684)
	at java_cup.runtime.lr_parser.parse(lr_parser.java:569)
	at mondrian.olap.Parser.parseInternal(Parser.java:754)
What we saw is that when the iif function is resolved it tries to get
a common result type between its arguments.There is no common
resulttype between a TupleType and a MemberType.
Currently in the TupleType the result type gets resolved to a
ScalarType when the other type is a ScalarType and to a TupleType when
the other one is a Tuple and in all other cases null.
Currently in the MemberType the result type gets resolved to null for
the above example when the incoming tuple has more than one argument
in it.
is it valid if the return type is resolved to a ScalarType when the
IIF gets a TupleType and MemberType as its arguments.

Code changes in TupleType :
//currently this check isnt there.
if (type instanceof MemberType) {
            return getValueType().computeCommonType(type, conversionCount);

Code changes in MemberType:

if (type instanceof TupleType) {
      TupleType tupleType = (TupleType) type;
       if (tupleType.elementTypes.length == 1) {
               return new TupleType(new Type[]
{type}).computeCommonType(tupleType, conversionCount);
            } else {
computeCommonType(tupleType.getValueType(),conversionCount);// this is
the code change, earlier returned null

More information about the Mondrian mailing list