[Mondrian] UDFs and Util.java changelist 9827

Reidmiller, Chuck creidmiller at cincom.com
Wed May 20 09:39:49 EDT 2009



Thanks for your response.  I think you have identified the behavior
change associated with 9827.  Before this change, the CalcImpl
constructor did not instantiate the UDF class, so an attempt was not
made to invoke the default constructor as now occurs when Util.createUdf
is called.  


The UDFs use a constructor with a  string argument per  the  UDF doc in
"How to Design a Mondrian Schema":


If a user-defined function has a public constructor with one string
argument, Mondrian will pass in the function's name. Why? This allows
you to define two or more user-defined functions using the same class.


This capability is then demonstrated in the example for the
PlusOrMinusOneUdf class.




From: mondrian-bounces at pentaho.org [mailto:mondrian-bounces at pentaho.org]
On Behalf Of Julian Hyde
Sent: Wednesday, May 20, 2009 3:58 AM
To: 'Mondrian developer mailing list'
Cc: 'Rushan Chen'
Subject: RE: [Mondrian] UDFs and Util.java changelist 9827




Are you claiming that behavior changed in 9827? It seems to me that a
block of code was moved from GlobalFunTable to Util.createUdf()
essentially unchanged.


I do see that UdfResolver.CalcImpl's constructor gets the class of a UDF
and passes it to Util.createUdf to create another instance of the same
UDF. That seems a bit wasteful - or maybe the author wanted to clone the
UDF so that each instance can use instance variables as workspace - but
it's not wrong.


Rushan, can you comment on your change at line 159 of UdfResolver?


UserDefinedFunction's javadoc is explicit about the default constructor:
"The class must have a public, zero-arguments constructor, be on
Mondrian's runtime class-path, and be referenced from the schema file".


Can you explain why you think we need to support UDF constructors that
take a 'String name' parameter?





	From: mondrian-bounces at pentaho.org
[mailto:mondrian-bounces at pentaho.org] On Behalf Of Reidmiller, Chuck
	Sent: Monday, May 18, 2009 7:20 AM
	To: Mondrian at pentaho.org
	Subject: [Mondrian] UDFs and Util.java changelist 9827

	We have a few UDFs that were developed against Mondrian 2.3.2.
I recently attempted to use the schema with these UDFs against Mondrian
3.0 and ran into this error for the GetExtractDate UDF:


	Caused by: mondrian.olap.MondrianException: Mondrian
Error:Failed to load user-defined function '': class
'mondrian.udf.GetExtractDate' does not implement the required interface


	The public constructor for GetExtractDate takes a string
argument in order to get the function name:


	    public GetExtractDate(String name){


	but the createUdf method of Util  is set up to call a default
constructor that has no argument.  The createUdf method appears to have
been added on 2007/08/29 with changelist 9827.  I have gotten past the
problem by overloading createUDF via: 


	    public static UserDefinedFunction createUdf(Class<?>

	                                        String name) {


	which includes code borrowed from defineFunction of RolapSchema
to call the UDF with a string argument when applicable.  In addition, I
changed the CalcImpl constructor in UdfResolver to invoke the overloaded
createUdf with the function name:


	this.udf = Util.createUdf(udf.getClass(), udf.getName());


	Any comments from folks who know the code better than me?


	Thanks, Chuck


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

More information about the Mondrian mailing list