[Mondrian] UDF and result type
Julian Hyde
julianhyde at speakeasy.net
Tue Jul 17 11:54:09 EDT 2007
I'm guessing that the code is instantiating the type based on category (the
approximate type: integer, string, member, dimension etc.) rather than the
type returned from getReturnType.
Please log a bug and provide a testcase method to add to UdfTest.
Julian
> -----Original Message-----
> From: mondrian-bounces at pentaho.org
> [mailto:mondrian-bounces at pentaho.org] On Behalf Of Anton Nikitin
> Sent: Tuesday, July 17, 2007 4:48 AM
> To: 'Mondrian developer mailing list'
> Subject: RE: [Mondrian] UDF and result type
>
> My case is more complex. Function accepts two arguments:
> member and dimension (not the one for first argument). Return
> type should be member from dimension, specified in 2nd parameter.
>
> I have the following definition of getReturnType() :
>
> public Type getReturnType(Type[] parameterTypes) {
> DimensionType dimType = (DimensionType) parameterTypes[1];
>
> if (dimType.getDimension()==null) {
> memberType = MemberType.Unknown;
> } else {
> memberType =
> MemberType.forHierarchy(dimType.getDimension().getHierarchy());
> }
>
> // This one provides the same error!
> //MemberType memberType =
> MemberType.forDimension(dimType.getDimension());
>
> return memberType;
> }
>
> After that I can see that resolver considers return type as a
> member from the same dimension as first argument, not the
> second one! Then (because I use this member as parameter in
> tuple expression I get the following):
>
> Caused by: mondrian.olap.MondrianException: Mondrian
> Error:Tuple contains more than one member of dimension '[2_6]'.
> at
> mondrian.resource.MondrianResource$_Def0.ex(MondrianResource.java:752)
> at
> mondrian.olap.fun.TupleFunDef.checkDimensions(TupleFunDef.java:95)
> at
> mondrian.olap.fun.TupleFunDef.getResultType(TupleFunDef.java:73)
> at mondrian.olap.fun.FunDefBase.createCall(FunDefBase.java:194)
> at
> mondrian.mdx.UnresolvedFunCall.accept(UnresolvedFunCall.java:93)
> ...
>
> Anton
>
> -----Original Message-----
> From: mondrian-bounces at pentaho.org
> [mailto:mondrian-bounces at pentaho.org] On Behalf Of Julian Hyde
> Sent: Monday, July 16, 2007 10:22 PM
> To: 'Mondrian developer mailing list'
> Subject: RE: [Mondrian] UDF and result type
>
> I just wrote a test with a function 'F(<Integer>, <String>)
> returns <String>'. FunDefBase.guessResultType would guess
> that this returns an integer, but that didn't happen. The
> test worked fine, because I implemented
>
>
> public Type getReturnType(Type[] parameterTypes) {
> return new StringType();
> }
>
> in my UDF.
>
> Julian
>
> > -----Original Message-----
> > From: mondrian-bounces at pentaho.org
> > [mailto:mondrian-bounces at pentaho.org] On Behalf Of Anton Nikitin
> > Sent: Monday, July 16, 2007 3:33 AM
> > To: 'Mondrian developer mailing list'
> > Subject: [Mondrian] UDF and result type
> >
> >
> > Hello.
> >
> > I have a question about User Defined Functions.
> >
> > AFAIK, UDF is resolved into UdfResolver.UdfFunDef instance which
> > derives from FunDefBase.
> > It forces using getResultType() from FunDefBase which doesn't work
> > correctly in our case (FunDefBase.guessResultType()
> provides incorrect
> > result). In turn, it is impossible to implement anything in
> UDF class
> > to correct its behavior (in contrast to FunDef-based
> approach, where I
> > could simply override getResultType()).
> >
> > Any thoughts, workarounds?
> >
> > Thanks,
> >
> > Anton
> >
> >
> > _______________________________________________
> > Mondrian mailing list
> > Mondrian at pentaho.org
> > http://lists.pentaho.org/mailman/listinfo/mondrian
> >
>
> _______________________________________________
> Mondrian mailing list
> Mondrian at pentaho.org
> http://lists.pentaho.org/mailman/listinfo/mondrian
>
> _______________________________________________
> Mondrian mailing list
> Mondrian at pentaho.org
> http://lists.pentaho.org/mailman/listinfo/mondrian
>
More information about the Mondrian
mailing list