mondrian.olap.fun
Class FunDefBase

java.lang.Object
  extended by org.eigenbase.xom.XMLUtil
      extended by org.eigenbase.xom.XOMUtil
          extended by mondrian.olap.Util
              extended by mondrian.olap.fun.FunUtil
                  extended by mondrian.olap.fun.FunDefBase
All Implemented Interfaces:
FunDef
Direct Known Subclasses:
AbstractAggregateFunDef, AddCalculatedMembersFunDef, AncestorFunDef, CacheFunDef, CalculatedChildFunDef, CaseMatchFunDef, CaseTestFunDef, CastFunDef, CoalesceEmptyFunDef, CovarianceFunDef, CrossJoinFunDef, DescendantsFunDef, DimensionCurrentMemberFunDef, DistinctFunDef, DrilldownLevelFunDef, DrilldownLevelTopBottomFunDef, DrilldownMemberFunDef, ExceptFunDef, ExistsFunDef, ExtractFunDef, FilterFunDef, FormatFunDef, GenerateFunDef, HeadTailFunDef, HierarchizeFunDef, HierarchyCurrentMemberFunDef, HierarchyDimensionFunDef, IifFunDef, IntersectFunDef, IsEmptyFunDef, IsFunDef, IsNullFunDef, JavaFunDef, LastPeriodsFunDef, LeadLagFunDef, LevelHierarchyFunDef, LinReg, MemberHierarchyFunDef, MemberLevelFunDef, OpeningClosingPeriodFunDef, OrderFunDef, ParallelPeriodFunDef, ParameterFunDef, ParenthesesFunDef, PeriodsToDateFunDef, PropertiesFunDef, RangeFunDef, RankFunDef, SetFunDef, SetItemFunDef, SetToStrFunDef, StrToSetFunDef, StrToTupleFunDef, SubsetFunDef, ToggleDrillStateFunDef, TopBottomCountFunDef, TopBottomPercentSumFunDef, TupleFunDef, TupleItemFunDef, TupleToStrFunDef, UnionFunDef, UnorderFunDef, ValidMeasureFunDef, ValueFunDef, VisualTotalsFunDef, XtdFunDef

public abstract class FunDefBase
extends FunUtil
implements FunDef

FunDefBase is the default implementation of FunDef.

Signatures

A function is defined by the following:

ParameterMeaningExample
nameName of the function"Members"
signature Signature of the function "<Dimension>.Members"
description Description of the function "Returns the set of all members in a dimension."
flags Encoding of the syntactic type, return type, and parameter types of this operator. The encoding is described below. "pxd"
The flags field is an string which encodes the syntactic type, return type, and parameter types of this operator.

For example, "pxd" means "an operator with property syntax (p) which returns a set (x) and takes a dimension (d) as its argument".

The arguments are always read from left to right, regardless of the syntactic type of the operator. For example, the "<Set>.Item(<Index>)" operator (signature "mmxn") has the syntax of a method-call, and takes two parameters: a set (x) and a numeric (n).

Since:
26 February, 2002
Author:
jhyde
 

Nested Class Summary
 
Nested classes/interfaces inherited from class mondrian.olap.fun.FunUtil
FunUtil.SetWrapper
 
Nested classes/interfaces inherited from class mondrian.olap.Util
Util.ErrorCellValue, Util.PropertyList
 
Field Summary
protected  int flags
           
protected  int[] parameterCategories
           
protected  int returnCategory
           
(package private)  String signature
           
 
Fields inherited from class mondrian.olap.fun.FunUtil
BooleanNull, DoubleEmpty, DoubleNull, emptyStringArray, IntegerNull, NullMember
 
Fields inherited from class mondrian.olap.Util
EmptyValue, JdbcVersion, nl, nullValue, PreJdk15, Retrowoven
 
Constructor Summary
(package private) FunDefBase(FunDef funDef)
          Copy constructor.
(package private) FunDefBase(Resolver resolver, int returnType, int[] parameterTypes)
          Convenience constructor when we are created by a Resolver.
protected FunDefBase(String name, String description, String flags)
          Creates an operator.
protected FunDefBase(String name, String signature, String description, String flags)
          Creates an operator with an explicit signature.
(package private) FunDefBase(String name, String signature, String description, Syntax syntax, int returnCategory, int[] parameterCategories)
          Creates an operator.
 
Method Summary
(package private) static Type castType(Type type, int category)
          Converts a type to a different category, maintaining as much type information as possible.
 Calc compileCall(ResolvedFunCall call, ExpCompiler compiler)
          Converts a call to this function into executable objects.
 Exp createCall(Validator validator, Exp[] args)
          Creates an expression which represents a call to this function with a given set of arguments.
 String getDescription()
          Returns the description of this function.
 String getName()
          Returns the name of this function.
 int[] getParameterCategories()
          Returns the types of the arguments of this function.
 Type getResultType(Validator validator, Exp[] args)
          Returns the type of a call to this function with a given set of arguments.

The default implementation makes the coarse assumption that the return type is in some way related to the type of the first argument.

 int getReturnCategory()
          Returns the Category code of the value returned by this function.
 String getSignature()
          Returns an English description of the signature of the function, for example "<Numeric Expression> / <Numeric Expression>".
 Syntax getSyntax()
          Returns the syntactic type of the function.
 void unparse(Exp[] args, PrintWriter pw)
          Converts a function call into MDX source code.
protected  Exp validateArg(Validator validator, Exp[] args, int i, int category)
          Validates an argument to a call to this function.
 
Methods inherited from class mondrian.olap.fun.FunUtil
addMembers, addMembers, addUnique, ancestor, appendTuple, avg, checkCompatible, checkFlag, checkIterListResultStyles, checkListResultStyles, compareHierarchically, compareSiblingMembers, compareValues, compareValues, compareValues, correlation, count, cousin, covariance, createDummyFunDef, decodeCategory, decodeParameterCategories, decodeReturnCategory, decodeSyntacticType, dimensionMembers, equalTuple, evaluateMembers, evaluateMembers, evaluateSet, evaluateSet, evaluateTuples, getLiteralArg, getLiteralArg, getNonEmptyLevelMembers, getNonEmptyMemberChildren, hierarchize, hierarchyMembers, isAncestorOf, isMemberType, levelMembers, makeNullMember, makeNullTuple, max, memberRange, min, newEvalException, newEvalException, percentile, periodsToDate, quartile, removeCalculatedMembers, resolveFunArgs, searchValuesDesc, sign, sortMembers, sortTuples, sortValuesDesc, stdev, sum, sumDouble, sumDouble, toPercent, tupleContainsNullMember, var
 
Methods inherited from class mondrian.olap.Util
addDatabaseTime, addLevelCalculatedMembers, areOccurencesEqual, assertPostcondition, assertPostcondition, assertPrecondition, assertPrecondition, assertTrue, assertTrue, badValue, camelToUpper, caseSensitiveCompareName, cast, cast, checkCJResultLimit, commaList, compareKey, compareName, convertStackToString, createExpr, createRandom, createSimpleValidator, createUdf, dbTimeMillis, deprecated, enumSetAllOf, enumSetNoneOf, enumSetOf, equal, equalName, equals, equals, getAnnotation, getErrorMessage, getErrorMessage, getFirstDescendantOnLevel, getMemberOrdinalInParent, hash, hash, hashArray, implode, isEmpty, isNull, isSorted, isValidProperty, lookup, lookup, lookup, lookup, lookupCompound, lookupCompound, lookupHierarchyLevel, lookupHierarchyRootMember, lookupHierarchyRootMember, lookupProperty, makeBigDecimalFromDouble, makeFqName, makeFqName, makeFqName, maskVersion, mdxEncodeString, needToImplement, newError, newError, newInternal, newInternal, nonDbTimeMillis, normalizeName, parseCommaList, parseConnectString, parseIdentifier, printMemory, printMemory, quoteForMdx, quoteMdxIdentifier, quoteMdxIdentifier, quoteMdxIdentifier, quoteMdxIdentifier, quotePattern, readFully, readURL, readURL, readURL, readURL, replace, replace, replaceProperties, singleQuoteString, singleQuoteString, toMap, toURL, unexpected, union, union, uniquify, unparse, unparse, wildcardToRegexp
 
Methods inherited from class org.eigenbase.xom.XOMUtil
addAll, addAll, addChild, addChild, addChildren, addElement, concatenate, createDefaultParser, discard, discard, discard, discard, discard, discard, discard, discard, discard, getFirstInstance, toList, toVector, wrapperToXml
 
Methods inherited from class org.eigenbase.xom.XMLUtil
getFirstTagName, printAtt, printAtt, printAtt, printAtt, printPCDATA, printPCDATA, printPCDATA, quoteAtt, quoteAtt, quoteAtt, quoteAtt, quotePCDATA, stringEncodeXML, stringHasXMLSpecials
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

flags

protected final int flags

signature

final String signature

returnCategory

protected final int returnCategory

parameterCategories

protected final int[] parameterCategories
Constructor Detail

FunDefBase

FunDefBase(String name,
           String signature,
           String description,
           Syntax syntax,
           int returnCategory,
           int[] parameterCategories)
Creates an operator.

Parameters:
name - Name of the function, for example "Members".
signature - Signature of the function, for example "<Dimension>.Members".
description - Description of the function, for example "Returns the set of all members in a dimension."
syntax - Syntactic type of the operator (for example, function, method, infix operator)
returnCategory - The Category of the value returned by this operator.
parameterCategories - An array of Category codes, one for each parameter.

FunDefBase

protected FunDefBase(String name,
                     String description,
                     String flags)
Creates an operator.

