mondrian.calc
Interface Calc
- All Known Subinterfaces:
- BooleanCalc, DateTimeCalc, DimensionCalc, DoubleCalc, HierarchyCalc, IntegerCalc, IterCalc, LevelCalc, ListCalc, MemberCalc, MemberIterCalc, MemberListCalc, StringCalc, TupleCalc, TupleIterCalc, TupleListCalc, VoidCalc
- All Known Implementing Classes:
- AbstractBooleanCalc, AbstractCalc, AbstractDateTimeCalc, AbstractDimensionCalc, AbstractDoubleCalc, AbstractHierarchyCalc, AbstractIntegerCalc, AbstractIterCalc, AbstractLevelCalc, AbstractListCalc, AbstractMemberCalc, AbstractMemberIterCalc, AbstractMemberListCalc, AbstractStringCalc, AbstractTupleCalc, AbstractTupleIterCalc, AbstractTupleListCalc, AbstractVoidCalc, AggregateFunDef.AggregateCalc, CacheCalc, ConstantCalc, CrossJoinFunDef.BaseListCalc, CrossJoinFunDef.BaseMemberArrayMemberArrayIterCalc, CrossJoinFunDef.BaseMemberArrayMemberIterCalc, CrossJoinFunDef.BaseMemberMemberArrayIterCalc, CrossJoinFunDef.BaseMemberMemberIterCalc, CrossJoinFunDef.ImmutableListMemberArrayListMemberArrayListCalc, CrossJoinFunDef.ImmutableListMemberArrayListMemberListCalc, CrossJoinFunDef.ImmutableListMemberListMemberArrayListCalc, CrossJoinFunDef.ImmutableListMemberListMemberListCalc, CrossJoinFunDef.IterMemberArrayIterMemberArrayIterCalc, CrossJoinFunDef.IterMemberArrayIterMemberIterCalc, CrossJoinFunDef.IterMemberArrayListMemberArrayIterCalc, CrossJoinFunDef.IterMemberArrayListMemberIterCalc, CrossJoinFunDef.IterMemberIterMemberArrayIterCalc, CrossJoinFunDef.IterMemberIterMemberIterCalc, CrossJoinFunDef.IterMemberListMemberArrayIterCalc, CrossJoinFunDef.IterMemberListMemberIterCalc, CrossJoinFunDef.ListMemberArrayIterMemberArrayIterCalc, CrossJoinFunDef.ListMemberArrayIterMemberIterCalc, CrossJoinFunDef.ListMemberArrayListMemberArrayIterCalc, CrossJoinFunDef.ListMemberArrayListMemberIterCalc, CrossJoinFunDef.ListMemberIterMemberArrayIterCalc, CrossJoinFunDef.ListMemberIterMemberIterCalc, CrossJoinFunDef.ListMemberListMemberArrayIterCalc, CrossJoinFunDef.ListMemberListMemberIterCalc, CrossJoinFunDef.MutableListMemberArrayListMemberArrayListCalc, CrossJoinFunDef.MutableListMemberArrayListMemberListCalc, CrossJoinFunDef.MutableListMemberListMemberArrayListCalc, CrossJoinFunDef.MutableListMemberListMemberListCalc, DistinctFunDef.CalcImpl, GenericCalc, GenericIterCalc, HierarchyCurrentMemberFunDef.CalcImpl, HierarchyCurrentMemberFunDef.FixedCalcImpl, HierarchyDimensionFunDef.CalcImpl, IterableMemberListCalc, IterableTupleListCalc, LevelHierarchyFunDef.CalcImpl, MemberHierarchyFunDef.CalcImpl, MemberLevelFunDef.CalcImpl, MemberOrderKeyFunDef.CalcImpl, MemberValueCalc, NativizeSetFunDef.NativeTupleListCalc, NativizeSetFunDef.NonNativeCalc, NativizeSetFunDef.NonNativeMemberIterCalc, NativizeSetFunDef.NonNativeMemberListCalc, ResultStyleCompiler.MultiCalc, SetFunDef.ExprMemberIterCalc, SetFunDef.ExprTupleIterCalc, SetFunDef.MemberSetListCalc, SetFunDef.TupleSetListCalc, TupleFunDef.CalcImpl, TupleValueCalc, ValueCalc
public interface Calc
Calc
is the base class for all calculable expressions.
Logical and physical expression languages
Mondrian has two expression languages:
- The logical language of parsed MDX fragments (
Exp
).
- The phyiscal language of compiled expressions (
Calc
).
The two languages allow us to separate logical (how an
MDX expression was specified) from physical (how it is to be evaluated).
The physical language is more strongly typed, and certain constructs which
are implicit in the logical language (such as the addition of calls
to the <Member>.CurrentMember
function) are made
explicit in the physical language.
Compilation
Expressions are generally created from using an expression compiler
(ExpCompiler
). There are often more than one evaluation strategy
for a given expression, and compilation process gives us an opportunity to
choose the optimal one.
Implementing expressions
The Calc
interface has sub-interfaces for various types:
IntegerCalc
,
BooleanCalc
,
DoubleCalc
,
StringCalc
are scalar expressions;
MemberCalc
,
LevelCalc
,
HierarchyCalc
,
DimensionCalc
yield elements of the OLAP model.
Each of these sub-interfaces has an abstract implementation:
AbstractIntegerCalc
,
AbstractBooleanCalc
,
AbstractDoubleCalc
,
AbstractStringCalc
,
AbstractMemberCalc
,
AbstractLevelCalc
,
AbstractHierarchyCalc
,
AbstractDimensionCalc
.
GenericCalc
is an adapter which implements all of these interfaces
and will try to convert any given result to the correct type. Use it
sparingly: if you know the expected result type, it is better to write a
class which implements a specific TypeCalc
interface.
- Since:
- Sep 26, 2005
- Version:
- $Id: //open/mondrian/src/main/mondrian/calc/Calc.java#9 $
- Author:
- jhyde
evaluate
java.lang.Object evaluate(Evaluator evaluator)
- Evaluates this expression.
- Parameters:
evaluator
- Provides dimensional context in which to evaluate
this expression
- Returns:
- Result of expression evaluation
dependsOn
boolean dependsOn(Hierarchy hierarchy)
- Returns whether this expression depends upon a given hierarchy.
If it does not depend on the hierarchy, then re-evaluating the
expression with a different member of this context must produce the
same answer.
Some examples:
- The expression
[Measures].[Unit Sales]
depends on all dimensions except [Measures]
.
- The boolean expression
([Measures].[Unit Sales],
[Time].[1997]) > 1000
depends on all hierarchies except [Measures] and [Time].
- The list expression
Filter([Store].[USA].Children,
[Measures].[Unit Sales] < 50)
depends upon all hierarchies except [Store] and [Measures].
How so? Normally the scalar expression would depend upon all hierarchies
except [Measures], but the Filter
function sets the [Store]
context before evaluating the scalar expression, so it is not inherited
from the surrounding context.
- Parameters:
hierarchy
- Hierarchy
- Returns:
- Whether this expression's result depends upon the current member
of the hierarchy
getType
Type getType()
- Returns the type of this expression.
accept
void accept(CalcWriter calcWriter)
- Prints this expression, by accepting a visiting
CalcWriter
.
- Parameters:
calcWriter
- Writer
getResultStyle
ResultStyle getResultStyle()
- Returns style in which the result of evaluating this expression is
returned.
One application of this method is for the compiler to figure out
whether the compiled expression is returning a mutable list. If a mutable
list is required, the compiler can create a mutable copy.
- See Also:
ExpCompiler.compileList(mondrian.olap.Exp, boolean)