Class StructFunctions


  • public class StructFunctions
    extends Object
    Built-in functions for collection and struct data types.

    These functions support accessing elements from collections (ARRAY, MAP), structured data types (ROW), and semi-structured data types (VARIANT).

    • Constructor Detail

      • StructFunctions

        public StructFunctions()
    • Method Detail

      • array

        public static List<Object> array​(Object... elements)
        Creates an ARRAY value.
      • map

        public static Map<Object,​Object> map​(Object... keyValues)
        Creates a MAP value from alternating keys and values.
      • row

        public static List<Object> row​(Object... fields)
        Creates a ROW value.
      • cardinality

        public static Integer cardinality​(List<?> array)
        Returns the number of elements in an ARRAY.
      • cardinality

        public static Integer cardinality​(Map<?,​?> map)
        Returns the number of entries in a MAP.
      • arrayContains

        public static Boolean arrayContains​(List<?> array,
                                            Object value)
        Returns whether an ARRAY contains the given value.
      • arrayPosition

        public static Integer arrayPosition​(List<?> array,
                                            Object value)
        Returns the 1-based position of a value in an ARRAY, or 0 if it is not found.
      • element

        public static <T> T element​(List<T> array)
        Returns the only element of an ARRAY.
      • itemAccess

        public static <T> T itemAccess​(List<T> array,
                                       Integer index)
        Accesses an element from an ARRAY by index (1-based, SQL standard).

        array[1] returns the first element.

        Type Parameters:
        T - the element type of the array
        Parameters:
        array - the array to access
        index - the 1-based index
        Returns:
        the element at the specified index, or null if index is out of bounds
      • itemAccess

        public static <K,​V> V itemAccess​(Map<K,​V> map,
                                               K key)
        Accesses a value from a MAP by key.

        map['key'] returns the value for 'key'.

        Type Parameters:
        K - the key type of the map
        V - the value type of the map
        Parameters:
        map - the map to access
        key - the key to look up
        Returns:
        the value for the specified key, or null if not found
      • itemAccess

        public static Variant itemAccess​(Variant variant,
                                         Integer index)
        Accesses an element from a VARIANT array by index (1-based, SQL standard).

        variant[1] returns the first element.

        Parameters:
        variant - the variant (must be an array) to access
        index - the 1-based index
        Returns:
        the element at the specified index as a Variant, or null if the variant is not an array or index is out of bounds
      • itemAccess

        public static Variant itemAccess​(Variant variant,
                                         String fieldName)
        Accesses a field from a VARIANT object by field name.

        variant['fieldName'] returns the value of the specified field.

        Parameters:
        variant - the variant (must be an object) to access
        fieldName - the name of the field to look up
        Returns:
        the field value as a Variant, or null if the variant is not an object or field is not found