mondrian.rolap
Class RolapEvaluator

java.lang.Object
  extended by mondrian.rolap.RolapEvaluator
All Implemented Interfaces:
Evaluator
Direct Known Subclasses:
RolapDependencyTestingEvaluator

public class RolapEvaluator
extends Object
implements Evaluator

RolapEvaluator evaluates expressions in a dimensional environment.

The context contains a member (which may be the default member) for every dimension in the current cube. Certain operations, such as evaluating a calculated member or a tuple, change the current context. The evaluator's push(mondrian.olap.Member[]) method creates a clone of the current evaluator so that you can revert to the original context once the operation has completed.

Developers note

Many of the methods in this class are performance-critical. Where possible they are declared 'final' so that the JVM can optimize calls to these methods. If future functionality requires it, the 'final' modifier can be removed and these methods can be overridden.

Since:
10 August, 2001
Author:
jhyde
 

Nested Class Summary
protected static class RolapEvaluator.RolapEvaluatorRoot
           
 
Field Summary
protected  List<List<Member[]>> aggregationLists
          List of lists of tuples or members, rarely used, but overrides the ordinary dimensional context if set when a cell value comes to be evaluated.
protected  CellReader cellReader
           
protected  RolapEvaluator.RolapEvaluatorRoot root
           
 
Constructor Summary
  RolapEvaluator(RolapEvaluator.RolapEvaluatorRoot root)
          Creates an evaluator with no parent.
protected RolapEvaluator(RolapEvaluator.RolapEvaluatorRoot root, RolapEvaluator parent)
          Creates an evaluator.
 
Method Summary
protected  RolapEvaluator _push()
          Creates a clone of the current validator.
(package private)  void addCalcMember(Member member)
           
 void clearExpResultCache(boolean clearValidResult)
           
static Evaluator create(Query query)
          Creates an evaluator.
 boolean equals(Object obj)
          Returns true if the other object is a RolapEvaluator with identical context.
 Object evaluateCurrent()
          Calculates and returns the value of the cell at the current context.
 Object evaluateNamedSet(String name, Exp exp)
          Evaluates a named set.
 String format(Object o)
          Formats a value as a string according to the current context's format.
 String format(Object o, String formatString)
          Formats a value as a string according to the current context's format, using a given format string.
 List<List<Member[]>> getAggregationLists()
           
 Object getCachedResult(ExpCacheDescriptor cacheDescriptor)
          Simple caching of the result of an Exp.
 Locale getConnectionLocale()
          Returns the connection's locale.
 RolapMember getContext(Dimension dimension)
           
 RolapCube getCube()
          Returns the current cube.
 int getDepth()
          Returns number of ancestor evaluators.
 SqlQuery.Dialect getDialect()
           
(package private)  Member getExpanding()
          Returns the calculated member being currently expanded.
 String getFormatString()
          Returns the format string for this cell.
 int getIterationLength()
           
protected  org.apache.log4j.Logger getLogger()
           
 RolapCube getMeasureCube()
          Returns the base (non-virtual) cube that the current measure in the context belongs to.
 Member[] getMembers()
          Returns an array of the members which make up the current context.
 int getMissCount()
          Returns the number of times that this evaluator has told a lie when retrieving cell values.
 Object getParameterValue(ParameterSlot slot)
          Returns the value of a parameter, evaluating its default value if it is not set.
 Evaluator getParent()
          Returns parent evaluator.
 Object getProperty(String name, Object defaultValue)
          Retrieves the value of property name.
 Query getQuery()
          Returns the current query.
 Date getQueryStartTime()
          Returns the start time of the current query.
 SchemaReader getSchemaReader()
          Returns a SchemaReader appropriate for the current access-control context.
 List<Member> getSlicerMembers()
          Return the list of slicer members in the current evaluator context.
 int hashCode()
           
 boolean isEvalAxes()
           
 boolean isNonEmpty()
          Returns true for an axis that is NON EMPTY.
 boolean needToReturnNullForUnrelatedDimension(Member[] members)
          If IgnoreMeasureForNonJoiningDimension is set to true and one or more members are on unrelated dimension for the measure in current context then returns true.
 RuntimeException newEvalException(Object context, String s)
          Creates an exception which indicates that an error has occurred during the runtime evaluation of a function.
 Evaluator pop()
          Restores previous evaluator.
 RolapEvaluator push()
          Creates a new Evaluator with the same context as this evaluator.
 RolapEvaluator push(Member member)
          Creates a new Evaluator with the same context except for one member.
 RolapEvaluator push(Member[] members)
          Creates a new Evaluator with each given member overriding the context of the current Evaluator for its dimension.
 Evaluator pushAggregation(List<Member[]> list)
          Returns a new Aggregator whose aggregation context adds a given list of tuples, and whose dimensional context is the same as this Aggregator.
