Skip to content

EQL v3 empty JSON arrays break array accessors #978

Open

Description

@tobyhede

The EQL v3 JSON domain accepts an empty searchable vector, but ste_vec()
aggregates zero rows to SQL NULL. As a result, jsonb_array_length returns
NULL instead of zero and jsonb_array_elements raises SQLSTATE 22004 because
its FOR loop has a null upper bound.

Acceptance criteria

  • The length of an encrypted empty JSON array is zero.
  • jsonb_array_elements returns zero rows without error.
  • Populated-array behaviour is unchanged.
  • Tests exercise a real encrypted empty-array payload as well as the SQL helper
    boundary.
  • The implementation composes with the umbrella array aggregation design.

Activity

  1. coderdan commented on Oct 21, 2026

    @coderdan
    Contributor

    How the EQL v4 json_tree family (#1288, #1325, #1329) handles the empty array, for comparison, plus one gap it has of its own.

    In v4 an empty array is a node whose encrypted plaintext says kind array, child count zero. eql_v4.json_tree_child_count returns 0 and json_tree_children returns no rows, with no null loop bound anywhere; a walk that reaches the empty array through gates (json_tree_subtree_at) returns the node itself at depth 0 and the client opens it to [].

    The gap: an empty container that is a chain head (a top-level field under the sealed root). json_tree_subtree(doc, token) returns a node's descendants, not the node, so an empty $.tags yields no rows and the client reports "a node with children" instead of []; and -> on its selector returns the node, which the client refuses to open because a container holds no value of its own. The fix is small and client-side: an extracted container node with zero children should open to its empty value. Not filed separately yet; I will unless someone objects to tracking it under this issue.

    v3's ste_vec() aggregation is unchanged by the v4 work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions