Class JsonExtractPathText

java.lang.Object
dev.frostlake.functions.BuiltInFunction
dev.frostlake.functions.scalar.semistructured.JsonExtractPathText

public class JsonExtractPathText extends BuiltInFunction
JSON_EXTRACT_PATH_TEXT(json, path) — parses the JSON text and returns the path's value as unquoted text.

The first argument is JSON TEXT or a VARIANT; a statically OBJECT- or ARRAY-typed value is an argument-type error, not a document — live refuses JSON_EXTRACT_PATH_TEXT(OBJECT_CONSTRUCT('a', 1), 'a') at compile time while the same call over a VARIANT, over a string, and even over a number returns a value.

  • Constructor Details

    • JsonExtractPathText

      public JsonExtractPathText()
  • Method Details

    • 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
    • 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