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 the mondrian.olap.fun package.
Since:
1.0
Author:
jhyde
  • Field Details

    • NullMember

      public static final mondrian.olap.fun.FunUtil.NullMember NullMember
    • DoubleNull

      public static final double DoubleNull
      Special value which indicates that a double computation has returned the MDX null value. See DoubleCalc.
      See Also:
    • DoubleEmpty

      public static final double DoubleEmpty
      Special value which indicates that a double computation has returned the MDX EMPTY value. See DoubleCalc.
      See Also:
    • IntegerNull

      public static final int IntegerNull
      Special value which indicates that an int computation has returned the MDX null value. See IntegerCalc.
      See Also:
    • BooleanNull

      public static final boolean BooleanNull
      Null value in three-valued boolean logic. Actually, a placeholder until we actually implement 3VL.
      See Also:
  • Constructor Details

    • FunUtil

      public FunUtil()
  • Method Details

    • 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 executed
      message - 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 message
      throwable - 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:
    • isAncestorOf

      public static boolean isAncestorOf(Member m0, Member m1, boolean strict)
      Returns whether m0 is an ancestor of m1.
      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 to Double.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 value
      value1 - 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 the flags parameter used to construct a FunDefBase.
      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 Category.Numeric, indicating this function has a numeric return value.

      Parameters:
      flags - The signature of an operator, as used by the flags parameter used to construct a FunDefBase.
      Returns:
      An array Category codes.
    • decodeCategory

      public static int decodeCategory(String flags, int offset)
      Decodes the offsetth character of an encoded method signature into a type category.

      The codes are:

      aCategory.Array
      dCategory.Dimension
      hCategory.Hierarchy
      lCategory.Level
      bCategory.Logical
      mCategory.Member
      NConstant Category.Numeric
      nCategory.Numeric
      xCategory.Set
      #Constant Category.String
      SCategory.String
      tCategory.Tuple
      vCategory.Value
      yCategory.Symbol
      Parameters:
      flags - Encoded signature string
      offset - 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 the flags parameter used to construct a FunDefBase.
      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 - Evaluator
      members - List of members
      exp - Expression to rank members
      range - Quartile (1, 2 or 3)
    • min

      public static Object min(Evaluator evaluator, TupleList members, Calc calc)
    • max

      public static Object max(Evaluator evaluator, TupleList members, Calc exp)
    • avg

      public static Object avg(Evaluator evaluator, TupleList members, Calc calc)
    • sum

      public static Object sum(Evaluator evaluator, TupleList members, Calc exp)
    • sumDouble

      public static double sumDouble(Evaluator evaluator, TupleList members, Calc exp)
    • 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, if post is true) walk over a hierarchy.
      Parameters:
      m1 - First member
      m2 - Second member
      post - 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 member
      m2 - 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.
    • makeNullTuple

      public static Member[] makeNullTuple(TupleType tupleType)
    • 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 function
      funDef - Function definition, or null to deduce definition from name, syntax and argument types
      args - Arguments to the function
      newArgs - Output parameter for the resolved arguments
      name - Function name
      syntax - 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