[Mondrian] Problem with user defined function returning a List

Pappyn Bart Bart.Pappyn at vandewiele.com
Fri May 4 03:35:13 EDT 2007


Julian,
 
I want to fix this issue in order to let my application run against the
latest mondrian build, but I need some feedback.
 
This query was working in pre mondrian 2.3.2 :
 
SELECT NON EMPTY crossjoin(VDWIIfSet([Shift.Shift variable].[All Shift
variables].[Current shift].Children, CrossJoin([Shift.Shift
variable].[All Shift variables].[Current shift].Children, [Loom
type].[All loom types].Children), IsEmpty(([Loom type].[All Loom
types].[Backup], [Measures].[Work time]))), {[Measures].[Capacity
level], [Measures].[CL 10SMA], [Measures].[Machine eff], [Measures].[ME
10SMA], [Measures].[Weaver eff], [Measures].[WE 10SMA],
[Measures].[Overall eff], [Measures].[OE 10SMA]}) ON columns, NON EMPTY
[Time].[All times].children ON rows FROM [Event] WHERE [Date.Date
variable D].[All Date variable Ds].[Today]
 
Now failing with :
Caused by: mondrian.olap.ResultStyleException: Mondrian Error:Wanted
ResultStyles: {ITERABLE,LIST,MUTABLE_LIST} but got: VALUE
	at
mondrian.olap.ResultStyleException.generateBadType(ResultStyleException.
java:56)
	at
mondrian.olap.fun.FunUtil.checkIterListResultStyles(FunUtil.java:99)
	at
mondrian.olap.fun.CrossJoinFunDef.compileCallIterable(CrossJoinFunDef.ja
va:139)
	at
mondrian.olap.fun.CrossJoinFunDef.compileCall(CrossJoinFunDef.java:100)
	at mondrian.mdx.ResolvedFunCall.accept(ResolvedFunCall.java:150)
	at
mondrian.calc.impl.AbstractExpCompiler.compile(AbstractExpCompiler.java:
64)
	at
mondrian.calc.impl.AbstractExpCompiler.compile(AbstractExpCompiler.java:
91)
	at mondrian.olap.QueryAxis.compile(QueryAxis.java:111)
	at mondrian.olap.Query.compile(Query.java:467)
	at mondrian.olap.Query.resolve(Query.java:405)
	at mondrian.olap.Query.<init>(Query.java:226)
	at mondrian.olap.Query.<init>(Query.java:187)
	at mondrian.olap.Parser.makeQuery(Parser.java:851)
	at
mondrian.olap.CUP$Parser$actions.CUP$Parser$do_action(Parser.java:1700)
	at mondrian.olap.Parser.do_action(Parser.java:685)
	at java_cup.runtime.lr_parser.parse(lr_parser.java:569)
	at mondrian.olap.Parser.parseInternal(Parser.java:755)
I want the UDF to be able to return list and iterable, but I am not sure
where to put the code.  I do not fully understand the way things are
working in this part of mondrian.
 
Can you give me a hint or a suggestion ?
 
Thanks,
Bart

________________________________

From: mondrian-bounces at pentaho.org [mailto:mondrian-bounces at pentaho.org]
On Behalf Of Pappyn Bart
Sent: woensdag 18 april 2007 15:14
To: Mondrian developer mailing list
Subject: [Mondrian] Problem with user defined function returning a List


Since the introduction of ITERABLE into mondrian, I have a user defined
function that is broken under some circumstances.
 
I have a user defined function, implementing an Iif() statement that
accepts Sets.  The return type is SetType(null).
 
But when using this function in a crossjoin, it fails with a
ResultStyleException, since UdfResolver and the underlying
AbstractCalc.getResultStyle() always returns VALUE.
 
Besides this problem, there is another one with user defined functions,
regardless of the return type returned by getReturnType(), mondrian
(FunDefBase.guessResultType) always looks to the first argument of the
udf to determine the result type.  So it is not possible to defined a
Iif() function with first argument the logical expression, and then the
two set arguments, since mondrian will assume that the UDF will return a
logical expression.
 
The is a snapshot of my UDF :
 
public class VDWIIfSet implements UserDefinedFunction {
    // public constructor
    public VDWIIfSet() {
    }
    
    public String getName() {
        return "VDWIIfSet";
    }
 
    public String getDescription() {
        // ahh, logical expression must not be the first since 
        // FunDefBase.guessResultType always looks at the first argument
        // to guest the result type
        return "VDWIIfSet(<Set1>, <Set2>,<Logical Expression>)";
    }
 
    public Syntax getSyntax() {
        return Syntax.Function;
    }
 
    public Type getReturnType(Type[] parameterTypes) {
        return new SetType(null);
    }
 
    public Type[] getParameterTypes() {
        return new Type[] {new SetType(null),
                           new SetType(null),
                           new BooleanType()};
    }
 
    public Object execute(Evaluator evaluator, Argument[] arguments) {
        Object list1 = arguments[0].evaluate(evaluator);
        Object list2 = arguments[1].evaluate(evaluator);        
 
        Boolean expression = (Boolean)arguments[2].evaluate(evaluator);

        
        if (expression) {
            return list1;
        } else {
            return list2;
        }
    }
 
    public String[] getReservedWords() {
        return null;
    }
}
 
Bart
 

______________________________________________________________________
This email has been scanned by the Email Security System.
______________________________________________________________________

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.pentaho.org/pipermail/mondrian/attachments/20070504/f729414f/attachment.html 


More information about the Mondrian mailing list