Parameters:
name - Name of the function, for example "Members".
description - Description of the function, for example "Returns the set of all members in a dimension."
flags - Encoding of the syntactic type, return type, and parameter types of this operator. The "Members" operator has a syntactic type "pxd" which means "an operator with property syntax (p) which returns a set (x) and takes a dimension (d) as its argument". See FunUtil.decodeSyntacticType(String), FunUtil.decodeReturnCategory(String), FunUtil.decodeParameterCategories(String).

FunDefBase

protected FunDefBase(String name,
                     String signature,
                     String description,
                     String flags)
Creates an operator with an explicit signature.

In most cases, the signature can be generated automatically, and you should use the constructor which creates an implicit signature, FunDefBase(String, String, String, String) instead.

Parameters:
name - Name of the function, for example "Members".
signature - Signature of the function, for example "<Dimension>.Members".
description - Description of the function, for example "Returns the set of all members in a dimension."
flags - Encoding of the syntactic type, return type, and parameter types of this operator. The "Members" operator has a syntactic type "pxd" which means "an operator with property syntax (p) which returns a set (x) and takes a dimension (d) as its argument". See FunUtil.decodeSyntacticType(String), FunUtil.decodeReturnCategory(String), FunUtil.decodeParameterCategories(String).

FunDefBase

FunDefBase(Resolver resolver,
           int returnType,
           int[] parameterTypes)
Convenience constructor when we are created by a Resolver.

Parameters:
resolver - Resolver
returnType - Return type
parameterTypes - Parameter types

FunDefBase

FunDefBase(FunDef funDef)
Copy constructor.

Parameters:
funDef - Function definition to copy
Method Detail

getName

public String getName()
Description copied from interface: FunDef
Returns the name of this function.

Specified by:
getName in interface FunDef

getDescription

public String getDescription()
Description copied from interface: FunDef
Returns the description of this function.

Specified by:
getDescription in interface FunDef

getSyntax

public Syntax getSyntax()
Description copied from interface: FunDef
Returns the syntactic type of the function.

Specified by:
getSyntax in interface FunDef

getReturnCategory

public int getReturnCategory()
Description copied from interface: FunDef
Returns the Category code of the value returned by this function.

Specified by:
getReturnCategory in interface FunDef

getParameterCategories

public int[] getParameterCategories()
Description copied from interface: FunDef
Returns the types of the arguments of this function. Values are the same as those returned by Exp.getCategory(). The 0th argument of methods and properties are the object they are applied to. Infix operators have two arguments, and prefix operators have one argument.

Specified by:
getParameterCategories in interface FunDef

createCall

public Exp createCall(Validator validator,
                      Exp[] args)
Description copied from interface: FunDef
Creates an expression which represents a call to this function with a given set of arguments. The result is usually a ResolvedFunCall but not always.

Specified by:
createCall in interface FunDef

validateArg

protected Exp validateArg(Validator validator,
                          Exp[] args,
                          int i,
                          int category)
Validates an argument to a call to this function.

The default implementation of this method adds an implicit conversion to the correct type. Derived classes may override.

Parameters:
validator - Validator
args - Arguments to this function
i - Ordinal of argument
category - Expected category of argument
Returns:
Validated argument

castType

static Type castType(Type type,
                     int category)
Converts a type to a different category, maintaining as much type information as possible. For example, given LevelType(dimension=Time, hierarchy=unknown, level=unkown) and category=Hierarchy, returns HierarchyType(dimension=Time).

Parameters:
type - Type
category - Desired category
Returns:
Type after conversion to desired category

getResultType

public Type getResultType(Validator validator,
                          Exp[] args)
Returns the type of a call to this function with a given set of arguments.

The default implementation makes the coarse assumption that the return type is in some way related to the type of the first argument. Operators whose arguments don't follow the requirements of this implementation should override this method.

If the function definition says it returns a literal type (numeric, string, symbol) then it's a fair guess that the function call returns the same kind of value.

If the function definition says it returns an object type (cube, dimension, hierarchy, level, member) then we check the first argument of the function. Suppose that the function definition says that it returns a hierarchy, and the first argument of the function happens to be a member. Then it's reasonable to assume that this function returns a member.

Parameters:
validator - Validator
args - Arguments to the call to this operator
Returns:
result type of a call this function

compileCall

public Calc compileCall(ResolvedFunCall call,
                        ExpCompiler compiler)
Description copied from interface: FunDef
Converts a call to this function into executable objects.

The result must implement the appropriate interface for the result type. For example, a function which returns an integer must return an object which implements IntegerCalc.

Specified by:
compileCall in interface FunDef

getSignature

public String getSignature()
Description copied from interface: FunDef
Returns an English description of the signature of the function, for example "<Numeric Expression> / <Numeric Expression>".

Specified by:
getSignature in interface FunDef

unparse

public void unparse(Exp[] args,
                    PrintWriter pw)
Description copied from interface: FunDef
Converts a function call into MDX source code.

Specified by:
unparse in interface FunDef

SourceForge.net_Logo