Flatcollection search queryconverter bugfix#308
Open
suddendust wants to merge 7 commits into
Open
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #308 +/- ##
============================================
- Coverage 81.68% 81.63% -0.05%
- Complexity 1532 1549 +17
============================================
Files 241 242 +1
Lines 7420 7450 +30
Branches 718 720 +2
============================================
+ Hits 6061 6082 +21
- Misses 912 916 +4
- Partials 447 452 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Test Results 124 files +2 124 suites +2 40s ⏱️ -13s Results for commit 38ed2e8. ± Comparison against base commit 059875b. This pull request removes 16 and adds 25 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
puneet-traceable
approved these changes
May 20, 2026
suddendust
commented
May 20, 2026
| @@ -5975,326 +5975,409 @@ private static Collection getFlatCollection(String dataStoreName) { | |||
| @Nested | |||
| class FlatCollectionLegacySearchMethod { | |||
Contributor
Author
There was a problem hiding this comment.
The strategy here is to run the same v1 and v2 query again the collection and both should return the same results.
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.
Fix legacy
search()transformer for array and JSONB columnsProblem
The legacy
Collection.search()path goes throughLegacyFilterToQueryFilterTransformer(for filters) andLegacyQueryToV2QueryTransformer(for selections / orderBy) to convert the v1Filter/QueryAPI into the v2QueryAPI before handing off to the Postgres parsers. Both transformers were dropping the column's type information when they constructed the v2IdentifierExpression, with two visible consequences:Array columns produced invalid SQL. A filter like
Filter(EQ, "tags", "hygiene")against aTEXT[]column was rendered as"tags" = ?with a text RHS — Postgres rejects this at execution time becausetext = text[]has no operator. The same problem occurred forINTEGER[],DOUBLE PRECISION[],BOOLEAN[], and anyIN/NOT_INvariants on array columns.JSONB column resolution was ad-hoc. Both transformers separately walked the schema looking for a JSONB prefix and built
JsonIdentifierExpressiondirectly, with no shared codepath for the "field resolves to the JSONB column itself" case (which is forbidden —JsonIdentifierExpressionrequires a non-emptyjsonPath).Net effect: filters on array columns failed at runtime, and the same logical query that worked through the v2
find()API blew up through the legacysearch()API.Solution
Introduced
IdentifierExpressionFactoryas a single resolution point that maps a(fieldName, ColumnMetadata)pair to the correctIdentifierExpressionsubtype using the column'scanonicalTypeandisArray()signals from the schema registry.Three cases the factory has to handle correctly:
STRING,INTEGER, …)IdentifierExpression.ofX(name)isArray() == true)ArrayIdentifierExpression.ofXs(name)= ANY(...),&&,@>).IdentifierExpression.of(name)JsonIdentifierExpressionrequires a non-emptyjsonPath— it represents a path inside a JSONB column, not the column itself.IdentifierExpression.of(name)Both
LegacyFilterToQueryFilterTransformerandLegacyQueryToV2QueryTransformernow route their direct-column lookups through this factory. The JSONB-prefix walk (for nested paths likeprops.brand) remains in each transformer because the value-type inference (which becomesJsonFieldType) is op-specific:LegacyFilterToQueryFilterTransformer.inferJsonFieldType(value)looks at the filter value's runtime type —String → STRING,Number → NUMBER,Boolean → BOOLEAN. Note: there is noSTRING_ARRAYinference path today; array-membership semantics on nested JSONB arrays are not reachable from the legacy filter API. Documented in tests.LegacyQueryToV2QueryTransformer(selections / orderBy) defaults toJsonFieldType.STRINGsince there's no value to infer from.