(package private)  void setCellReader(CellReader cellReader)
           
 void setContext(List<Member> memberList)
           
 Member setContext(Member member)
          Makes member the current member of its dimension.
 void setContext(Member[] members)
           
 void setEvalAxes(boolean evalAxes)
          Indicate whether the evaluator is evaluating the axes
 void setIterationLength(int length)
          Sets the iteration length for the current evaluator context
 void setNonEmpty(boolean nonEmpty)
          Sets whether an expression evaluation should filter out empty cells.
 void setSlicerContext(Member member)
          Adds a slicer member to the evaluator context, and remember it as part of the slicer.
 boolean shouldIgnoreUnrelatedDimensions()
          Checks if unrelated dimensions to the measure in the current context should be ignored.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cellReader

protected CellReader cellReader

root

protected final RolapEvaluator.RolapEvaluatorRoot root

aggregationLists

protected List<List<Member[]>> aggregationLists
List of lists of tuples or members, rarely used, but overrides the ordinary dimensional context if set when a cell value comes to be evaluated.

Constructor Detail

RolapEvaluator

protected RolapEvaluator(RolapEvaluator.RolapEvaluatorRoot root,
                         RolapEvaluator parent)
Creates an evaluator.

Parameters:
root - Root context for stack of evaluators (contains information which does not change during the evaluation)
parent - Parent evaluator, or null if this is the root

RolapEvaluator

public RolapEvaluator(RolapEvaluator.RolapEvaluatorRoot root)
Creates an evaluator with no parent.

Parameters:
root - Shared context between this evaluator and its children
Method Detail

create

public static Evaluator create(Query query)
Creates an evaluator.


getMeasureCube

public RolapCube getMeasureCube()
Returns the base (non-virtual) cube that the current measure in the context belongs to.

Specified by:
getMeasureCube in interface Evaluator
Returns:
Cube

needToReturnNullForUnrelatedDimension

public boolean needToReturnNullForUnrelatedDimension(Member[] members)
If IgnoreMeasureForNonJoiningDimension is set to true and one or more members are on unrelated dimension for the measure in current context then returns true.

Specified by:
needToReturnNullForUnrelatedDimension in interface Evaluator
Parameters:
members - dimensions for the members need to be checked whether related or unrelated
Returns:
boolean

getLogger

protected final org.apache.log4j.Logger getLogger()

getMembers

public final Member[] getMembers()
Description copied from interface: Evaluator
Returns an array of the members which make up the current context.

Specified by:
getMembers in interface Evaluator

getAggregationLists

public final List<List<Member[]>> getAggregationLists()

setCellReader

final void setCellReader(CellReader cellReader)

getCube

public final RolapCube getCube()
Description copied from interface: Evaluator
Returns the current cube.

Specified by:
getCube in interface Evaluator

getQuery

public final Query getQuery()
Description copied from interface: Evaluator
Returns the current query.

Specified by:
getQuery in interface Evaluator

getDepth

public final int getDepth()
Description copied from interface: Evaluator
Returns number of ancestor evaluators. Used to check for infinite loops.

Specified by:
getDepth in interface Evaluator

getParent

public final Evaluator getParent()
Description copied from interface: Evaluator
Returns parent evaluator.

Specified by:
getParent in interface Evaluator

getSchemaReader

public final SchemaReader getSchemaReader()
Description copied from interface: Evaluator
Returns a SchemaReader appropriate for the current access-control context.

