[Mondrian] CurrentDateMember udf

Julian Hyde julianhyde at speakeasy.net
Tue Aug 28 19:47:17 EDT 2007


People writing MDX should not make any assumptions about how many times a
UDF is executed. Mondrian has to assume that a function depends on the
entire dimensional context (that is, the current member of each dimension),
so to be safe, it will typically execute it every time it is needed.

If you really want to ensure that a UDF is executed only once, you can use a
parameter. Something like this:

WITH MEMBER [Time].[Today] AS 
 ' Parameter("now", CurrentDateMember([Time], '[YYYY].[MM].[DD]')) '
SELECT {[Time].[Today]} ON 0
 ...

Using parameters for this purpose is a bit of a back. I guess we could add a
function 'Cache(<Expression>)' to asks mondrian to cache expression results:

WITH MEMBER [Time].[Today] AS 
 ' Cache(CurrentDateMember([Time], '[YYYY].[MM].[DD]')) '
SELECT {[Time].[Today]} ON 0
 ...

And/or, the UDF SPI could allow a UDF to declare which dimensions it depends
on. That sounds a bit complicated, though.

Re. CurrentDateMember specifically, it's a good idea to make it use the time
that the query started executing. You could add a field to RolapResult for
that, initialized when a RolapResult is created.

Unless & until we make UDFs declare their dependencies, it is not safe for
the system to automatically cache their results, so it would also be a good
idea to have CurrentDateMember cache the results for a particular timestamp
string. 

Julian




More information about the Mondrian mailing list