Package mondrian.olap.fun
Class FunUtil
- java.lang.Object
-
- org.eigenbase.xom.XMLUtil
-
- org.eigenbase.xom.XOMUtil
-
- mondrian.olap.Util
-
- mondrian.olap.fun.FunUtil
-
- Direct Known Subclasses:
CacheFunDef.CacheFunResolver
,FunDefBase
,MultiResolver
public class FunUtil extends Util
FunUtil
contains a set of methods useful within themondrian.olap.fun
package.- Since:
- 1.0
- Author:
- jhyde
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FunUtil.DescendingValueComparator
Compares cell values, so that larger values compare first.-
Nested classes/interfaces inherited from class mondrian.olap.Util
Util.AbstractFlatList<T>, Util.ByteMatcher, Util.ErrorCellValue, Util.Flat2List<T>, Util.Flat3List<T>, Util.Functor1<RT,PT>, Util.GcIterator<T>, Util.MemoryInfo, Util.PropertyList, Util.SqlNullSafeComparator
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
BooleanNull
Null value in three-valued boolean logic.static double
DoubleEmpty
Special value which indicates that adouble
computation has returned the MDX EMPTY value.static double
DoubleNull
Special value which indicates that adouble
computation has returned the MDX null value.static int
IntegerNull
Special value which indicates that anint
computation has returned the MDX null value.static mondrian.olap.fun.FunUtil.NullMember
NullMember
-
Fields inherited from class mondrian.olap.Util
DEBUG, EmptyValue, IBM_JVM, JdbcVersion, JVM_INSTANCE_UUID, nl, nullValue, Retrowoven
-
-
Constructor Summary
Constructors Constructor Description FunUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Object
avg(Evaluator evaluator, TupleList members, Calc calc)
static Double
box(double d)
Converts a double (primitive) value to a Double.static Integer
box(int n)
Converts an int (primitive) value to an Integer.static void
checkIterListResultStyles(Calc calc)
static void
checkListResultStyles(Calc calc)
static int
compareHierarchically(Member m1, Member m2, boolean post)
Compares a pair of members according to their positions in a prefix-order (or postfix-order, ifpost
is true) walk over a hierarchy.static int
compareSiblingMembers(Member m1, Member m2)
Compares two members which are known to have the same parent.static int
compareValues(double d1, double d2)
Compares double-precision values according to MDX semantics.static int
compareValues(Object value0, Object value1)
Compares two cell values.static int
count(Evaluator evaluator, TupleIterable iterable, boolean includeEmpty)
static int
decodeCategory(String flags, int offset)
Decodes theoffset
th character of an encoded method signature into a type category.static int[]
decodeParameterCategories(String flags)
Decodes a string of parameter types into an array of type codes.static int
decodeReturnCategory(String flags)
Decodes the signature of a function into a category code which describes the return type of the operator.static Syntax
decodeSyntacticType(String flags)
Decodes the syntactic type of an operator.static Hierarchy
getDimensionDefaultHierarchy(Dimension dimension)
Returns the default hierarchy of a dimension, or null if there is no default.static List<Member>
getNonEmptyMemberChildren(Evaluator evaluator, Member member)
static Map<Member,Access>
getNonEmptyMemberChildrenWithDetails(Evaluator evaluator, Member member)
static boolean
isAncestorOf(Member m0, Member m1, boolean strict)
Returns whetherm0
is an ancestor ofm1
.static Member[]
makeNullTuple(TupleType tupleType)
static Object
max(Evaluator evaluator, TupleList members, Calc exp)
static Object
min(Evaluator evaluator, TupleList members, Calc calc)
static RuntimeException
newEvalException(String message, Throwable throwable)
Creates an exception which indicates that an error has occurred while executing a given function.static RuntimeException
newEvalException(Throwable throwable)
Creates an exception which indicates that an error has occurred while executing a given function.static RuntimeException
newEvalException(FunDef funDef, String message)
Creates an exception which indicates that an error has occurred while executing a given function.protected static double
quartile(Evaluator evaluator, TupleList members, Calc exp, int range)
Returns the member which lies upon a particular quartile according to a given expression.static FunDef
resolveFunArgs(Validator validator, FunDef funDef, Exp[] args, Exp[] newArgs, String name, Syntax syntax)
Validates the arguments to a function and resolves the function.static Object
sum(Evaluator evaluator, TupleList members, Calc exp)
static double
sumDouble(Evaluator evaluator, TupleIterable iterable, Calc exp)
static double
sumDouble(Evaluator evaluator, TupleList members, Calc exp)
static boolean
tupleContainsNullMember(List<Member> tuple)
Returns whether one of the members in a tuple is null.static boolean
tupleContainsNullMember(Member[] tuple)
Returns whether one of the members in a tuple is null.static boolean
worthCaching(Exp exp)
Returns whether an expression is worth wrapping in "Cache( ...-
Methods inherited from class mondrian.olap.Util
addAppender, addDatabaseTime, addLevelCalculatedMembers, append, appendArrays, areOccurencesEqual, assertPostcondition, assertPostcondition, assertPrecondition, assertPrecondition, assertTrue, assertTrue, badValue, binarySearch, bitSetBetween, camelToUpper, canCast, cancelStatement, caseSensitiveCompareName, cast, cast, castToIterable, checkCJResultLimit, close, commaList, compare, compareIntegers, compareKey, compareName, compileScript, convert, convert, convertOlap4jConnectStringToNativeMondrian, convertStackToString, copyOf, copyOf, copyOf, copyOf, copyOf, createExpr, createRandom, createRootRole, createSimpleValidator, createUdf, dbTimeMillis, deprecated, deprecated, digestMd5, digestSha256, equal, equalName, equals, equals, explain, falseFunctor, filter, flatList, flatList, flatListCopy, generateUuidString, genericArray, getAnnotation, getClosestResource, getDimensionCube, getErrorMessage, getErrorMessage, getExecutorService, getFirstDescendantOnLevel, getMatchingCause, getMemberOrdinalInParent, getMemoryInfo, getScheduledExecutorService, hash, hash, hashArray, identityFunctor, implode, intersect, isBlank, isEmpty, isNull, isSorted, isValidProperty, last, lookup, lookup, lookup, lookup, lookup, lookupCompound, lookupCompound, lookupHierarchyLevel, lookupHierarchyRootMember, lookupHierarchyRootMember, lookupProperty, makeAppender, makeBigDecimalFromDouble, makeFqName, makeFqName, makeFqName, matches, matches, mdxEncodeString, needToImplement, newElementNotFoundException, newError, newError, newIdentityHashSet, newIdentityHashSetFake, newInternal, newInternal, newTimer, nonDbTimeMillis, normalizeName, only, parseCommaList, parseConnectString, parseIdentifier, parseInterval, parseLocale, printMemory, printMemory, quoteForMdx, quoteForMdx, quoteJavaString, quoteMdxIdentifier, quoteMdxIdentifier, quoteMdxIdentifier, quoteMdxIdentifier, quotePattern, readFully, readFully, readURL, readURL, readURL, readVirtualFile, readVirtualFileAsString, removeAppender, replace, replace, replaceProperties, safeGet, setLevel, singleQuoteString, singleQuoteString, sort, sort, threadLocalRemove, toMap, toNullValuesMap, toOlap4j, toOlap4j, toOlap4j, toURL, trueFunctor, unexpected, uniquify, unparse, unparse, wildcardToRegexp
-
Methods inherited from class org.eigenbase.xom.XOMUtil
addChild, addChild, addChildren, addElement, concatenate, createDefaultParser, discard, discard, discard, discard, discard, discard, discard, discard, discard, getFirstInstance, wrapperToXml
-
-
-
-
Field Detail
-
NullMember
public static final mondrian.olap.fun.FunUtil.NullMember NullMember
-
DoubleNull
public static final double DoubleNull
Special value which indicates that adouble
computation has returned the MDX null value. SeeDoubleCalc
.- See Also:
- Constant Field Values
-
DoubleEmpty
public static final double DoubleEmpty
Special value which indicates that adouble
computation has returned the MDX EMPTY value. SeeDoubleCalc
.- See Also:
- Constant Field Values
-
IntegerNull
public static final int IntegerNull
Special value which indicates that anint
computation has returned the MDX null value. SeeIntegerCalc
.- See Also:
- Constant Field Values
-
BooleanNull
public static final boolean BooleanNull
Null value in three-valued boolean logic. Actually, a placeholder until we actually implement 3VL.- See Also:
- Constant Field Values
-
-
Method Detail
-
newEvalException
public static RuntimeException newEvalException(FunDef funDef, String message)
Creates an exception which indicates that an error has occurred while executing a given function.- Parameters:
funDef
- Function being executedmessage
- Explanatory message- Returns:
- Exception that can be used as a cell result
-
newEvalException
public static RuntimeException newEvalException(Throwable throwable)
Creates an exception which indicates that an error has occurred while executing a given function.- Parameters:
throwable
- Exception- Returns:
- Exception that can be used as a cell result
-
newEvalException
public static RuntimeException newEvalException(String message, Throwable throwable)
Creates an exception which indicates that an error has occurred while executing a given function.- Parameters:
message
- Explanatory messagethrowable
- Exception- Returns:
- Exception that can be used as a cell result
-
checkIterListResultStyles
public static void checkIterListResultStyles(Calc calc)
-
checkListResultStyles
public static void checkListResultStyles(Calc calc)
-
getDimensionDefaultHierarchy
public static Hierarchy getDimensionDefaultHierarchy(Dimension dimension)
Returns the default hierarchy of a dimension, or null if there is no default.- Parameters:
dimension
- Dimension- Returns:
- Default hierarchy, or null
- See Also:
MondrianResource.CannotImplicitlyConvertDimensionToHierarchy
-
isAncestorOf
public static boolean isAncestorOf(Member m0, Member m1, boolean strict)
Returns whetherm0
is an ancestor ofm1
.- Parameters:
strict
- if true, a member is not an ancestor of itself
-
compareValues
public static int compareValues(double d1, double d2)
Compares double-precision values according to MDX semantics.MDX requires a total order:
-inf < NULL < ... < -1 < ... < 0 < ... < NaN < +inf
but this is different than Java semantics, specifically with regard toDouble.NaN
.
-
compareValues
public static int compareValues(Object value0, Object value1)
Compares two cell values.Nulls compare last, exceptions (including the object which indicates the the cell is not in the cache yet) next, then numbers and strings are compared by value.
- Parameters:
value0
- First cell valuevalue1
- Second cell value- Returns:
- -1, 0, or 1, depending upon whether first cell value is less than, equal to, or greater than the second
-
decodeSyntacticType
public static Syntax decodeSyntacticType(String flags)
Decodes the syntactic type of an operator.- Parameters:
flags
- A encoded string which represents an operator signature, as used by theflags
parameter used to construct aFunDefBase
.- Returns:
- A
Syntax
-
decodeReturnCategory
public static int decodeReturnCategory(String flags)
Decodes the signature of a function into a category code which describes the return type of the operator.For example,
decodeReturnType("fnx")
returns
, indicating this function has a numeric return value.Category.Numeric
- Parameters:
flags
- The signature of an operator, as used by theflags
parameter used to construct aFunDefBase
.- Returns:
- An array
Category
codes.
-
decodeCategory
public static int decodeCategory(String flags, int offset)
Decodes theoffset
th character of an encoded method signature into a type category.The codes are:
- Parameters:
flags
- Encoded signature stringoffset
- 0-based offset of character within string- Returns:
- A
Category
-
decodeParameterCategories
public static int[] decodeParameterCategories(String flags)
Decodes a string of parameter types into an array of type codes.Each character is decoded using
decodeCategory(String, int)
. For example,decodeParameterTypes("nx")
returns{
.Category.Numeric
,Category.Set
}- Parameters:
flags
- The signature of an operator, as used by theflags
parameter used to construct aFunDefBase
.- Returns:
- An array
Category
codes.
-
box
public static Double box(double d)
Converts a double (primitive) value to a Double.DoubleNull
becomes null.
-
box
public static Integer box(int n)
Converts an int (primitive) value to an Integer.IntegerNull
becomes null.
-
quartile
protected static double quartile(Evaluator evaluator, TupleList members, Calc exp, int range)
Returns the member which lies upon a particular quartile according to a given expression.- Parameters:
evaluator
- Evaluatormembers
- List of membersexp
- Expression to rank membersrange
- Quartile (1, 2 or 3)
-
sumDouble
public static double sumDouble(Evaluator evaluator, TupleIterable iterable, Calc exp)
-
count
public static int count(Evaluator evaluator, TupleIterable iterable, boolean includeEmpty)
-
compareHierarchically
public static int compareHierarchically(Member m1, Member m2, boolean post)
Compares a pair of members according to their positions in a prefix-order (or postfix-order, ifpost
is true) walk over a hierarchy.- Parameters:
m1
- First memberm2
- Second memberpost
- Whether to sortMembers in postfix order. If true, a parent will sortMembers immediately after its last child. If false, a parent will sortMembers immediately before its first child.- Returns:
- -1 if m1 collates before m2, 0 if m1 equals m2, 1 if m1 collates after m2
-
compareSiblingMembers
public static int compareSiblingMembers(Member m1, Member m2)
Compares two members which are known to have the same parent.First, compare by ordinal. This is only valid now we know they're siblings, because ordinals are only unique within a parent. If the dimension does not use ordinals, both ordinals will be -1.
If the ordinals do not differ, compare using regular member comparison.
- Parameters:
m1
- First memberm2
- Second member- Returns:
- -1 if m1 collates less than m2, 1 if m1 collates after m2, 0 if m1 == m2.
-
tupleContainsNullMember
public static boolean tupleContainsNullMember(Member[] tuple)
Returns whether one of the members in a tuple is null.
-
tupleContainsNullMember
public static boolean tupleContainsNullMember(List<Member> tuple)
Returns whether one of the members in a tuple is null.
-
resolveFunArgs
public static FunDef resolveFunArgs(Validator validator, FunDef funDef, Exp[] args, Exp[] newArgs, String name, Syntax syntax)
Validates the arguments to a function and resolves the function.- Parameters:
validator
- Validator used to validate function arguments and resolve the functionfunDef
- Function definition, or null to deduce definition from name, syntax and argument typesargs
- Arguments to the functionnewArgs
- Output parameter for the resolved argumentsname
- Function namesyntax
- Syntax style used to invoke function- Returns:
- resolved function definition
-
getNonEmptyMemberChildren
public static List<Member> getNonEmptyMemberChildren(Evaluator evaluator, Member member)
-
getNonEmptyMemberChildrenWithDetails
public static Map<Member,Access> getNonEmptyMemberChildrenWithDetails(Evaluator evaluator, Member member)
-
worthCaching
public static boolean worthCaching(Exp exp)
Returns whether an expression is worth wrapping in "Cache( ... )".- Parameters:
exp
- Expression- Returns:
- Whether worth caching
-
-