Specified by:
getSchemaReader in interface Evaluator

getQueryStartTime

public Date getQueryStartTime()
Description copied from interface: Evaluator
Returns the start time of the current query.

Specified by:
getQueryStartTime in interface Evaluator

getDialect

public SqlQuery.Dialect getDialect()

push

public final RolapEvaluator push(Member[] members)
Description copied from interface: Evaluator
Creates a new Evaluator with each given member overriding the context of the current Evaluator for its dimension. Other dimensions retain the same context as this Evaluator.

You can retrieve this Evaluator by calling the new Evaluator's Evaluator.pop() method, but it is not necessary to call pop.

Specified by:
push in interface Evaluator
Parameters:
members - Array of members to add to the context
Returns:
Evaluator with each given member overriding the state of the current Evaluator for its dimension

push

public final RolapEvaluator push(Member member)
Description copied from interface: Evaluator
Creates a new Evaluator with the same context except for one member. Equivalent to push(new Member[] |member}).

You can retrieve this Evaluator by calling the new Evaluator's Evaluator.pop() method, but it is not necessary to call pop.

Specified by:
push in interface Evaluator
Parameters:
member - Member to add to the context
Returns:
Evaluator with each given member overriding the state of the current Evaluator for its dimension

push

public final RolapEvaluator push()
Description copied from interface: Evaluator
Creates a new Evaluator with the same context as this evaluator. Equivalent to push(new Member[0]).

This method is typically called before evaluating an expression which is known to corrupt the evaluation context.

You can retrieve this Evaluator by calling the new Evaluator's Evaluator.pop() method, but it is not necessary to call pop.

Specified by:
push in interface Evaluator
Returns:
Evaluator with each given member overriding the state of the current Evaluator for its dimension

_push

protected RolapEvaluator _push()
Creates a clone of the current validator.


pop

public final Evaluator pop()
Description copied from interface: Evaluator
Restores previous evaluator.

Specified by:
pop in interface Evaluator

pushAggregation

public final Evaluator pushAggregation(List<Member[]> list)
Description copied from interface: Evaluator
Returns a new Aggregator whose aggregation context adds a given list of tuples, and whose dimensional context is the same as this Aggregator.

Specified by:
pushAggregation in interface Evaluator
Parameters:
list - List of tuples
Returns:
Aggregator with list added to its aggregation context

equals

public final boolean equals(Object obj)
Returns true if the other object is a RolapEvaluator with identical context.

Overrides:
equals in class Object

hashCode

public final int hashCode()
Overrides:
hashCode in class Object

setSlicerContext

public final void setSlicerContext(Member member)
Adds a slicer member to the evaluator context, and remember it as part of the slicer. The slicer members are passed onto derived evaluators so that functions using those evaluators can choose to ignore the slicer members. One such function is CrossJoin emptiness check.

Parameters:
member - a member in the slicer

getSlicerMembers

public final List<Member> getSlicerMembers()
Return the list of slicer members in the current evaluator context.

Returns:
slicerMembers

setContext

public final Member setContext(Member member)
Description copied from interface: Evaluator
Makes member the current member of its dimension. Returns the previous context.

Specified by:
setContext in interface Evaluator

setContext

public final void setContext(List<Member> memberList)
Specified by:
setContext in interface Evaluator

setContext

public final void setContext(Member[] members)
Specified by:
setContext in interface Evaluator

getContext

public final RolapMember getContext(Dimension dimension)
Specified by:
getContext in interface Evaluator

evaluateCurrent

public final Object evaluateCurrent()
Description copied from interface: Evaluator
Calculates and returns the value of the cell at the current context.

Specified by:
evaluateCurrent in interface Evaluator

getExpanding

Member getExpanding()
Returns the calculated member being currently expanded.

This can be useful if many calculated members are generated with essentially the same expression. The compiled expression can call this method to find which instance of the member is current, and therefore the calculated members can share the same Calc object.

Returns:
Calculated member currently being expanded

getProperty

public final Object getProperty(String name,
                                Object defaultValue)
Description copied from interface: Evaluator
Retrieves the value of property name. If more than one member in the current context defines that property, the one with the highest solve order has precedence.

