Skip to content

Implement XQuery 4.0 record type support#6210

Open
joewiz wants to merge 2 commits intoeXist-db:developfrom
joewiz:v2/xq4-record-types
Open

Implement XQuery 4.0 record type support#6210
joewiz wants to merge 2 commits intoeXist-db:developfrom
joewiz:v2/xq4-record-types

Conversation

@joewiz
Copy link
Copy Markdown
Member

@joewiz joewiz commented Apr 6, 2026

Summary

Adds record type declarations and pattern matching per the XQuery 4.0 spec.

Tests

  • exist-core: 6,559 run, 0 failures, 0 errors
  • RecordTypeTest: 17/17 pass
  • Codacy: 0 new issues (3 fixed)

Spec References

Test plan

  • exist-core unit tests pass (6,559 run, 0 failures)
  • Record type tests pass (17/17)

🤖 Generated with Claude Code

joewiz and others added 2 commits April 13, 2026 09:25
Add record type support to eXist-db's type system, laying the groundwork
for XQ4 record type annotations (record(name as xs:string, age? as xs:integer, *)).

Type system:
- Type.RECORD = 70, subtype of MAP_ITEM (aligned with parser-next branch)
- RecordType class with FieldDeclaration (name, type, optional flag)
- Extensible records (trailing "*") support
- RecordType.matches() validates map contents against field declarations

SequenceType integration:
- isRecordType(), getFieldDeclarations(), isRecordExtensible() API
- setRecordType()/getRecordType() for parser integration
- checkType() delegates to RecordType.matches() for runtime validation

DynamicTypeCheck:
- Maps pass through record type check (handled by SequenceType.checkType)

Tests: 7 unit tests covering type hierarchy, field declarations, optional
fields, extensible records, toString output, and SequenceType record API.

Parser support (field accessor .name syntax, record test parsing) requires
coordination with parser-next branch and will follow in a separate commit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…(Phase 3-4)

Phase 3 — FieldAccessor expression:
- New FieldAccessor class evaluates $expr.fieldName as map:get($expr, "fieldName")
- Returns empty sequence for missing fields, XPTY0004 for non-map base
- Parser-next branch will wire the .NCName postfix syntax to this class

Phase 4 — Record type checking in function arguments:
- RecordTypeCheck wraps function arguments declared with record types
- Validates at runtime: argument is a map, has all required fields, field
  types match, no extra keys (unless extensible)
- Wired into Function.checkArgumentType() (both typeMatches and non-match
  paths) alongside existing FunctionTypeCheck pattern
- Also wired into UserDefinedFunction.eval() for runtime parameter validation
- Descriptive error messages: "missing required field 'age'" etc.

10 new tests (4 FieldAccessor + 6 RecordTypeCheck), all 17 tests passing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@joewiz joewiz force-pushed the v2/xq4-record-types branch from fa65c7c to a6626a9 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: 8/9 checks pass. The 1 remaining failure (ubuntu integration) is a pre-existing test hang unrelated to this PR.

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 added this to the eXist-7.0.0 milestone Apr 14, 2026
@duncdrum duncdrum moved this to Backlog in v7.0.0 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