Skip to content

feat: Complex pattern streaming for JSONPath expressions#1

Merged
FunkyOz merged 3 commits intomainfrom
feature/phase-5-complex-patterns
Dec 17, 2025
Merged

feat: Complex pattern streaming for JSONPath expressions#1
FunkyOz merged 3 commits intomainfrom
feature/phase-5-complex-patterns

Conversation

@FunkyOz
Copy link
Copy Markdown
Owner

@FunkyOz FunkyOz commented Dec 17, 2025

Summary

This pull request implements Task 25 - Complex Pattern Streaming, extending the JSONPath streaming capability to handle sophisticated patterns that previously required buffering the entire JSON in memory.

Key Features

  • Property Extraction After Wildcards: Patterns like $.users[*].name now stream individual property values without buffering the entire array
  • Array Index Streaming: Patterns like $.items[0].name extract nested properties from array elements with streaming
  • Filter Expression Support: Filter-based patterns like $.items[?price > 100].name leverage streaming when possible
  • Sequential Result Indexing: All streamed results maintain correct key ordering across operations

Technical Changes

Core Implementation

  • PathEvaluator.php: Added shouldExtractFromValue() and walkValue() methods for partial path matching and nested value extraction
  • PathExpression.php: Updated canUseSimpleStreaming() to recognize complex streamable patterns
  • Parser.php: Enhanced parsing to support complex pattern detection and evaluation

Compatibility

  • All 568 existing tests pass with 21,621 assertions
  • Code maintains PSR-12 compliance
  • PHPStan static analysis passes
  • No breaking changes to public API

Files Changed

  • src/Internal/JsonPath/PathEvaluator.php - Core streaming logic (191 lines added)
  • src/Internal/JsonPath/PathExpression.php - Pattern recognition (53 lines updated)
  • src/Internal/JsonPath/PropertySegment.php - Property extraction (8 lines added)
  • src/Internal/Parser.php - Pattern detection (32 lines updated)
  • tests/Unit/JsonPath/PathExpressionTest.php - Test coverage (21 lines updated)
  • tasks/00-INDEX.md - Task tracking (30 lines updated)
  • tasks/25-complex-pattern-streaming.md - Task completion
  • tasks/56-nested-wildcard-streaming.md - New task for future nested wildcard optimization
  • composer.json - Version bump
  • Cleaned up coverage-analysis-100-percent.md

Testing & Quality

Unit Tests: All PathExpression streaming logic tests pass
Integration Tests: Complex pattern streaming validated against real JSON data
Static Analysis: PHPStan level 9 compliance verified
Code Style: PSR-12 formatting enforced

Performance Impact

  • Memory: Complex patterns now use constant memory instead of buffering entire arrays
  • Speed: Streaming approach maintains performance parity with buffered approach
  • Scalability: Can now process very large JSON arrays with complex patterns

Migration Guide

No changes required for existing code. New streaming capability is automatically used for eligible patterns.

Future Work

Task 56 (Nested Wildcard Streaming) deferred as low-priority optimization for patterns with multiple [*] operators (e.g., $.users[*].posts[*].title). These currently fall back to PathFilter buffering but could be optimized in the future.


Related Issues/Tasks: Task 25 - Complex Pattern Streaming | Task 24 - Streaming JSONPath Memory Optimization
Branch: feature/phase-5-complex-patterns
Base: main

Extended streaming support to handle property extraction after wildcards,
filters, and array operations. Added shouldExtractFromValue() and walkValue()
methods to PathEvaluator for partial path matching and nested value extraction.
Updated canUseSimpleStreaming() to recognize patterns like $.users[*].name,
$.items[0].name, and filter expressions as streamable. Implemented sequential
result indexing to maintain correct key ordering across all streamed results.

All 568 tests pass with 21,621 assertions passing. Code is PSR-12 compliant
and passes PHPStan analysis.
Added Phase 12 (Advanced Streaming Features) to task index with Task 56
for nested wildcard streaming. Updated total task count to 55 and adjusted
completion metrics. Created detailed task file for nested wildcard patterns
like $.users[*].posts[*]. Cleaned up 100% coverage analysis document.
@FunkyOz FunkyOz assigned FunkyOz and unassigned FunkyOz Dec 17, 2025
@FunkyOz FunkyOz merged commit 50e0b75 into main Dec 17, 2025
97 checks passed
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