Class RolapEvaluator
- All Implemented Interfaces:
Evaluator
- Direct Known Subclasses:
RolapDependencyTestingEvaluator
,RolapProfilingEvaluator
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.
There are two ways of preserving context.
First, the push(mondrian.olap.Member[])
method creates a verbatim copy of the evaluator. Use that copy for computations, and any
changes of state will be made only to the copy.
Second, the savepoint()
method tells the evaluator to create a checkpoint of its state, and returns an
int
value that can later be passed to restore(int)
.
The savepoint
method is recommended for most purposes, because the initial checkpoint is extremely cheap.
Each call that modifies state (such as Evaluator.setContext(mondrian.olap.Member)
) creates, at
a modest cost, an entry on an internal command stack.
One occasion that you would use push
is when creating an iterator, and the iterator needs its own evaluator
context, even if the code that created the iterator later reverts the context. In this case, the iterator's
constructor should call push
.
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
Nested classes/interfaces inherited from interface mondrian.olap.Evaluator
Evaluator.NamedSetEvaluator, Evaluator.SetEvaluator
-
Field Summary
Modifier and TypeFieldDescriptionList 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 mondrian.rolap.CellReader
protected final mondrian.rolap.RolapEvaluatorRoot
protected CompoundPredicateInfo
-
Constructor Summary
ModifierConstructorDescriptionRolapEvaluator
(mondrian.rolap.RolapEvaluatorRoot root) Creates a root evaluator.protected
RolapEvaluator
(mondrian.rolap.RolapEvaluatorRoot root, RolapEvaluator parent, List<List<Member>> aggregationList) Creates a non-root evaluator. -
Method Summary
Modifier and TypeMethodDescriptionprotected RolapEvaluator
Creates a clone of the current validator.final void
clearExpResultCache
(boolean clearValidResult) static Evaluator
Creates an evaluator.boolean
Returns whether the current context is an empty cell.final boolean
Returns true if the other object is aRolapEvaluator
with identical context.final Object
Calculates and returns the value of the cell at the current context.final String
Formats a value as a string according to the current context's format.final String
Formats a value as a string according to the current context's format, using a given format string.Set of expressions actively being expanded.final Object
getCachedResult
(ExpCacheDescriptor cacheDescriptor) Simple caching of the result of anExp
.final Locale
Returns the connection's locale.final RolapMember
getContext
(Hierarchy hierarchy) final RolapMember
getContext
(RolapHierarchy hierarchy) More specific version ofgetContext(mondrian.olap.Hierarchy)
, for internal code.final RolapCube
getCube()
Returns the current cube.final int
getDepth()
Obsolete method.final String
Returns the format string for this cell.final int
protected final org.apache.logging.log4j.Logger
Returns the base (non-virtual) cube that the current measure in the context belongs to.final Member[]
Returns an array of the members which make up the current context.final int
Returns the number of times that this evaluator has told a lie when retrieving cell values.getNamedSetEvaluator
(NamedSet namedSet, boolean create) Returns an evaluator for a named set.final Member[]
Returns an array of the non-All members which make up the current context.final TupleList
getOptimizedSlicerTuples
(RolapCube baseCube) Returns an optimized list of tuples related to the slicer based on the current evaluator.final Object
Returns the value of a parameter, evaluating its default value if it is not set.final RolapEvaluator
Returns parent evaluator.getPreviousContext
(Hierarchy hierarchy) Returns the member that was the current evaluation context for a particular hierarchy before the most recent change in context.final Object
getProperty
(String name, Object defaultValue) Retrieves the value of propertyname
.final Query
getQuery()
Returns the current query.Returns the start time of the current query.final SchemaReader
Returns aSchemaReader
appropriate for the current access-control context.final Evaluator.SetEvaluator
getSetEvaluator
(Exp exp, boolean create) Returns an evaluator for a set.Return the list of slicer members in the current evaluator context.final TupleList
Return the list of compound slicer tuplesfinal QueryTiming
Returns the query timing context for this execution.final int
hashCode()
boolean
final boolean
boolean
final boolean
Returns true for an axis that is NON EMPTY.boolean
Returns whether it is necessary to check whether to return null for an unrelated dimension.boolean
Returns whether native evaluation is enabled in this context.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.final RuntimeException
newEvalException
(Object context, String s) Creates an exception which indicates that an error has occurred during the runtime evaluation of a function.final RolapEvaluator
push()
Creates a new Evaluator with the same context as this evaluator.final Evaluator
push
(boolean nonEmpty) Creates a new evaluator with the same state except nonEmpty propertyfinal Evaluator
push
(boolean nonEmpty, boolean nativeEnabled) Creates a new evaluator with the same state except nonEmpty and nativeEnabled properties.final RolapEvaluator
Creates a new Evaluator with the same context except for one member.final RolapEvaluator
Creates a new Evaluator with each given member overriding the context of the current Evaluator for its hierarchy.final Evaluator
pushAggregation
(List<List<Member>> list) Returns a new Aggregator whose aggregation context adds a given list of tuples, and whose evaluation context is the same as this Aggregator.final void
restore
(int savepoint) Restores previous evaluator.final int
Creates a savepoint encapsulating the current state of the evalutor.final void
setContext
(List<Member> memberList) Sets the context to a list of members.final void
setContext
(List<Member> memberList, boolean safe) Sets the context to a list of members, optionally skipping the check whether it is necessary to store the previous member of each hierarchy.final Member
setContext
(Member member) Makesmember
the current member of its hierarchy.final void
setContext
(Member[] members) Sets the context to an array of members.final void
setContext
(Member[] members, boolean safe) Sets the context to an array of members, optionally skipping the check whether it is necessary to store the previous member of each hierarchy.final void
setContext
(Member member, boolean safe) Makesmember
the current member of its hierarchy.final void
setEvalAxes
(boolean evalAxes) Indicate whether the evaluator is evaluating the axesfinal void
setIterationLength
(int iterationLength) Sets the iteration length for the current evaluator contextfinal void
setNativeEnabled
(boolean nativeEnabled) Sets whether native evaluation should be used.final void
setNonEmpty
(boolean nonEmpty) Sets whether an expression evaluation should filter out empty cells.final void
Adds a slicer member to the evaluator context, and remember it as part of the slicer.final void
setSlicerTuples
(TupleList tuples) Sets the slicer tuple object, used later by native evaluation and non-empty crossjoins.boolean
Checks if unrelated dimensions to the measure in the current context should be ignored.
-
Field Details
-
cellReader
protected mondrian.rolap.CellReader cellReader -
root
protected final mondrian.rolap.RolapEvaluatorRoot root -
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. -
slicerPredicateInfo
-
-
Constructor Details
-
RolapEvaluator
protected RolapEvaluator(mondrian.rolap.RolapEvaluatorRoot root, RolapEvaluator parent, List<List<Member>> aggregationList) Creates a non-root evaluator.- Parameters:
root
- Root context for stack of evaluators (contains information which does not change during the evaluation)parent
- Parent evaluator, not nullaggregationList
- List of tuples to add to aggregation context, or null
-
RolapEvaluator
public RolapEvaluator(mondrian.rolap.RolapEvaluatorRoot root) Creates a root evaluator.- Parameters:
root
- Shared context between this evaluator and its children
-
-
Method Details
-
getActiveNativeExpansions
Set of expressions actively being expanded. Prevents infinite cycle of expansions.- Returns:
- Mutable set of expressions being expanded
-
getSlicerPredicateInfo
-
create
Creates an evaluator. -
getMeasureCube
Description copied from interface:Evaluator
Returns the base (non-virtual) cube that the current measure in the context belongs to.- Specified by:
getMeasureCube
in interfaceEvaluator
- Returns:
- Cube
-
nativeEnabled
public boolean nativeEnabled()Description copied from interface:Evaluator
Returns whether native evaluation is enabled in this context.- Specified by:
nativeEnabled
in interfaceEvaluator
- Returns:
- whether native evaluation is enabled in this context
-
currentIsEmpty
public boolean currentIsEmpty()Description copied from interface:Evaluator
Returns whether the current context is an empty cell.- Specified by:
currentIsEmpty
in interfaceEvaluator
- Returns:
- Whether the current context is an empty cell
-
getPreviousContext
Description copied from interface:Evaluator
Returns the member that was the current evaluation context for a particular hierarchy before the most recent change in context.- Specified by:
getPreviousContext
in interfaceEvaluator
- Parameters:
hierarchy
- Hierarchy- Returns:
- Previous context member for given hierarchy
-
getTiming
Description copied from interface:Evaluator
Returns the query timing context for this execution. -
savepoint
public final int savepoint()Description copied from interface:Evaluator
Creates a savepoint encapsulating the current state of the evalutor. You can restore the evaluator to this state by callingEvaluator.restore(int)
with the value returned by this method.This method is typically called before evaluating an expression which is known to corrupt the evaluation context.
Multiple savepoints may be active at the same time for the same evaluator. And, it is allowable to restore to the save savepoint more than once (or not at all). However, when you have rolled back to a particular savepoint you may not restore to a later savepoint.
-
setNativeEnabled
public final void setNativeEnabled(boolean nativeEnabled) Description copied from interface:Evaluator
Sets whether native evaluation should be used.- Specified by:
setNativeEnabled
in interfaceEvaluator
- Parameters:
nativeEnabled
- Whether native evaluation should be used
-
getLogger
protected final org.apache.logging.log4j.Logger getLogger() -
getMembers
Description copied from interface:Evaluator
Returns an array of the members which make up the current context.- Specified by:
getMembers
in interfaceEvaluator
-
getNonAllMembers
Description copied from interface:Evaluator
Returns an array of the non-All members which make up the current context.Notes:
- The 0th element is a measure, but otherwise the order of the members is unspecified.
- No hierarchy occurs more than once.
- In rare circumstances, some of the members may be an 'All' member.
- The list may contain calculated members.
- Specified by:
getNonAllMembers
in interfaceEvaluator
-
getAggregationLists
-
getCube
Description copied from interface:Evaluator
Returns the current cube. -
getQuery
Description copied from interface:Evaluator
Returns the current query. -
getDepth
public final int getDepth()Description copied from interface:Evaluator
Obsolete method. -
getParent
Description copied from interface:Evaluator
Returns parent evaluator. -
getSchemaReader
Description copied from interface:Evaluator
Returns aSchemaReader
appropriate for the current access-control context.- Specified by:
getSchemaReader
in interfaceEvaluator
-
getQueryStartTime
Description copied from interface:Evaluator
Returns the start time of the current query.- Specified by:
getQueryStartTime
in interfaceEvaluator
-
getDialect
-
push
Description copied from interface:Evaluator
Creates a new Evaluator with each given member overriding the context of the current Evaluator for its hierarchy. Other hierarchies retain the same context as this Evaluator.In mondrian-3.3 and later, a more efficient way to save the state of an evaluator is to call
Evaluator.savepoint()
followed byEvaluator.restore(int)
. We recommend using those methods. -
push
Description copied from interface:Evaluator
Creates a new Evaluator with the same context except for one member.This method is typically called before evaluating an expression which may corrupt the evaluation context.
In mondrian-3.3 and later, a more efficient way to save the state of an evaluator is to call
Evaluator.savepoint()
followed byEvaluator.restore(int)
. We recommend using those methods. -
push
Description copied from interface:Evaluator
Creates a new evaluator with the same state except nonEmpty propertyIn mondrian-3.3 and later, a more efficient way to save the state of an evaluator is to call
Evaluator.savepoint()
followed byEvaluator.restore(int)
. We recommend using those methods. -
push
Description copied from interface:Evaluator
Creates a new evaluator with the same state except nonEmpty and nativeEnabled properties.In mondrian-3.3 and later, a more efficient way to save the state of an evaluator is to call
Evaluator.savepoint()
followed byEvaluator.restore(int)
. We recommend using those methods. -
push
Description copied from interface:Evaluator
Creates a new Evaluator with the same context as this evaluator.This method is typically called before evaluating an expression which may corrupt the evaluation context.
In mondrian-3.3 and later, a more efficient way to save the state of an evaluator is to call
Evaluator.savepoint()
followed byEvaluator.restore(int)
. We recommend using those methods most of the time.However, it makes sense to use this method in the constructor of an iterator. It allows the iterator to modify its evaluation context without affecting the evaluation context of the calling code. This behavior cannot be achieved using
savepoint
. -
_push
Creates a clone of the current validator.- Parameters:
aggregationList
- List of tuples to add to aggregation context, or null
-
restore
public final void restore(int savepoint) Description copied from interface:Evaluator
Restores previous evaluator.- Specified by:
restore
in interfaceEvaluator
- Parameters:
savepoint
- Savepoint returned byEvaluator.savepoint()
-
pushAggregation
Description copied from interface:Evaluator
Returns a new Aggregator whose aggregation context adds a given list of tuples, and whose evaluation context is the same as this Aggregator.- Specified by:
pushAggregation
in interfaceEvaluator
- Parameters:
list
- List of tuples- Returns:
- Aggregator with
list
added to its aggregation context
-
equals
Returns true if the other object is aRolapEvaluator
with identical context. -
hashCode
public final int hashCode() -
setSlicerContext
public final void setSlicerContext(List<Member> members, Map<Hierarchy, Set<Member>> membersByHierarchy) 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:
members
- members in slicermembersByHierarchy
- members in slicer by hierarchy
-
getSlicerMembers
Return the list of slicer members in the current evaluator context.- Returns:
- slicerMembers
-
getSlicerMembersByHierarchy
-
setSlicerTuples
Sets the slicer tuple object, used later by native evaluation and non-empty crossjoins.- Parameters:
tuples
- slicer
-
getSlicerTuples
Return the list of compound slicer tuples -
isDisjointSlicerTuple
public boolean isDisjointSlicerTuple() -
isMultiLevelSlicerTuple
public boolean isMultiLevelSlicerTuple() -
getOptimizedSlicerTuples
Returns an optimized list of tuples related to the slicer based on the current evaluator. This function removes overridden compound slicer members from the tuple list. TODO: Add Virtual Cube test cases, demonstrating unrelated dimensions. TODO: Test various Tuple List sizes - tuples sizes that are bigger and smaller than list size- Parameters:
baseCube
- if this is a virtual cube, remove the unrelated tuples from the slicer.- Returns:
- optimized slicer tuple list
-
setContext
Description copied from interface:Evaluator
Makesmember
the current member of its hierarchy.- Specified by:
setContext
in interfaceEvaluator
- Parameters:
member
- New member- Returns:
- Previous member of this hierarchy
-
setContext
Description copied from interface:Evaluator
Makesmember
the current member of its hierarchy.If
safe
, checks whether this is the first time that a member of this hierarchy has been changed sinceEvaluator.savepoint()
was called. If so, saves the previous member. Ifsafe
is false, never saves the previous member.Use
safe = false
only if you are sure that the context has been set before. For example,int n = 0;
for (Member member : members) {
evaluator.setContext(member, n++ > 0);
}- Specified by:
setContext
in interfaceEvaluator
- Parameters:
member
- New membersafe
- Whether to store the member of this hierarchy that was current last time thatEvaluator.savepoint()
was called.
-
setContext
Description copied from interface:Evaluator
Sets the context to a list of members.Equivalent to
for (Member member : memberList) {
setContext(member);
}- Specified by:
setContext
in interfaceEvaluator
- Parameters:
memberList
- List of members
-
setContext
Description copied from interface:Evaluator
Sets the context to a list of members, optionally skipping the check whether it is necessary to store the previous member of each hierarchy.Equivalent to
for (Member member : memberList) {
setContext(member, safe);
}- Specified by:
setContext
in interfaceEvaluator
- Parameters:
memberList
- List of memberssafe
- Whether to store the member of each hierarchy that was current last time thatEvaluator.savepoint()
was called.
-
setContext
Description copied from interface:Evaluator
Sets the context to an array of members.Equivalent to
for (Member member : memberList) {
setContext(member);
}- Specified by:
setContext
in interfaceEvaluator
- Parameters:
members
- Array of members
-
setContext
Description copied from interface:Evaluator
Sets the context to an array of members, optionally skipping the check whether it is necessary to store the previous member of each hierarchy.Equivalent to
for (Member member : memberList) {
setContext(member, safe);
}- Specified by:
setContext
in interfaceEvaluator
- Parameters:
members
- Array of memberssafe
- Whether to store the member of each hierarchy that was current last time thatEvaluator.savepoint()
was called.
-
getContext
- Specified by:
getContext
in interfaceEvaluator
-
getContext
More specific version ofgetContext(mondrian.olap.Hierarchy)
, for internal code.- Parameters:
hierarchy
- Hierarchy- Returns:
- current member
-
evaluateCurrent
Description copied from interface:Evaluator
Calculates and returns the value of the cell at the current context.- Specified by:
evaluateCurrent
in interfaceEvaluator
-
getProperty
Description copied from interface:Evaluator
Retrieves the value of propertyname
. 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 interfaceEvaluator
-
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 interfaceEvaluator
-
getConnectionLocale
Description copied from interface:Evaluator
Returns the connection's locale.- Specified by:
getConnectionLocale
in interfaceEvaluator
-
format
Description copied from interface:Evaluator
Formats a value as a string according to the current context's format. -
format
Description copied from interface:Evaluator
Formats a value as a string according to the current context's format, using a given format string. -
getCachedResult
Description copied from interface:Evaluator
Simple caching of the result of anExp
. The key for the cache consists of all members of the current context thatexp
depends on. Members of independent hierarchies are not part of the key.- Specified by:
getCachedResult
in interfaceEvaluator
- See Also:
-
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 interfaceEvaluator
-
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 interfaceEvaluator
-
newEvalException
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 interfaceEvaluator
-
getNamedSetEvaluator
Description copied from interface:Evaluator
Returns an evaluator for a named set.- Specified by:
getNamedSetEvaluator
in interfaceEvaluator
- Parameters:
namedSet
- Named setcreate
- Whether to create evaluator if not found- Returns:
- Evaluator of named set
-
getSetEvaluator
Description copied from interface:Evaluator
Returns an evaluator for a set.- Specified by:
getSetEvaluator
in interfaceEvaluator
- Parameters:
exp
- Expressioncreate
- Whether to create evaluator if not found- Returns:
- Evaluator of named set
-
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 interfaceEvaluator
-
getParameterValue
Description copied from interface:Evaluator
Returns the value of a parameter, evaluating its default value if it is not set.- Specified by:
getParameterValue
in interfaceEvaluator
-
getIterationLength
public final int getIterationLength()- Specified by:
getIterationLength
in interfaceEvaluator
- Returns:
- the iteration length of the current context
-
setIterationLength
public final void setIterationLength(int iterationLength) Description copied from interface:Evaluator
Sets the iteration length for the current evaluator context- Specified by:
setIterationLength
in interfaceEvaluator
- Parameters:
iterationLength
- length to be set
-
isEvalAxes
public final boolean isEvalAxes()- Specified by:
isEvalAxes
in interfaceEvaluator
- 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 interfaceEvaluator
- Parameters:
evalAxes
- true if evaluating axes
-