Skip to content

fix(sparql): CONSTRUCT WHERE and STRBEFORE/STRAFTER edge cases#1380

Open
bplatz wants to merge 2 commits into
mainfrom
fix/sparql-w3c-construct-strbefore
Open

fix(sparql): CONSTRUCT WHERE and STRBEFORE/STRAFTER edge cases#1380
bplatz wants to merge 2 commits into
mainfrom
fix/sparql-w3c-construct-strbefore

Conversation

@bplatz

@bplatz bplatz commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

A couple of narrow SPARQL correctness fixes surfaced by the W3C 1.1 query test suite. These are edge-case bugs in already-supported features — not gaps in functionality.

CONSTRUCT

  • Compact-IRI comparison in the test harness. Our engine already emits valid compact JSON-LD for CONSTRUCT (e.g. @id: ":s1" with @context: {"": "http://example.org/"}). The W3C harness's graph comparator was reading @id/predicate keys literally and ignoring @context, so equivalent graphs compared unequal. Added a minimal context expander (prefix terms incl. the empty prefix, @vocab, @base). Engine output unchanged.
  • CONSTRUCT WHERE shorthand was too permissive. Per the SPARQL 1.1 grammar the shorthand block is triples-only; we were routing it through the full group-graph-pattern parser and accepting FILTER/GRAPH/etc. Now rejected as a syntax error, matching the spec's negative tests.

STRBEFORE / STRAFTER

  • Datatyping edge cases (SPARQL 1.1 §17.4.3.7/8): a not-found search now returns a plain empty literal (previously it inherited arg1's language tag), a found match — including the empty search string — preserves arg1's tag, and an arg2 with an incompatible language tag now raises a type error per the argument-compatibility rules.
  • Language tags on literal constants in expression position were dropped at lowering ("x"@lang became a bare "x"). They now lower to STRLANG("x", "lang") so the tag survives — needed for the compatibility checks above, and correct for language-aware expressions generally.

Validation

  • W3C SPARQL 1.1 eval suite: +9 tests, zero regressions.
  • Full fluree-db-sparql, fluree-db-query, and fluree-db-api test suites pass; added unit tests covering the STRBEFORE/STRAFTER cases and the CONSTRUCT context expansion.
  • cargo fmt + clippy clean on the touched crates.

bplatz added 2 commits June 25, 2026 22:54
Expand compact IRIs against @context in the testsuite's CONSTRUCT graph
comparison (cw01/02/03). The engine emits valid compact JSON-LD (e.g.
@id ":s1" with @context {"":"http://example.org/"}); the harness
previously read @id and predicate keys literally, ignoring @context.
Adds a minimal context expander handling prefix terms (including the
empty prefix), @vocab, and @base.

Tighten the CONSTRUCT WHERE shorthand to a triples-only block per the
SPARQL 1.1 grammar, rejecting FILTER/GRAPH/OPTIONAL/etc. in that
position (cw05/06).
Implement SPARQL 1.1 §17.4.3.7/8 semantics: a not-found search returns a
plain empty literal (dropping arg1's language tag), a found match
(including the empty search string) preserves arg1's tag, and an arg2
whose language tag is incompatible with arg1 raises a type error. Fixes
W3C strbefore01a/02 and strafter01a/02.

Preserve language tags on literal constants in expression position by
lowering "x"@lang to STRLANG("x", "lang") instead of a bare string
constant, so argument-compatibility checks can see the tag.
@bplatz bplatz requested review from aaj3f and zonotope June 26, 2026 02:55
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