Skip to content

Add find_values() convenience method with optional native acceleration - #242

Open
SereinCin wants to merge 1 commit into
h2non:masterfrom
SereinCin:feat/find-values-native-accelerator
Open

Add find_values() convenience method with optional native acceleration#242
SereinCin wants to merge 1 commit into
h2non:masterfrom
SereinCin:feat/find-values-native-accelerator

Conversation

@SereinCin

Copy link
Copy Markdown

Summary

Add a find_values() convenience method to the 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 significant speedups on filter/descendant workloads.

Motivation

The standard find() returns DatumInContext objects, 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)

Expression aero (q/s) jsonpath-ng (q/s) Speedup
$..author 261 44 5.98x
$..book[?(@.isbn)] 144 37 3.90x
$..book[0,1,2].title 191 51 3.77x
$.store.book[?(@.price < 15 & @.category == 'fiction')].title 278 110 2.54x
$.store.book[?(@.price < 10)].title 282 163 1.73x

Changes

  • jsonpath_ng/jsonpath.py: add find_values() to JSONPath base class with native fallback
  • jsonpath_ng/parser.py, jsonpath_ng/ext/parser.py: store source expression string on parsed path
  • jsonpath_ng/_native.py: native accelerator bridge that imports aero_jsonpath when available
  • tests/test_find_values.py: 6 tests covering filters, descendants, slices, string comparisons, AND conditions
  • CHANGELOG.md: document the new method

Compatibility

  • Fully backward compatible: existing find() API is unchanged
  • find_values() falls back to [m.value for m in self.find(data)] when aero-jsonpath is not installed
  • No new required dependencies

Test plan

All 357 existing tests pass + 6 new tests for find_values():

============================= 357 passed in 4.96s =============================

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
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.

1 participant