Skip to content

Implement XQuery 4.0 FilterExprAM (?[expr]) for arrays and maps#6211

Open
joewiz wants to merge 1 commit intoeXist-db:developfrom
joewiz:v2/xq4-filter-expr-am
Open

Implement XQuery 4.0 FilterExprAM (?[expr]) for arrays and maps#6211
joewiz wants to merge 1 commit intoeXist-db:developfrom
joewiz:v2/xq4-filter-expr-am

Conversation

@joewiz
Copy link
Copy Markdown
Member

@joewiz joewiz commented Apr 6, 2026

Summary

Adds the ?[expr] filter syntax for arrays and maps per XQuery 4.0. Includes grammar changes (XQuery.g, XQueryTree.g) and expression class.

Spec References

Tests

  • exist-core: 6,557 run, 0 failures, 0 errors
  • FilterExprAM XQSuite: 15/15 pass
  • Codacy: 0 issues

Test plan

  • exist-core unit tests pass (6,557 run, 0 failures)
  • FilterExprAM tests pass (15/15)

🤖 Generated with Claude Code

Add the array/map filter expression from the QT4 specification.
The ?[expr] operator filters array members or map entries by
evaluating a predicate with each member/value as the context item.

Examples:
  [1, 2, 3, 4, 5]?[. > 3]            -> [4, 5]
  map{"a":1, "b":2, "c":3}?[. > 1]   -> map{"b":2, "c":3}

Parser (XQuery.g):
- Add FILTER_AM token
- Add filterExprAM rule: QUESTION LPPAREN exprSingle RPPAREN
- Disambiguate from lookup: ?[ is FilterExprAM, ?name is lookup

Tree Walker (XQueryTree.g):
- Add filterExprAM rule that creates FilterExprAM expression
- Chain in postfixExpr alongside lookup and predicate

FilterExprAM.java:
- Extends AbstractExpression
- For arrays: iterates members, evaluates predicate with each as
  context item, keeps members where EBV is true
- For maps: iterates entries, evaluates predicate with each value
  as context item, keeps entries where EBV is true
- XPTY0004 for non-array/map targets

17 XQSuite tests (993/993 total XQuery3Tests pass, 0 regressions).

Spec: https://qt4cg.org/specifications/xquery-40/xpath-40-xquery-40.html#id-filter-am

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@joewiz joewiz force-pushed the v2/xq4-filter-expr-am branch from f36b12f to 9378360 Compare April 13, 2026 13:26
@joewiz joewiz marked this pull request as ready for review April 14, 2026 13:43
@joewiz joewiz requested a review from a team as a code owner April 14, 2026 13:43
@joewiz
Copy link
Copy Markdown
Member Author

joewiz commented Apr 14, 2026

[This response was co-authored with Claude Code. -Joe]

CI state: 5/9 checks pass. Of the 4 failures:

  • 3 are pre-existing integration test hangs (ubuntu, windows, macOS)
  • 1 ("Test and Publish Container Images") was caused by a transient HTTP 502 from exist-db.org's public XAR repo during that run — not a code issue

Dependencies: None. This PR is Wave 1 — it can be reviewed and merged independently.

For full context on all 7.0 PRs and the merge order, see the Reviewer Guide.

@duncdrum duncdrum added xquery issue is related to xquery implementation XQ4 xquery 4 enhancement new features, suggestions, etc. labels Apr 14, 2026
@duncdrum duncdrum added this to v7.0.0 Apr 14, 2026
@duncdrum duncdrum moved this to Backlog in v7.0.0 Apr 14, 2026
@duncdrum duncdrum added this to the eXist-7.0.0 milestone Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement new features, suggestions, etc. XQ4 xquery 4 xquery issue is related to xquery implementation

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants