-
Notifications
You must be signed in to change notification settings - Fork 14
Changes to enhance existing length op #312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sarthak77
wants to merge
15
commits into
main
Choose a base branch
from
pc_13
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
58cae6f
Changes to enhance existing length op
sarthak77 317cc25
nit
sarthak77 3353873
nit
sarthak77 6abda6d
fix: use jsonb_array_length for raw jsonb fields in LENGTH operator
sarthak77 ebdb64c
fix: use jsonb field accessor without cast for jsonb_array_length
sarthak77 b7b7439
fix: use ARRAY_LENGTH for flat collections in LENGTH operator
sarthak77 be9514a
refactor: wrap test body in try-finally for deterministic cleanup
sarthak77 bc24f4c
fix: handle JSON null in jsonb LENGTH using jsonb_typeof guard
sarthak77 df178fa
test: add integration test for LENGTH on jsonb field in flat collection
sarthak77 e75d045
fix: use FieldToPgColumn to determine array type instead of DocumentType
sarthak77 5fb58fa
refactor: move array length logic into PostgresColTransformer
sarthak77 08650ab
refactor: address review feedback on array length handling
sarthak77 a77362a
test: cover typed JSONB array and top-level native array LENGTH
sarthak77 1f9510b
Merge branch 'main' into pc_13
sarthak77 2acc721
revert: drop Postgres LENGTH changes, keep Mongo-only for now
sarthak77 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -919,6 +919,58 @@ public void testAggregateWithMultipleGroupingLevels(String dataStoreName) throws | |
| testCountApi(dataStoreName, query, "query/multi_level_grouping_response.json"); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ArgumentsSource(MongoProvider.class) | ||
| public void testSortByListSizeWithMissingField(String dataStoreName) throws IOException { | ||
| Datastore datastore = datastoreMap.get(dataStoreName); | ||
| String collectionName = "list_size_sort_collection"; | ||
| datastore.deleteCollection(collectionName); | ||
| datastore.createCollection(collectionName, null); | ||
| Collection collection = datastore.getCollection(collectionName); | ||
|
Comment on lines
+924
to
+929
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. Wrapped the test body in try-finally in be9514a so |
||
|
|
||
| try { | ||
| collection.upsert( | ||
| new SingleValueKey(TENANT_ID, "three"), | ||
| new JSONDocument("{\"item\":\"three\",\"tags\":[\"a\",\"b\",\"c\"]}")); | ||
| collection.upsert( | ||
| new SingleValueKey(TENANT_ID, "one"), | ||
| new JSONDocument("{\"item\":\"one\",\"tags\":[\"x\"]}")); | ||
| // Document intentionally missing the "tags" field; LENGTH must resolve to 0 instead of | ||
| // failing | ||
| collection.upsert( | ||
| new SingleValueKey(TENANT_ID, "none"), new JSONDocument("{\"item\":\"none\"}")); | ||
|
|
||
| Query query = | ||
| Query.builder() | ||
| .addSelection(IdentifierExpression.of("item")) | ||
| .addSelection( | ||
| FunctionExpression.builder() | ||
| .operator(LENGTH) | ||
| .operand(IdentifierExpression.of("tags")) | ||
| .build(), | ||
| "tag_count") | ||
| .addSort(IdentifierExpression.of("tag_count"), ASC) | ||
| .build(); | ||
|
|
||
| Iterator<Document> resultDocs = collection.aggregate(query); | ||
| List<Map<String, Object>> results = new ArrayList<>(); | ||
| while (resultDocs.hasNext()) { | ||
| results.add(Utils.convertDocumentToMap(resultDocs.next())); | ||
| } | ||
|
|
||
| assertEquals(3, results.size()); | ||
| // Document without the "tags" field counts as 0 and sorts first in ascending order | ||
| assertEquals("none", results.get(0).get("item")); | ||
| assertEquals(0, ((Number) results.get(0).get("tag_count")).intValue()); | ||
| assertEquals("one", results.get(1).get("item")); | ||
| assertEquals(1, ((Number) results.get(1).get("tag_count")).intValue()); | ||
| assertEquals("three", results.get(2).get("item")); | ||
| assertEquals(3, ((Number) results.get(2).get("tag_count")).intValue()); | ||
| } finally { | ||
| datastore.deleteCollection(collectionName); | ||
| } | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ArgumentsSource(AllProvider.class) | ||
| public void testAggregateWithFunctionalLeftHandSideFilter(final String dataStoreName) | ||
|
|
||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,12 @@ | |
| { | ||
| "$project": { | ||
| "total": { | ||
| "$size": "$total" | ||
| "$size": { | ||
| "$ifNull": [ | ||
| "$total", | ||
| [] | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,12 @@ | |
| { | ||
| "$project": { | ||
| "total": { | ||
| "$size": "$total" | ||
| "$size": { | ||
| "$ifNull": [ | ||
| "$total", | ||
| [] | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| }, | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,12 @@ | |
| { | ||
| "$project": { | ||
| "total": { | ||
| "$size": "$total" | ||
| "$size": { | ||
| "$ifNull": [ | ||
| "$total", | ||
| [] | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The integration test runs against nested collections (the standard document store pattern) which exercises the
jsonb_array_lengthpath. The flat collection path (ARRAY_LENGTH) is covered by the existing unit tests inPostgresQueryParserTestwhich validate SQL generation for LENGTH on aggregation aliases. The flat collection LENGTH on a direct column field follows the sameARRAY_LENGTHcodepath and is validated by the existing tests that assert correct SQL output.