Enum Class FunctionProperty

java.lang.Object
java.lang.Enum<FunctionProperty>
com.darkcollective.relix.symbol.FunctionProperty
All Implemented Interfaces:
Serializable, Comparable<FunctionProperty>, Constable

public enum FunctionProperty extends Enum<FunctionProperty>
Optimizer hint flags that may be attached to a function symbol.

Each property makes a contract between the function author and the query optimizer. Declaring a property that the function does not actually satisfy may lead to incorrect query results, so these should be set conservatively.

Properties are stored as a Set on the function symbol, so multiple flags may be combined freely.

Example — a pure, commutative addition built-in:


 ScalarFunctionSymbol.builder("add")
     .property(FunctionProperty.COMMUTATIVE)
     .property(FunctionProperty.PURE)
     .build();
 
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    f(a, b) = f(b, a) — the function produces the same result regardless of argument order.
    The same argument values always produce the same return value.
    f(f(x)) = f(x) — applying the function a second time yields the same result as applying it once.
    The function has no observable side-effects and reads no hidden state (i.e.
    The function reads ambient state, but that state does not change while a query runs — so the call has one value for the whole run, and a different one next time.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the enum constant of this class with the specified name.
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • COMMUTATIVE

      public static final FunctionProperty COMMUTATIVE
      f(a, b) = f(b, a) — the function produces the same result regardless of argument order. The optimizer may reorder arguments or merge symmetric join conditions.
    • DETERMINISTIC

      public static final FunctionProperty DETERMINISTIC
      The same argument values always produce the same return value. The optimizer may cache or deduplicate calls with identical arguments.
    • IDEMPOTENT

      public static final FunctionProperty IDEMPOTENT
      f(f(x)) = f(x) — applying the function a second time yields the same result as applying it once. The optimizer may eliminate redundant nested calls.
    • PURE

      public static final FunctionProperty PURE
      The function has no observable side-effects and reads no hidden state (i.e. it is a pure mathematical function). Implies DETERMINISTIC. The optimizer may freely reorder, eliminate, or hoist calls out of loops.
    • STABLE

      public static final FunctionProperty STABLE
      The function reads ambient state, but that state does not change while a query runs — so the call has one value for the whole run, and a different one next time. NOW() is the case: every row of a query sees the same instant, and the query after it sees a later one.

      This is the middle of three, and the reason two were not enough. DETERMINISTIC says a call may be handed to a backend, which a clock call may not be — the backend would answer from its own clock rather than the one this session was given. Declaring nothing says the value may differ per row, which is true of a random source and not of a clock. Between them sits a call the engine can evaluate once and send the resulting value, which is how a query over "now" reaches the database without the database deciding when "now" is.

      It is a claim about the run, so it obliges the engine as much as the function: a stable call is evaluated against a clock that is read once and pinned for the whole run, which is what makes "one value for the whole run" true rather than merely intended.

      Declaring it alongside DETERMINISTIC says nothing new — a deterministic call is already constant for any run — and a function that is neither is per-row volatile, which is the safe default and needs no property.

  • Method Details

    • values

      public static FunctionProperty[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static FunctionProperty valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null