public class FunUtil extends Util
FunUtil
contains a set of methods useful within the mondrian.olap.fun
package.Modifier and Type | Class and Description |
---|---|
static class |
FunUtil.DescendingValueComparator
Compares cell values, so that larger values compare first.
|
static class |
FunUtil.ObjIntPair<T>
Tuple consisting of an object and an integer.
|
static class |
FunUtil.OrderKey |
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
Modifier and Type | Field and Description |
---|---|
static boolean |
BooleanNull
Null value in three-valued boolean logic.
|
static double |
DoubleEmpty
Special value which indicates that a
double computation
has returned the MDX EMPTY value. |
static double |
DoubleNull
Special value which indicates that a
double computation
has returned the MDX null value. |
static int |
IntegerNull
Special value which indicates that an
int computation
has returned the MDX null value. |
static mondrian.olap.fun.FunUtil.NullMember |
NullMember |
DEBUG, EmptyValue, IBM_JVM, JdbcVersion, JVM_INSTANCE_UUID, nl, nullValue, Retrowoven
Constructor and Description |
---|
FunUtil() |
Modifier and Type | Method and 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, if
post 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 the
offset 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 void |
hierarchizeMemberList(List<Member> memberList,
boolean post)
Sorts a list of members into hierarchical order.
|
static TupleList |
hierarchizeTupleList(TupleList tupleList,
boolean post)
Sorts a list of tuples into hierarchical order.
|
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(FunDef funDef,
String message)
Creates an exception which indicates that an error has occurred while
executing a given function.
|
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 List<Member> |
partiallySortMembers(Evaluator evaluator,
List<Member> list,
Calc exp,
int limit,
boolean desc)
Partially sorts a list of Members by the value of an applied expression.
|
static List<List<Member>> |
partiallySortTuples(Evaluator evaluator,
TupleList list,
Calc exp,
int limit,
boolean desc)
Partially sorts a list of Tuples by the value of an applied expression.
|
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 TupleList |
sortTuples(Evaluator evaluator,
TupleIterable tupleIterable,
TupleList tupleList,
Calc exp,
boolean desc,
boolean brk,
int arity)
Sorts a list of Tuples by the value of an applied expression.
|
static <T> List<T> |
stablePartialSort(List<T> list,
Comparator<T> comp,
int limit)
Stable partial sort of a list.
|
static <T> List<T> |
stablePartialSort(List<T> list,
Comparator<T> comp,
int limit,
int algorithm)
Stable partial sort of a list, using a specified algorithm.
|
static <T> List<T> |
stablePartialSortArray(List<T> list,
Comparator<T> comp,
int limit)
Partial sort an array by sorting it and returning the first
limit
elements. |
static <T> List<T> |
stablePartialSortJulian(List<T> list,
Comparator<T> comp,
int limit)
Julian's algorithm for stable partial sort.
|
static <T> List<T> |
stablePartialSortMarc(List<T> list,
Comparator<T> comp,
int limit)
Marc's original algorithm for stable partial sort of a list.
|
static <T> List<T> |
stablePartialSortPedro(List<T> list,
Comparator<T> comp,
int limit)
Pedro's algorithm for stably sorting the top
limit items in
a list. |
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( ...
|
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, falseFunctor, filter, flatList, flatList, flatListCopy, generateUuidString, genericArray, getAnnotation, getClosestResource, getDimensionCube, getErrorMessage, getErrorMessage, getExecutorService, getFirstDescendantOnLevel, getMatchingCause, getMemberOrdinalInParent, getMembersToHierarchyMap, 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, 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, replace, replace, replaceProperties, safeGet, singleQuoteString, singleQuoteString, sort, sort, threadLocalRemove, toMap, toNullValuesMap, toOlap4j, toOlap4j, toOlap4j, toURL, trueFunctor, unexpected, uniquify, unparse, unparse, wildcardToRegexp
addChild, addChild, addChildren, addElement, concatenate, createDefaultParser, discard, discard, discard, discard, discard, discard, discard, discard, discard, getFirstInstance, wrapperToXml
public static final mondrian.olap.fun.FunUtil.NullMember NullMember
public static final double DoubleNull
double
computation
has returned the MDX null value. See DoubleCalc
.public static final double DoubleEmpty
double
computation
has returned the MDX EMPTY value. See DoubleCalc
.public static final int IntegerNull
int
computation
has returned the MDX null value. See IntegerCalc
.public static final boolean BooleanNull
public static RuntimeException newEvalException(FunDef funDef, String message)
funDef
- Function being executedmessage
- Explanatory messagepublic static RuntimeException newEvalException(Throwable throwable)
throwable
- Exceptionpublic static RuntimeException newEvalException(String message, Throwable throwable)
message
- Explanatory messagethrowable
- Exceptionpublic static void checkIterListResultStyles(Calc calc)
public static void checkListResultStyles(Calc calc)
public static Hierarchy getDimensionDefaultHierarchy(Dimension dimension)
dimension
- DimensionMondrianResource.CannotImplicitlyConvertDimensionToHierarchy
public static TupleList sortTuples(Evaluator evaluator, TupleIterable tupleIterable, TupleList tupleList, Calc exp, boolean desc, boolean brk, int arity)
Helper function for MDX functions TopCount, TopSum, TopPercent, BottomCount, BottomSum, BottomPercent, but not the MDX function Order.
NOTE: This function does not preserve the contents of the validator.
If you specify tupleList
, the list is sorted in place, and
tupleList is returned.
evaluator
- EvaluatortupleIterable
- Iterator over tuplestupleList
- List of tuples, if known, otherwise nullexp
- Expression to sort ondesc
- Whether to sort descendingbrk
- Whether to breakarity
- Number of members in each tuplepublic static List<Member> partiallySortMembers(Evaluator evaluator, List<Member> list, Calc exp, int limit, boolean desc)
Avoids sorting the whole list, finds only the ntop (or bottom) valued Members, and returns them as a new List. Helper function for MDX functions TopCount and BottomCount.
NOTE: Does not preserve the contents of the validator.
list
- a list of membersexp
- a Calc applied to each member to find its sort-keyevaluator
- Evaluatorlimit
- maximum count of members to return.desc
- true to sort descending (and find TopCount), false to sort
ascending (and find BottomCount).public static List<List<Member>> partiallySortTuples(Evaluator evaluator, TupleList list, Calc exp, int limit, boolean desc)
Avoids sorting the whole list, finds only the n top (or bottom) valued Tuples, and returns them as a new List. Helper function for MDX functions TopCount and BottomCount.
NOTE: Does not preserve the contents of the validator. The returned list is immutable.
evaluator
- Evaluatorlist
- a list of tuplesexp
- a Calc applied to each tuple to find its sort-keylimit
- maximum count of tuples to return.desc
- true to sort descending (and find TopCount),
false to sort ascending (and find BottomCount).public static void hierarchizeMemberList(List<Member> memberList, boolean post)
memberList
- List of memberspost
- Whether to sort in post order; if false, sorts in pre orderhierarchizeTupleList(mondrian.calc.TupleList, boolean)
public static TupleList hierarchizeTupleList(TupleList tupleList, boolean post)
tupleList
- List of tuplespost
- Whether to sort in post order; if false, sorts in pre orderhierarchizeMemberList(java.util.List, boolean)
public static int compareValues(double d1, double d2)
MDX requires a total order:
-inf < NULL < ... < -1 < ... < 0 < ... < NaN < +infbut this is different than Java semantics, specifically with regard to
Double.NaN
.public static int compareValues(Object value0, Object value1)
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.
value0
- First cell valuevalue1
- Second cell valuepublic static Syntax decodeSyntacticType(String flags)
flags
- A encoded string which represents an operator signature,
as used by the flags
parameter used to construct a
FunDefBase
.Syntax
public static int decodeReturnCategory(String flags)
For example, decodeReturnType("fnx")
returns
, indicating this function has a
numeric return value.Category.Numeric
flags
- The signature of an operator,
as used by the flags
parameter used to construct a
FunDefBase
.Category
codes.public static int decodeCategory(String flags, int offset)
offset
th character of an encoded method
signature into a type category.
The codes are:
flags
- Encoded signature stringoffset
- 0-based offset of character within stringCategory
public static int[] decodeParameterCategories(String flags)
Each character is decoded using decodeCategory(String, int)
.
For example, decodeParameterTypes("nx")
returns
{
.Category.Numeric
, Category.Set
}
flags
- The signature of an operator,
as used by the flags
parameter used to construct a
FunDefBase
.Category
codes.public static Double box(double d)
DoubleNull
becomes null.public static Integer box(int n)
IntegerNull
becomes null.protected static double quartile(Evaluator evaluator, TupleList members, Calc exp, int range)
evaluator
- Evaluatormembers
- List of membersexp
- Expression to rank membersrange
- Quartile (1, 2 or 3)public static double sumDouble(Evaluator evaluator, TupleIterable iterable, Calc exp)
public static int count(Evaluator evaluator, TupleIterable iterable, boolean includeEmpty)
public static int compareHierarchically(Member m1, Member m2, boolean post)
post
is true) walk
over a hierarchy.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.public static int compareSiblingMembers(Member m1, Member m2)
If the ordinals do not differ, compare using regular member comparison.
m1
- First memberm2
- Second memberpublic static boolean tupleContainsNullMember(Member[] tuple)
public static boolean tupleContainsNullMember(List<Member> tuple)
public static FunDef resolveFunArgs(Validator validator, FunDef funDef, Exp[] args, Exp[] newArgs, String name, Syntax syntax)
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 functionpublic static List<Member> getNonEmptyMemberChildren(Evaluator evaluator, Member member)
public static Map<Member,Access> getNonEmptyMemberChildrenWithDetails(Evaluator evaluator, Member member)
public static <T> List<T> stablePartialSort(List<T> list, Comparator<T> comp, int limit)
public static <T> List<T> stablePartialSort(List<T> list, Comparator<T> comp, int limit, int algorithm)
public static <T> List<T> stablePartialSortArray(List<T> list, Comparator<T> comp, int limit)
limit
elements. Fastest approach if limit is a significant fraction of the
list.public static <T> List<T> stablePartialSortMarc(List<T> list, Comparator<T> comp, int limit)
stablePartialSortJulian(java.util.List<T>, java.util.Comparator<T>, int)
.public static <T> List<T> stablePartialSortPedro(List<T> list, Comparator<T> comp, int limit)
limit
items in
a list.public static <T> List<T> stablePartialSortJulian(List<T> list, Comparator<T> comp, int limit)
limit
items seen.
The items on the priority queue have an ordinal field, so the queue
can be used to generate a list of stably sorted items. (Heap sort is
not normally stable.)T
- Element typelist
- List to sortcomp
- Comparatorlimit
- Maximum number of items to returnpublic static boolean worthCaching(Exp exp)
exp
- ExpressionCopyright © 2020 Hitachi Vantara. All rights reserved.