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.
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
.
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.
Evaluator.NamedSetEvaluator, Evaluator.SetEvaluator
Modifier and Type | Field and Description |
---|---|
protected List<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 mondrian.rolap.CellReader |
cellReader |
protected mondrian.rolap.RolapEvaluatorRoot |
root |
protected CompoundPredicateInfo |
slicerPredicateInfo |
Modifier | Constructor and Description |
---|---|
|
RolapEvaluator(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.
|
Modifier and Type | Method and Description |
---|---|
protected RolapEvaluator |
_push(List<List<Member>> aggregationList)
Creates a clone of the current validator.
|
void |
clearExpResultCache(boolean clearValidResult) |
static Evaluator |
create(Statement statement)
Creates an evaluator.
|
boolean |
currentIsEmpty()
Returns whether the current context is an empty cell.
|
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.
|
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.
|
Set<Exp> |
getActiveNativeExpansions()
Set of expressions actively being expanded.
|
List<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(Hierarchy hierarchy) |
RolapMember |
getContext(RolapHierarchy hierarchy)
More specific version of
getContext(mondrian.olap.Hierarchy) ,
for internal code. |
RolapCube |
getCube()
Returns the current cube.
|
int |
getDepth()
Obsolete method.
|
Dialect |
getDialect() |
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.
|
Evaluator.NamedSetEvaluator |
getNamedSetEvaluator(NamedSet namedSet,
boolean create)
Returns an evaluator for a named set.
|
Member[] |
getNonAllMembers()
Returns an array of the non-All members which make up the current
context.
|
TupleList |
getOptimizedSlicerTuples(RolapCube baseCube)
Returns an optimized list of tuples related to the slicer based on the
current evaluator.
|
Object |
getParameterValue(ParameterSlot slot)
Returns the value of a parameter, evaluating its default value if it is
not set.
|
RolapEvaluator |
getParent()
Returns parent evaluator.
|
Member |
getPreviousContext(Hierarchy hierarchy)
Returns the member that was the current evaluation context for a
particular hierarchy before the most recent change in context.
|
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. |
Evaluator.SetEvaluator |
getSetEvaluator(Exp exp,
boolean create)
Returns an evaluator for a set.
|
List<Member> |
getSlicerMembers()
Return the list of slicer members in the current evaluator context.
|
CompoundPredicateInfo |
getSlicerPredicateInfo() |
TupleList |
getSlicerTuples()
Return the list of compound slicer tuples
|
QueryTiming |
getTiming()
Returns the query timing context for this execution.
|
int |
hashCode() |
boolean |
isDisjointSlicerTuple() |
boolean |
isEvalAxes() |
boolean |
isMultiLevelSlicerTuple() |
boolean |
isNonEmpty()
Returns true for an axis that is NON EMPTY.
|
boolean |
mightReturnNullForUnrelatedDimension()
Returns whether it is necessary to check whether to return null for
an unrelated dimension.
|
boolean |
nativeEnabled()
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.
|
RuntimeException |
newEvalException(Object context,
String s)
Creates an exception which indicates that an error has occurred during
the runtime evaluation of a function.
|
RolapEvaluator |
push()
Creates a new Evaluator with the same context as this evaluator.
|
Evaluator |
push(boolean nonEmpty)
Creates a new evaluator with the same state except nonEmpty property
|
Evaluator |
push(boolean nonEmpty,
boolean nativeEnabled)
Creates a new evaluator with the same state except nonEmpty
and nativeEnabled properties.
|
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 hierarchy.
|
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.
|
void |
restore(int savepoint)
Restores previous evaluator.
|
int |
savepoint()
Creates a savepoint encapsulating the current state of the evalutor.
|
void |
setContext(List<Member> memberList)
Sets the context to a list of members.
|
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.
|
Member |
setContext(Member member)
Makes
member the current member of its hierarchy. |
void |
setContext(Member[] members)
Sets the context to an array of members.
|
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.
|
void |
setContext(Member member,
boolean safe)
Makes
member the current member of its hierarchy. |
void |
setEvalAxes(boolean evalAxes)
Indicate whether the evaluator is evaluating the axes
|
void |
setIterationLength(int iterationLength)
Sets the iteration length for the current evaluator context
|
void |
setNativeEnabled(boolean nativeEnabled)
Sets whether native evaluation should be used.
|
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.
|
void |
setSlicerTuples(TupleList tuples)
Sets the slicer tuple object, used later by native evaluation and
non-empty crossjoins.
|
boolean |
shouldIgnoreUnrelatedDimensions()
Checks if unrelated dimensions to the measure in the current context
should be ignored.
|
protected mondrian.rolap.CellReader cellReader
protected final mondrian.rolap.RolapEvaluatorRoot root
protected final List<List<List<Member>>> aggregationLists
protected CompoundPredicateInfo slicerPredicateInfo
protected RolapEvaluator(mondrian.rolap.RolapEvaluatorRoot root, RolapEvaluator parent, List<List<Member>> aggregationList)
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 nullpublic RolapEvaluator(mondrian.rolap.RolapEvaluatorRoot root)
root
- Shared context between this evaluator and its childrenpublic Set<Exp> getActiveNativeExpansions()
public CompoundPredicateInfo getSlicerPredicateInfo()
public RolapCube getMeasureCube()
Evaluator
getMeasureCube
in interface Evaluator
public boolean mightReturnNullForUnrelatedDimension()
Evaluator
Evaluator.needToReturnNullForUnrelatedDimension(mondrian.olap.Member[])
will always return false.mightReturnNullForUnrelatedDimension
in interface Evaluator
public boolean needToReturnNullForUnrelatedDimension(Member[] members)
Evaluator
You must not call this method unless
Evaluator.mightReturnNullForUnrelatedDimension()
has returned true.
needToReturnNullForUnrelatedDimension
in interface Evaluator
members
- Dimensions for the members need to be checked whether
related or unrelatedpublic boolean nativeEnabled()
Evaluator
nativeEnabled
in interface Evaluator
public boolean currentIsEmpty()
Evaluator
currentIsEmpty
in interface Evaluator
public Member getPreviousContext(Hierarchy hierarchy)
Evaluator
getPreviousContext
in interface Evaluator
hierarchy
- Hierarchypublic final QueryTiming getTiming()
Evaluator
public final int savepoint()
Evaluator
Evaluator.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.
public final void setNativeEnabled(boolean nativeEnabled)
Evaluator
setNativeEnabled
in interface Evaluator
nativeEnabled
- Whether native evaluation should be usedprotected final org.apache.log4j.Logger getLogger()
public final Member[] getMembers()
Evaluator
getMembers
in interface Evaluator
public final Member[] getNonAllMembers()
Evaluator
Notes:
getNonAllMembers
in interface Evaluator
public final RolapCube getCube()
Evaluator
public final Query getQuery()
Evaluator
public final int getDepth()
Evaluator
public final RolapEvaluator getParent()
Evaluator
public final SchemaReader getSchemaReader()
Evaluator
SchemaReader
appropriate for the current
access-control context.getSchemaReader
in interface Evaluator
public Date getQueryStartTime()
Evaluator
getQueryStartTime
in interface Evaluator
public Dialect getDialect()
public final RolapEvaluator push(Member[] members)
Evaluator
In mondrian-3.3 and later, a more efficient way to save the state of
an evaluator is to call Evaluator.savepoint()
followed by
Evaluator.restore(int)
. We recommend using those methods.
public final RolapEvaluator push(Member member)
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 by
Evaluator.restore(int)
. We recommend using those methods.
public final Evaluator push(boolean nonEmpty)
Evaluator
In mondrian-3.3 and later, a more efficient way to save the state of
an evaluator is to call Evaluator.savepoint()
followed by
Evaluator.restore(int)
. We recommend using those methods.
public final Evaluator push(boolean nonEmpty, boolean nativeEnabled)
Evaluator
In mondrian-3.3 and later, a more efficient way to save the state of
an evaluator is to call Evaluator.savepoint()
followed by
Evaluator.restore(int)
. We recommend using those methods.
public final RolapEvaluator push()
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 by
Evaluator.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
.
protected RolapEvaluator _push(List<List<Member>> aggregationList)
aggregationList
- List of tuples to add to aggregation context,
or nullpublic final void restore(int savepoint)
Evaluator
restore
in interface Evaluator
savepoint
- Savepoint returned by Evaluator.savepoint()
public final Evaluator pushAggregation(List<List<Member>> list)
Evaluator
pushAggregation
in interface Evaluator
list
- List of tupleslist
added to its aggregation
contextpublic final boolean equals(Object obj)
RolapEvaluator
with
identical context.public final void setSlicerContext(Member member)
member
- a member in the slicerpublic final List<Member> getSlicerMembers()
public final void setSlicerTuples(TupleList tuples)
tuples
- slicerpublic final TupleList getSlicerTuples()
public boolean isDisjointSlicerTuple()
public boolean isMultiLevelSlicerTuple()
public final TupleList getOptimizedSlicerTuples(RolapCube baseCube)
baseCube
- if this is a virtual cube, remove the unrelated tuples
from the slicer.public final Member setContext(Member member)
Evaluator
member
the current member of its hierarchy.setContext
in interface Evaluator
member
- New memberpublic final void setContext(Member member, boolean safe)
Evaluator
member
the current member of its hierarchy.
If safe
, checks whether this is the first time that
a member of this hierarchy has been changed since Evaluator.savepoint()
was called. If so, saves the previous member. If safe
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);
}
setContext
in interface Evaluator
member
- New membersafe
- Whether to store the member of this hierarchy that was
current last time that Evaluator.savepoint()
was called.public final void setContext(List<Member> memberList)
Evaluator
Equivalent to
for (Member member : memberList) {
setContext(member);
}
setContext
in interface Evaluator
memberList
- List of memberspublic final void setContext(List<Member> memberList, boolean safe)
Evaluator
Equivalent to
for (Member member : memberList) {
setContext(member, safe);
}
setContext
in interface Evaluator
memberList
- List of memberssafe
- Whether to store the member of each hierarchy that was
current last time that Evaluator.savepoint()
was called.public final void setContext(Member[] members)
Evaluator
Equivalent to
for (Member member : memberList) {
setContext(member);
}
setContext
in interface Evaluator
members
- Array of memberspublic final void setContext(Member[] members, boolean safe)
Evaluator
Equivalent to
for (Member member : memberList) {
setContext(member, safe);
}
setContext
in interface Evaluator
members
- Array of memberssafe
- Whether to store the member of each hierarchy that was
current last time that Evaluator.savepoint()
was called.public final RolapMember getContext(Hierarchy hierarchy)
getContext
in interface Evaluator
public final RolapMember getContext(RolapHierarchy hierarchy)
getContext(mondrian.olap.Hierarchy)
,
for internal code.hierarchy
- Hierarchypublic final Object evaluateCurrent()
Evaluator
evaluateCurrent
in interface Evaluator
public final Object getProperty(String name, Object defaultValue)
Evaluator
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.
getProperty
in interface Evaluator
public final String getFormatString()
getFormatString
in interface Evaluator
public final Locale getConnectionLocale()
Evaluator
getConnectionLocale
in interface Evaluator
public final String format(Object o)
Evaluator
public final String format(Object o, String formatString)
Evaluator
public final Object getCachedResult(ExpCacheDescriptor cacheDescriptor)
Evaluator
Exp
. The
key for the cache consists of all members of the current
context that exp
depends on. Members of
independent hierarchies are not part of the key.getCachedResult
in interface Evaluator
Calc.dependsOn(Hierarchy)
public final void clearExpResultCache(boolean clearValidResult)
public final boolean isNonEmpty()
Evaluator
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));
isNonEmpty
in interface Evaluator
public final void setNonEmpty(boolean nonEmpty)
Evaluator
setNonEmpty
in interface Evaluator
public final RuntimeException newEvalException(Object context, String s)
Evaluator
newEvalException
in interface Evaluator
public final Evaluator.NamedSetEvaluator getNamedSetEvaluator(NamedSet namedSet, boolean create)
Evaluator
getNamedSetEvaluator
in interface Evaluator
namedSet
- Named setcreate
- Whether to create evaluator if not foundpublic final Evaluator.SetEvaluator getSetEvaluator(Exp exp, boolean create)
Evaluator
getSetEvaluator
in interface Evaluator
exp
- Expressioncreate
- Whether to create evaluator if not foundpublic final int getMissCount()
Evaluator
getMissCount
in interface Evaluator
public final Object getParameterValue(ParameterSlot slot)
Evaluator
getParameterValue
in interface Evaluator
public final int getIterationLength()
getIterationLength
in interface Evaluator
public final void setIterationLength(int iterationLength)
Evaluator
setIterationLength
in interface Evaluator
iterationLength
- length to be setpublic final boolean isEvalAxes()
isEvalAxes
in interface Evaluator
public final void setEvalAxes(boolean evalAxes)
Evaluator
setEvalAxes
in interface Evaluator
evalAxes
- true if evaluating axespublic boolean shouldIgnoreUnrelatedDimensions()
shouldIgnoreUnrelatedDimensions
in interface Evaluator
Copyright © 2020 Hitachi Vantara. All rights reserved.