Class ObjectAgg


public class ObjectAgg extends AggregateFunction
OBJECT_AGG(key, value) — aggregates key/value pairs into a single OBJECT. Pairs with a NULL key or NULL value are omitted; the result is canonical JSON text (keys sorted), the engine's OBJECT form.
  • Constructor Details

    • ObjectAgg

      public ObjectAgg()
  • Method Details

    • semiStructuredRejection

      public SemiStructuredRejection semiStructuredRejection(int position)
      The KEY is never semi-structured, plain or not: live, OBJECT_AGG(o, n) is "Invalid argument types for function 'OBJECT_AGG': (OBJECT, NUMBER(38,0))" and OBJECT_AGG(so, n) / OBJECT_AGG(sa, n) are the same sentence with the structured type named. Position 1, the VALUE, is where the two kinds diverge — see structuredRejection(int).
      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
    • structuredRejection

      public SemiStructuredRejection structuredRejection(int position)
      The VALUE takes a plain OBJECT or ARRAY and refuses a STRUCTURED one: live, OBJECT_AGG(s, o) builds {"aa":{"k":"v1"},…} while OBJECT_AGG(s, so) is "Invalid argument types for function 'OBJECT_AGG': (VARCHAR(16777216), OBJECT(x VARCHAR(16777216)))" — the message lists BOTH arguments, so the offending position is visible.
      Overrides:
      structuredRejection in class BuiltInFunction
      Parameters:
      position - the zero-based argument position being asked about
      Returns:
      the extra refusal this position gives a structured value, or NONE when undeclared
    • fileRejection

      public SemiStructuredRejection fileRejection(int position)
      A FILE is refused in BOTH halves, which is where it parts company with the plain OBJECT the VALUE position accepts: live, OBJECT_AGG(f, 1) is "Invalid argument types for function 'OBJECT_AGG': (FILE, NUMBER(1,0))" and OBJECT_AGG(s, f) is the same sentence naming "(VARCHAR(16777216), FILE)", while OBJECT_AGG(s, o) builds its object happily. Without this the inherited default would read semiStructuredRejection(int) and let the value half through.
      Overrides:
      fileRejection in class BuiltInFunction
      Parameters:
      position - the zero-based argument position being asked about
      Returns:
      the refusal this position gives a FILE value; by default, the semi-structured answer
    • textRejection

      public SemiStructuredRejection textRejection(int position)
      The VALUE takes a NUMBER, a BOOLEAN, a FLOAT or a VARIANT (cast to VARIANT in the plan) and refuses a VARCHAR, a temporal or a BINARY with the argument-type list — OBJECT_AGG(t, t) is "Invalid argument types for function 'OBJECT_AGG': (VARCHAR(10), VARCHAR(10))", OBJECT_AGG(t, d) "(VARCHAR(10), DATE)" — while the KEY takes any of them, cast to text (live-verified).
      Overrides:
      textRejection in class BuiltInFunction
    • temporalRejection

      public SemiStructuredRejection temporalRejection(int position)
      Description copied from class: BuiltInFunction
      The refusal this position gives a declared DATE / TIME / TIMESTAMP argument. Declared per function: the numeric family refuses every temporal flavour at compile time, each named with its own parameters — (DATE), (TIME(9)), (TIMESTAMP_NTZ(9)) and the LTZ/TZ twins — where the datetime functions read them happily.
      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
    • 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
    • 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