Package dev.frostlake.functions.scalar
Class ArrayFunctionHelper
java.lang.Object
dev.frostlake.functions.scalar.ArrayFunctionHelper
Shared helpers for array/object scalar functions.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic tools.jackson.databind.JsonNodecanonicalize(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 intcompareNodes(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 ObjectfromNode(tools.jackson.databind.JsonNode node) Convert a JsonNode back to a plain Java value.static ObjectfromNodeKeepingJsonNull(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 booleannodesEqual(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.ArrayNodeparseArray(Object value) Parse value as ArrayNode, or return null.static tools.jackson.databind.JsonNodeParse a value to JsonNode.static StringtoCanonicalJson(tools.jackson.databind.JsonNode node) Canonical JSON text for an object/array value — seecanonicalize(JsonNode).static VariantValuetoCanonicalVariant(tools.jackson.databind.JsonNode node) Canonical semi-structured runtime value for a node — the typed counterpart oftoCanonicalJson(JsonNode), carrying exactly that canonical text.static tools.jackson.databind.JsonNodetoElementNode(tools.jackson.databind.ObjectMapper mapper, Object value) The node a value takes as an ARRAY ELEMENT: a SQL NULL becomes the VARIANTundefinedsentinel — live-verifiedARRAY_CONSTRUCT(1, NULL, 2)is[1,undefined,2],ARRAY_APPEND([1], NULL)is[1,undefined]andARRAY_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.JsonNodeConvert a Java value to a JsonNode for insertion into arrays/objects.
-
Field Details
-
MAPPER
public static final tools.jackson.databind.ObjectMapper MAPPER
-
-
Method Details
-
parseNode
Parse a value to JsonNode. Returns null if unparseable. -
parseArray
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 VARIANTundefinedsentinel — live-verifiedARRAY_CONSTRUCT(1, NULL, 2)is[1,undefined,2],ARRAY_APPEND([1], NULL)is[1,undefined]andARRAY_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 astoNode(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 strictJsonNode.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
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'andGET(...) IS NULLis FALSE, while a MISSING key —GET(PARSE_JSON('{"a":1}'),'zz')— is SQL NULL and its TYPEOF is SQL NULL. -
fromNode
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
Canonical JSON text for an object/array value — seecanonicalize(JsonNode). -
toCanonicalVariant
Canonical semi-structured runtime value for a node — the typed counterpart oftoCanonicalJson(JsonNode), carrying exactly that canonical text.
-