public class Sum extends AggregateFunction
  • Constructor Details

    • Sum

      public Sum()
  • Method Details

    • createAccumulator

      public AggregateFunction.Accumulator createAccumulator()
      Description copied from class: AggregateFunction
      Creates the fresh, empty per-group state for one evaluation of this aggregate; the executor makes one per group (or per window partition) and never shares them.
      Specified by:
      createAccumulator in class AggregateFunction
      Returns:
      a new accumulator starting from this aggregate's empty-group state
    • evaluate

      public Object evaluate(List<Object> args)
      Description copied from class: BuiltInFunction
      Computes the function's result over its already-evaluated argument values. A SQL NULL argument arrives as Java null, and returning null makes the SQL result NULL.
      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
    • 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
    • temporalRejection

      public SemiStructuredRejection temporalRejection(int position)
      SUM adds numbers, and a semi-structured value is not one. Live, SUM(o) over an OBJECT column is "Invalid argument types for function 'SUM': (OBJECT)" (SQLSTATE 42P13), SUM(a) names ARRAY, and the DISTINCT and windowed forms reject identically — while Frostlake used to answer 0.0, a plausible number a caller could go on to average. A structured column names its whole type: "(OBJECT(x VARCHAR(16777216)))".

      Declared here rather than by extending NumericArgumentFunction only because an aggregate already extends AggregateFunction; the rule is the same one.

      Overrides:
      temporalRejection in class BuiltInFunction
      Parameters:
      position - the zero-based argument position being asked about
      Returns:
      the refusal this position gives a temporal value; by default none
    • booleanRejection

      public SemiStructuredRejection booleanRejection(int position)
      Description copied from class: BuiltInFunction
      The refusal this position gives a declared BOOLEAN argument. Membership is declared per function and never assumed for a family: the whole NUMERIC family (NumericArgumentFunction) refuses a SQL BOOLEAN at compile time in every position — "Invalid argument types for function 'ABS': (BOOLEAN)", MOD(1, TRUE) listing "(NUMBER(1,0), BOOLEAN)" — while the SAME value inside a VARIANT converts to 1.0, and the conditionals (NULLIF(b, 0), NULLIFZERO(b)) take it. The rule reads the DECLARED type, like every channel here.
      Overrides:
      booleanRejection in class BuiltInFunction
      Parameters:
      position - the zero-based argument position being asked about
      Returns:
      the refusal this position gives a BOOLEAN value; by default none
    • binaryRejection

      public SemiStructuredRejection binaryRejection(int position)
      Description copied from class: BuiltInFunction
      The refusal a position gives a statically BINARY-typed value.

      A fifth question rather than a reuse of any of the four above, because BINARY sits on the opposite side of them: it is a scalar a text function is happy to be handed almost everywhere — live answers LENGTH(bn), SUBSTR(bn, 1, 1), CONCAT(bn, bn) — where an OBJECT is refused. Only the functions that read their argument AS TEXT and would have to decode it refuse one, and they say so themselves: VALIDATE_UTF8(bn) and TRY_VALIDATE_UTF8(bn) are "Invalid argument types for function 'TRY_VALIDATE_UTF8': (BINARY(5))" while the same call over a VARCHAR, and even over a NUMBER, returns a value.

      The default is NONE: undeclared means unconstrained, as for the other four.

      Overrides:
      binaryRejection in class BuiltInFunction
      Parameters:
      position - the zero-based argument position being asked about
      Returns:
      the refusal this position gives a BINARY value; by default none
    • semiStructuredRejection

      public SemiStructuredRejection semiStructuredRejection(int position)
      Description copied from class: BuiltInFunction
      How argument position refuses a statically OBJECT- or ARRAY-typed value, or SemiStructuredRejection.NONE when it does not. Snowflake never implicitly coerces a semi-structured value to the VARCHAR (or NUMBER) a text or numeric function reads, so such an argument is an argument-type error at COMPILE time rather than a stringification or a fabricated zero: live, UPPER(o) over an OBJECT column is "Invalid argument types for function 'UPPER': (OBJECT)", SUM(o) is the same sentence for 'SUM', and SPLIT_PART(s, o, 1) names the position it was given. VARIANT is never refused, even when it holds an object.

      Declared HERE, on the function, rather than in a name-keyed table beside the rule: the registry is already the authority on a function's types (BuiltInFunction.getReturnType()), a declaration on the instance covers the function's ALIASES for free (SUBSTR and SUBSTRING are one object, and so are VARIANCE_POP and VAR_POP), and a per-position answer is the only shape that fits — ARRAY_TO_STRING(a, ',') takes an ARRAY in position 0 and refuses one in position 1.

      The answer is an ENUM rather than a boolean because Snowflake phrases the refusal three different ways, with three different SQLSTATEs — see SemiStructuredRejection.

      The default is NONE, meaning UNDECLARED rather than "accepts": a function that has not been measured against live Snowflake constrains nothing. Answering for every position is what TextArgumentFunction and NumericArgumentFunction exist for.

      Overrides:
      semiStructuredRejection in class BuiltInFunction
      Parameters:
      position - the zero-based argument position being asked about
      Returns:
      the refusal this position gives a semi-structured value, or NONE when undeclared