Add ALL and ONE array filter operators for MongoDB and Postgres - #323
Open
lrathod wants to merge 1 commit into
Open
Add ALL and ONE array filter operators for MongoDB and Postgres#323lrathod wants to merge 1 commit into
lrathod wants to merge 1 commit into
Conversation
Add two new ArrayOperator values for filtering on array-valued attributes: - ALL: array attribute must contain every value specified in the filter - ONE: array attribute must contain exactly one element, and that element must be one of the specified values MongoDB: ALL uses $setIsSubset with an $ifNull guard; ONE combines $size == 1 with $in on the first element via $arrayElemAt. Postgres: native array columns use @> (ALL) and array_length + && (ONE); JSONB array paths use jsonb_typeof-guarded @> containment and jsonb_array_length respectively. Both parsers require the inner filter to carry a constant value list; non-constant RHS expressions throw UnsupportedOperationException since these are set-level operators, not per-element predicates like ANY. Co-authored-by: Cursor <cursoragent@cursor.com>
lrathod
requested review from
avinashkolluru,
kotharironak,
puneet-traceable,
skjindal93,
suddendust and
suresh-prakash
as code owners
August 27, 2026 11:16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two new
ArrayOperatorvalues for filtering on array-valued attributes (ticket ASP-3008):MongoDB
ALL→{"$expr": {"$setIsSubset": [<values>, {"$ifNull": ["$<arrayPath>", []]}]}}(set containment, null-safe)ONE→$andof$size == 1and$inon$arrayElemAt [path, 0](cardinality + membership)Postgres
ALL→COALESCE(col, ARRAY[]::type[]) @> ?;ONE→array_length(...) = 1 AND col && ?ALL→(CASE WHEN jsonb_typeof(path) = 'array' THEN path ELSE '[]'::jsonb END) @> ?::jsonb;ONE→jsonb_array_length(...) = 1 AND (path @> ?::jsonb OR ...)per valuePostgresDataType.fromJavaValue()Design note
Both parsers require the inner
RelationalExpressionto carry a constant value list; a non-constant RHS throwsUnsupportedOperationException. This is intentional —ALL/ONEare set-level operators, unlikeANYwhich supports arbitrary per-element sub-filters.Test plan
MongoArrayFilterParserTest(operator structure,$ifNullguards, single-value, non-constant RHS rejection, no double$exprwrapping)PostgresQueryParserTest(ALL/ONE × JSONB/native array, nested JSONB path)ArrayFiltersQueryIntegrationTest(Mongo + Postgres) with 3 new JSON fixtures — run in CI:document-store:build(compile + unit tests + spotless) passes locallyMade with Cursor