Skip to content

[Query] Fix SPARQL blank node BGP scope validation and xsd:double MIN/MAX normalization #607

Description

@abdessamad-abdoun

Summary

Fix two W3C SPARQL conformance test failures:

  1. Blank node BGP scope validation — the parser incorrectly rejected valid queries where a blank node label appeared in multiple TriplesBlock nodes within the same GroupGraphPattern (e.g. separated by FILTER), and incorrectly accepted invalid queries where a blank node label crossed UNION/OPTIONAL/GRAPH boundaries within the same outer group.

  2. xsd:double lexical form normalization for MIN/MAX results — the W3C min_with_group_by test expected "2.0E-1" but the engine returned "2E-1" (both represent the same value). The comparison now uses numeric equality for MIN/MAX aggregate results.

Specification & Semantics

Per SPARQL 1.0 §4.1.4: a blank node label is scoped to a basic graph pattern. A BGP extends across multiple TriplesBlock elements in a GroupGraphPattern unless separated by a BGP-breaking pattern: OPTIONAL, UNION, GRAPH, SERVICE, MINUS, EXISTS, or a plain nested { } group. FILTER does NOT break a BGP.

Root Cause

Blank node scoping

The previous implementation tracked blank node labels against the identity of bgpStack.peek() (per-TriplesBlock). Because the ANTLR grammar defines TriplesBlock recursively, two consecutive triples in the same semantic BGP had different list identities → false validation errors on valid queries.

The fix introduces a bgpScopeIdStack (parallel to groupStack) that:

  • Pushes a new scope ID at every enterGroup()
  • Pops at exitGroup()
  • Renews the outer scope after any BGP-breaking inner pattern closes
  • Does NOT renew for FILTER

MIN/MAX numeric normalization

Extended ComputedNumericResults.computed() to include MIN and MAX aggregates so comparison uses numeric equality (via BigDecimal) instead of lexical equality.

Target Branch

feature/corese-next

Targeted W3C Tests — Previously Failing → Now Passing

  • syn-09, syn-10, syn-11, syntax-bnodes-05, syn-blabel-cross-filter (positive syntax)
  • synbad-union-breaks-bgp, synbad-opt-breaks-bgp, synbad-graph-breaks-bgp (negative syntax)
  • syn-blabel-cross-union-bad, syn-blabel-cross-optional-bad, syn-blabel-cross-graph-bad
  • synbad34rq–synbad38rq (SPARQL 1.1 negative syntax)
  • synbad03rq (SPARQL 1.1 — duplicate SELECT variable)
  • min_with_group_by (SPARQL 1.1 aggregate MIN)

Acceptance Criteria

  • All previously failing blank node scope tests pass (positive and negative)
  • No regressions on previously passing tests
  • min_with_group_by W3C test passes
  • ScalarFunctionsTest.decimalCastDoesNotRewriteItsSourceTerm still passes
  • 0 SonarLint issues

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

featureNew feature or capabilityw3c-conformanceW3C standards compliance (SPARQL 1.1, Turtle, RDF 1.1)

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions