Add find_values() convenience method with optional native acceleration - #242
Open
SereinCin wants to merge 1 commit into
Open
Add find_values() convenience method with optional native acceleration#242SereinCin wants to merge 1 commit into
SereinCin wants to merge 1 commit into
Conversation
Add find_values() to JSONPath base class that returns plain values (equivalent to [m.value for m in path.find(data)]). When the optional aero-jsonpath package is installed, find_values() delegates to a native Aero-compiled kernel for 2-6x speedup on filter/descendant workloads. Changes: - jsonpath.py: add find_values() with native fallback - parser.py, ext/parser.py: store source expression string on parsed path - _native.py: native accelerator bridge (imports aero_jsonpath if available) - tests/test_find_values.py: 6 tests covering filters, descendants, slices - CHANGELOG.md: document the new method
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
Add a
find_values()convenience method to theJSONPathbase class that returns plain values (equivalent to[m.value for m in path.find(data)]). When the optionalaero-jsonpathpackage is installed,find_values()delegates to a native Aero-compiled kernel for significant speedups on filter/descendant workloads.Motivation
The standard
find()returnsDatumInContextobjects, so extracting plain values requires a list comprehension every time.find_values()provides this as a one-liner and opens the door to optional native acceleration without changing the existing API.Performance (benchmark: 2000-book document, full pipeline)
$..author$..book[?(@.isbn)]$..book[0,1,2].title$.store.book[?(@.price < 15 & @.category == 'fiction')].title$.store.book[?(@.price < 10)].titleChanges
jsonpath_ng/jsonpath.py: addfind_values()toJSONPathbase class with native fallbackjsonpath_ng/parser.py,jsonpath_ng/ext/parser.py: store source expression string on parsed pathjsonpath_ng/_native.py: native accelerator bridge that importsaero_jsonpathwhen availabletests/test_find_values.py: 6 tests covering filters, descendants, slices, string comparisons, AND conditionsCHANGELOG.md: document the new methodCompatibility
find()API is unchangedfind_values()falls back to[m.value for m in self.find(data)]whenaero-jsonpathis not installedTest plan
All 357 existing tests pass + 6 new tests for
find_values():