java.lang.Object
dev.frostlake.functions.BuiltInFunction
dev.frostlake.functions.scalar.conditional.NullIf

public class NullIf extends BuiltInFunction
  • Constructor Details

    • NullIf

      public NullIf()
  • Method Details

    • geoRejection

      public SemiStructuredRejection geoRejection(int position)
      NULLIF compares its two arguments, and a GEOSPATIAL value does not compare: live NULLIF(g, g) is "Invalid argument types for function 'NULLIF': (GEOGRAPHY, GEOGRAPHY)" (SQLSTATE 42P13), while COALESCE(g, NULL) — which chooses without comparing — returns the geo value.
      Overrides:
      geoRejection in class BuiltInFunction
      Parameters:
      position - the zero-based argument position being asked about
      Returns:
      the refusal this position gives a GEOGRAPHY or GEOMETRY value; by default, the union of the two semi-structured answers
    • evaluate

      public Object evaluate(List<Object> args)
      NULLIF(a, b) is CASE WHEN a = b THEN NULL ELSE a END, so it decides equality the way the = operator does — by VALUE, across the type families. Deciding it with Object.equals(java.lang.Object) instead made the answer depend on a runtime class the SQL cannot see: NULLIF(1.00, 1) handed back 1.00 because a BigDecimal is not a Long, and the same split hid every mixed-family pair — a boolean beside a number, a numeric string beside a number, a DATE beside a TIMESTAMP at the same instant. A NULL on either side is never compared: SQL NULL is not equal to anything, so the first argument stands.
      Specified by:
      evaluate in class BuiltInFunction
      Parameters:
      args - the argument values, in call order
      Returns:
      the function's value for these arguments, or null for SQL NULL
    • evaluate

      public Object evaluate(List<Object> args, CollationSpec collation)
      Under a collation the two are compared by its rules, so a case-blind pair answers NULL.
      Overrides:
      evaluate in class BuiltInFunction
      Parameters:
      args - the argument values, in call order
      collation - the collation the call settled on, or null when it carries none
      Returns:
      the function's value for these arguments, or null for SQL NULL
    • getMinArgCount

      public int getMinArgCount()
      Description copied from class: BuiltInFunction
      The fewest arguments a call to this function may pass; fewer is an argument-count error.
      Specified by:
      getMinArgCount in class BuiltInFunction
      Returns:
      the minimum accepted argument count
    • getMaxArgCount

      public int getMaxArgCount()
      Description copied from class: BuiltInFunction
      The most arguments a call to this function may pass; Integer.MAX_VALUE marks a variadic function (see BuiltInFunction.isVariadic()).
      Specified by:
      getMaxArgCount in class BuiltInFunction
      Returns:
      the maximum accepted argument count