If the property is not defined, default value is returned.

Specified by:
getProperty in interface Evaluator

getFormatString

public final String getFormatString()
Returns the format string for this cell. This is computed by evaluating the format expression in the current context, and therefore different cells may have different format strings.

Specified by:
getFormatString in interface Evaluator
Post-condition:
return != null

getConnectionLocale

public final Locale getConnectionLocale()
Description copied from interface: Evaluator
Returns the connection's locale.

Specified by:
getConnectionLocale in interface Evaluator

format

public final String format(Object o)
Description copied from interface: Evaluator
Formats a value as a string according to the current context's format.

Specified by:
format in interface Evaluator

format

public final String format(Object o,
                           String formatString)
Description copied from interface: Evaluator
Formats a value as a string according to the current context's format, using a given format string.

Specified by:
format in interface Evaluator

getCachedResult

public final Object getCachedResult(ExpCacheDescriptor cacheDescriptor)
Description copied from interface: Evaluator
Simple caching of the result of an Exp. The key for the cache consists of all members of the current context that exp depends on. Members of independent dimensions are not part of the key.

Specified by:
getCachedResult in interface Evaluator
See Also:
Calc.dependsOn(mondrian.olap.Dimension)

clearExpResultCache

public final void clearExpResultCache(boolean clearValidResult)

isNonEmpty

public final boolean isNonEmpty()
Description copied from interface: Evaluator
Returns true for an axis that is NON EMPTY.

May be used by expression evaluators to optimize their result. For example, a top-level crossjoin may be optimized by removing all non-empty set elements before performing the crossjoin. This is possible because of the identity

nonempty(crossjoin(a, b)) == nonempty(crossjoin(nonempty(a), nonempty(b));

Specified by:
isNonEmpty in interface Evaluator

setNonEmpty

public final void setNonEmpty(boolean nonEmpty)
Description copied from interface: Evaluator
Sets whether an expression evaluation should filter out empty cells. Allows expressions to modify non empty flag to evaluate their children.

Specified by:
setNonEmpty in interface Evaluator

newEvalException

public final RuntimeException newEvalException(Object context,
                                               String s)
Description copied from interface: Evaluator
Creates an exception which indicates that an error has occurred during the runtime evaluation of a function. The caller should then throw that exception.

Specified by:
newEvalException in interface Evaluator

evaluateNamedSet

public final Object evaluateNamedSet(String name,
                                     Exp exp)
Description copied from interface: Evaluator
Evaluates a named set.

Specified by:
evaluateNamedSet in interface Evaluator

getMissCount

public final int getMissCount()
Description copied from interface: Evaluator
Returns the number of times that this evaluator has told a lie when retrieving cell values.

Specified by:
getMissCount in interface Evaluator

getParameterValue

public final Object getParameterValue(ParameterSlot slot)
Description copied from interface: Evaluator
Returns the value of a parameter, evaluating its default value if it is not set.

Specified by:
getParameterValue in interface Evaluator

addCalcMember

final void addCalcMember(Member member)

getIterationLength

public final int getIterationLength()
Specified by:
getIterationLength in interface Evaluator
Returns:
the iteration length of the current context

setIterationLength

public final void setIterationLength(int length)
Description copied from interface: Evaluator
Sets the iteration length for the current evaluator context

Specified by:
setIterationLength in interface Evaluator
Parameters:
length - length to be set

isEvalAxes

public final boolean isEvalAxes()
Specified by:
isEvalAxes in interface Evaluator
Returns:
true if evaluating axes

setEvalAxes

public final void setEvalAxes(boolean evalAxes)
Description copied from interface: Evaluator
Indicate whether the evaluator is evaluating the axes

Specified by:
setEvalAxes in interface Evaluator
Parameters:
evalAxes - true if evaluating axes

shouldIgnoreUnrelatedDimensions

public boolean shouldIgnoreUnrelatedDimensions()
Checks if unrelated dimensions to the measure in the current context should be ignored.

Specified by:
shouldIgnoreUnrelatedDimensions in interface Evaluator
Returns:
boolean

SourceForge.net_Logo