Skip to content

Conversation

@suddendust
Copy link
Contributor

Fix Postgres Array EQ/NEQ Query Generation

Problem

EQ and NEQ operators on array fields in flat should behave similarly to Mongo:

  1. Arrays EQ scalar: Containment check.
  2. Arrays NEQ scalar: ! containment check.
  3. Arrays EQ arrays: Exact match on arrays.
  4. Arrays NEQ arrays: ! exact match on arrays.

Solution

1. Operator Conversion for Scalar Values

When EQ/NEQ is used on an array field with a scalar RHS, convert to CONTAINS/NOT_CONTAINS:

  • tags EQ "hygiene"tags @> ARRAY['hygiene']::text[]
  • props.colors NEQ "Blue"NOT (props->'colors' @> '["Blue"]'::jsonb)

2. Exact Equality for Array Values

When EQ/NEQ is used with an array RHS, use exact equality operators:

  • tags EQ ["hygiene", "family-pack"]tags = ARRAY['hygiene','family-pack']::text[]
  • props.colors EQ ["Blue", "Green"]props->'colors' = '["Blue","Green"]'::jsonb

Testing

[x] Added integration tests.
[] Test these changes in a live env.

Checklist:

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

@suddendust suddendust changed the title Eq on arrays Sync EQ/NEQ on Arrays in Flat Collections with Mongo Dec 5, 2025
@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

❌ Patch coverage is 81.57895% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.48%. Comparing base (df5c5f6) to head (5a32cec).

Files with missing lines Patch % Lines
...ter/PostgresRelationalFilterParserFactoryImpl.java 78.57% 2 Missing and 7 partials ⚠️
...der/PostgresSelectExpressionParserBuilderImpl.java 80.00% 1 Missing and 3 partials ⚠️
.../filter/PostgresJsonArrayEqualityFilterParser.java 73.33% 3 Missing and 1 partial ⚠️
...ter/PostgresTopLevelArrayEqualityFilterParser.java 83.33% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #257      +/-   ##
============================================
+ Coverage     80.44%   80.48%   +0.03%     
- Complexity     1256     1297      +41     
============================================
  Files           227      230       +3     
  Lines          5839     5948     +109     
  Branches        517      536      +19     
============================================
+ Hits           4697     4787      +90     
- Misses          789      797       +8     
- Partials        353      364      +11     
Flag Coverage Δ
integration 80.48% <81.57%> (+0.03%) ⬆️
unit 57.96% <71.05%> (+0.28%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

suresh-prakash
suresh-prakash previously approved these changes Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants