Class ArrayFunctionHelper

java.lang.Object
dev.frostlake.functions.scalar.ArrayFunctionHelper

public final class ArrayFunctionHelper extends Object
Shared helpers for array/object scalar functions.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final tools.jackson.databind.ObjectMapper
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static tools.jackson.databind.JsonNode
    canonicalize(tools.jackson.databind.JsonNode node)
    Canonical form of a JSON node, matching Snowflake's OBJECT/VARIANT normalization: object keys are sorted alphabetically (objects are unordered) and a whole-valued decimal loses its scale (406.0 -> 406).
    static int
    compareNodes(tools.jackson.databind.JsonNode a, tools.jackson.databind.JsonNode b)
    Ordering comparison between two JsonNodes: numeric-aware (two numeric nodes compare by value), otherwise a lexical comparison of their textual form.
    static Object
    fromNode(tools.jackson.databind.JsonNode node)
    Convert a JsonNode back to a plain Java value.
    static Object
    fromNodeKeepingJsonNull(tools.jackson.databind.JsonNode node)
    Convert a JsonNode back to a plain Java value, keeping a PRESENT JSON null as the typed VARIANT JSON null instead of collapsing it to SQL NULL.
    static boolean
    nodesEqual(tools.jackson.databind.JsonNode a, tools.jackson.databind.JsonNode b)
    JsonNode equality that also treats two numeric nodes of equal value as equal (2 == 2 whether one is an int node and the other a long/double node).
    static tools.jackson.databind.node.ArrayNode
    Parse value as ArrayNode, or return null.
    static tools.jackson.databind.JsonNode
    Parse a value to JsonNode.
    static String
    toCanonicalJson(tools.jackson.databind.JsonNode node)
    Canonical JSON text for an object/array value — see canonicalize(JsonNode).
    toCanonicalVariant(tools.jackson.databind.JsonNode node)
    Canonical semi-structured runtime value for a node — the typed counterpart of toCanonicalJson(JsonNode), carrying exactly that canonical text.
    static tools.jackson.databind.JsonNode
    toElementNode(tools.jackson.databind.ObjectMapper mapper, Object value)
    The node a value takes as an ARRAY ELEMENT: a SQL NULL becomes the VARIANT undefined sentinel — live-verified ARRAY_CONSTRUCT(1, NULL, 2) is [1,undefined,2], ARRAY_APPEND([1], NULL) is [1,undefined] and ARRAY_REPEAT(NULL, 3) is [undefined,undefined,undefined], while an OBJECT member keeps a JSON null (OBJECT_CONSTRUCT_KEEP_NULL('k', NULL) is {"k":null}).
    static tools.jackson.databind.JsonNode
    toNode(tools.jackson.databind.ObjectMapper mapper, Object value)
    Convert a Java value to a JsonNode for insertion into arrays/objects.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAPPER

      public static final tools.jackson.databind.ObjectMapper MAPPER
  • Method Details

    • parseNode

      public static tools.jackson.databind.JsonNode parseNode(Object value)
      Parse a value to JsonNode. Returns null if unparseable.
    • parseArray

      public static tools.jackson.databind.node.ArrayNode parseArray(Object value)
      Parse value as ArrayNode, or return null.
    • toElementNode

      public static tools.jackson.databind.JsonNode toElementNode(tools.jackson.databind.ObjectMapper mapper, Object value)
      The node a value takes as an ARRAY ELEMENT: a SQL NULL becomes the VARIANT undefined sentinel — live-verified ARRAY_CONSTRUCT(1, NULL, 2) is [1,undefined,2], ARRAY_APPEND([1], NULL) is [1,undefined] and ARRAY_REPEAT(NULL, 3) is [undefined,undefined,undefined], while an OBJECT member keeps a JSON null (OBJECT_CONSTRUCT_KEEP_NULL('k', NULL) is {"k":null}). Every other value converts exactly as toNode(ObjectMapper, Object) does.
    • toNode

      public static tools.jackson.databind.JsonNode toNode(tools.jackson.databind.ObjectMapper mapper, Object value)
      Convert a Java value to a JsonNode for insertion into arrays/objects.
    • nodesEqual

      public static boolean nodesEqual(tools.jackson.databind.JsonNode a, tools.jackson.databind.JsonNode b)
      JsonNode equality that also treats two numeric nodes of equal value as equal (2 == 2 whether one is an int node and the other a long/double node). A strict JsonNode.equals(java.util.Comparator<tools.jackson.databind.JsonNode>, tools.jackson.databind.JsonNode) distinguishes IntNode from LongNode, which makes ARRAY_CONTAINS / ARRAY_REMOVE miss numeric members built by ARRAY_CONSTRUCT.
    • compareNodes

      public static int compareNodes(tools.jackson.databind.JsonNode a, tools.jackson.databind.JsonNode b)
      Ordering comparison between two JsonNodes: numeric-aware (two numeric nodes compare by value), otherwise a lexical comparison of their textual form. Used by ARRAY_SORT / ARRAY_MIN / ARRAY_MAX.
    • fromNodeKeepingJsonNull

      public static Object fromNodeKeepingJsonNull(tools.jackson.databind.JsonNode node)
      Convert a JsonNode back to a plain Java value, keeping a PRESENT JSON null as the typed VARIANT JSON null instead of collapsing it to SQL NULL. Use this wherever the distinction is observable — an extraction that found the key, as opposed to one that did not.

      Live-verified: TYPEOF(GET(PARSE_JSON('{"b":null}'),'b')) is 'NULL_VALUE' and GET(...) IS NULL is FALSE, while a MISSING key — GET(PARSE_JSON('{"a":1}'),'zz') — is SQL NULL and its TYPEOF is SQL NULL.

    • fromNode

      public static Object fromNode(tools.jackson.databind.JsonNode node)
      Convert a JsonNode back to a plain Java value. Objects/arrays become typed semi-structured values.
    • canonicalize

      public static tools.jackson.databind.JsonNode canonicalize(tools.jackson.databind.JsonNode node)
      Canonical form of a JSON node, matching Snowflake's OBJECT/VARIANT normalization: object keys are sorted alphabetically (objects are unordered) and a whole-valued decimal loses its scale (406.0 -> 406). Frostlake stores OBJECT/ARRAY values as their JSON text and compares them by that text (EXCEPT, DISTINCT, GROUP BY, =), so without this two objects differing only in key order or number scale would wrongly compare unequal. Arrays keep their order (arrays are ordered) but their elements are canonicalized.
    • toCanonicalJson

      public static String toCanonicalJson(tools.jackson.databind.JsonNode node)
      Canonical JSON text for an object/array value — see canonicalize(JsonNode).
    • toCanonicalVariant

      public static VariantValue toCanonicalVariant(tools.jackson.databind.JsonNode node)
      Canonical semi-structured runtime value for a node — the typed counterpart of toCanonicalJson(JsonNode), carrying exactly that canonical text.