From c8deb22250c7fda5af04f607905e50f7724c9b4a Mon Sep 17 00:00:00 2001 From: Olaf Hartig Date: Thu, 25 Sep 2025 12:54:59 +0200 Subject: [PATCH 1/3] improves definitions of all algebra operators that involve expressions --- spec/index.html | 114 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 78 insertions(+), 36 deletions(-) diff --git a/spec/index.html b/spec/index.html index 3eabcac0..849e9721 100644 --- a/spec/index.html +++ b/spec/index.html @@ -4694,6 +4694,15 @@

Operand Data Types

Expression Evaluation

+

+ A SPARQL expression is evaluated + with respect to a solution mapping + and in the context of an RDF dataset + with an active graph. + The result of such an evaluation is either + an RDF term or + an [=error=]. +

SPARQL provides a subset of the functions and operators defined by XPath and XQuery Functions and Operators. @@ -10048,16 +10057,18 @@

SPARQL Algebra

|D| be a dataset, and |G| be the active graph. We define:

-

Filter(expr, Ω, |D|, |G|) = { μ in Ω | expr(μ) is an expression that has an - [=effective boolean value=] of true }

-
- It is not clear what expr(μ) is, and it is not apparent in the formula that the expression |expr| is meant to be evaluated not only with respect to μ but also with respect to |D| with active graph |G|.
+

Filter(expr, Ω, |D|, |G|) = + { μ in Ω | + |expr|(μ, |D|, |G|) is an RDF term |t| + such that EBV(|t|) is `"true"^^xsd:boolean` }

multiplicity( μ | Filter(expr, Ω, |D|, |G|) ) = multiplicity( μ | Ω )

-
- Note that evaluating an exists(pattern) expression uses the dataset |D| and - active graph |G|. See the evaluation of filter. -
+

+ where, for every solution mapping μ, + |expr|(μ, |D|, |G|) is the result of + evaluating expression |expr| + with respect to μ, in the context of dataset |D| with active graph |G|. +

Definition: Join

@@ -10077,29 +10088,43 @@

SPARQL Algebra

of μ is the sum of the multiplicities from all possibilities.

Definition: Diff

-

Let Ω1 and Ω2 be multisets of solution mappings and expr be an - expression. We define:

-

Diff(Ω1, Ω2, expr) = { μ | μ in Ω1 such that ∀ μ' in - Ω2, either μ and μ' are not compatible or μ and μ' are compatible and - expr(merge(μ, μ')) does not have an [=effective boolean value=] of true }

-
- It is not clear what expr(μ) is, and it is not apparent in the formula that the expression |expr| is meant to be evaluated not only with respect to μ but also with respect to |D| with active graph |G|.
-

multiplicity( μ | Diff(Ω1, Ω2, expr) ) = +

Let Ω1 and Ω2 be multisets of solution mappings, + expr be an expression, + |D| be a dataset, + and |G| be the active graph. + We define:

+

Diff(Ω1, Ω2, expr, |D|, |G|) = { μ | μ in Ω1 such that ∀ μ' in + Ω2, either i) μ and μ' are not compatible, + or + ii) μ and μ' are compatible and + |expr|(merge(μ, μ'), |D|, |G|) is an [=error=], + or + iii) μ and μ' are compatible and + |expr|(merge(μ, μ'), |D|, |G|) is an RDF term |t| for which + EBV(|t|) is not `"true"^^xsd:boolean` }

+

multiplicity( μ | Diff(Ω1, Ω2, expr, |D|, |G|) ) = multiplicity( μ | Ω1 )

+

+ where, for every solution mapping μ, + |expr|(μ, |D|, |G|) is the result of + evaluating expression |expr| + with respect to μ, in the context of dataset |D| with active graph |G|. +

-

The evaluation of expr(merge(μ, μ')) does not have an - [=effective boolean value=] of true if it evaluates to false or if it raises an error.

Diff is used internally for the definition of LeftJoin.

Definition: LeftJoin

-

Let Ω1 and Ω2 be multisets of solution mappings and expr be an - expression. We define:

-

LeftJoin(Ω1, Ω2, expr) = Filter(expr, Join(Ω1, - Ω2)) ∪ Diff(Ω1, Ω2, expr)

-

multiplicity( μ | LeftJoin(Ω1, Ω2, expr) ) = - multiplicity( μ | Filter(expr, Join(Ω1, Ω2)) ) + +

Let Ω1 and Ω2 be multisets of solution mappings, + expr be an expression, + |D| be a dataset, + and |G| be the active graph. + We define:

+

LeftJoin(Ω1, Ω2, expr, |D|, |G|) = Filter(expr, Join(Ω1, + Ω2), |D|, |G|) ∪ Diff(Ω1, Ω2, expr, |D|, |G|)

+

multiplicity( μ | LeftJoin(Ω1, Ω2, expr, |D|, |G|) ) = + multiplicity( μ | Filter(expr, Join(Ω1, Ω2), |D|, |G|) ) + multiplicity( μ | Diff(Ω1, Ω2, - expr) )

+ expr, |D|, |G|) )

@@ -10128,14 +10153,28 @@

SPARQL Algebra

pattern P.

Definition: Extend

-

Let μ be a solution mapping, Ω a multiset of solution mappings, var a variable - and expr be an expression, then we define:

-

Extend(μ, var, expr) = μ ∪ { (var, value) | var not in dom(μ) and value = expr(μ) }

-
- It is not clear what expr(μ) is, and it is not apparent in the formula that the expression |expr| is meant to be evaluated not only with respect to μ but also with respect to |D| with active graph |G|.
-

Extend(μ, var, expr) = μ if var not in dom(μ) and expr(μ) is an error

-

Extend is undefined if var in dom(μ).

-

Extend(Ω, var, expr) = { Extend(μ, var, expr) | μ in Ω }

+

Let μ be a solution mapping, Ω a multiset of solution mappings, + var be a variable, + expr be an expression, + |D| be a dataset, + and |G| be the active graph. + We define:

+

Extend(Ω, var, expr, |D|, |G|) = { |Extend|(μ, var, expr, |D|, |G|) | μ in Ω },

+

where, for every solution mapping μ,

+

|Extend|(μ, var, expr, |D|, |G|) = μ ∪ { (var, |expr|(μ, |D|, |G|)) } + if var not in dom(μ) and + |expr|(μ, |D|, |G|) is an RDF term,

+

|Extend|(μ, var, expr, |D|, |G|) = μ + if var not in dom(μ) and + |expr|(μ, |D|, |G|) is an [=error=],

+

|Extend|(μ, var, expr, |D|, |G|) is undefined + if var in dom(μ), and

+

|expr|(μ, |D|, |G|) is the result of + evaluating expression |expr| + with respect to μ, in the context of dataset |D| with active graph |G|. +

+
+ We need to define multiplicity( μ | Extend(Ω, var, expr, |D|, |G|) )

Write [ x | C ] for a sequence of elements where C is a condition on x.

@@ -10631,7 +10670,7 @@

Evaluation Semantics

Definition: Evaluation of LeftJoin

-eval( |D|(|G|), LeftJoin(P1, P2, |F|) ) = LeftJoin( eval(|D|(|G|), P1), eval(|D|(|G|), P2), |F| ) +eval( |D|(|G|), LeftJoin(P1, P2, |F|) ) = LeftJoin( eval(|D|(|G|), P1), eval(|D|(|G|), P2), |F|, |D|, |G| )

@@ -10702,9 +10741,9 @@

Evaluation Semantics

Note that if eval(|D|(|G|), Ai) is an error, it is ignored.

-

Definition: Evaluation of Extend

+

Definition: Evaluation of Extend

-eval( |D|(|G|), Extend(|P|, |var|, |expr|) ) = Extend( eval(|D|(|G|), |P|), |var|, |expr| ) +eval( |D|(|G|), Extend(|P|, |var|, |expr|) ) = Extend( eval(|D|(|G|), |P|), |var|, |expr|, |D|, |G| )

@@ -12652,6 +12691,9 @@

Changes between SPARQL 1.1 Query Language and SPARQL 1.2 Query Language

from eval to reachableTerms.
  • Add section about SPARQL expression evaluation errors.
  • Rename section "Filter evaluation" as .
  • +
  • Improve definitions of all algebra operators that involve expressions + (Filter, Diff, + LeftJoin, and Extend).
  • From 0c316c42cd1590e378f4f0de13f62463e1413597 Mon Sep 17 00:00:00 2001 From: Olaf Hartig Date: Sat, 27 Sep 2025 11:32:00 +0200 Subject: [PATCH 2/3] better formatting of the conditions in the definition of Diff, as proposed by @TallTed in https://github.com/w3c/sparql-query/pull/291#discussion_r2383336557 --- spec/index.html | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/spec/index.html b/spec/index.html index 849e9721..2fc1f4c6 100644 --- a/spec/index.html +++ b/spec/index.html @@ -10093,15 +10093,18 @@

    SPARQL Algebra

    |D| be a dataset, and |G| be the active graph. We define:

    -

    Diff(Ω1, Ω2, expr, |D|, |G|) = { μ | μ in Ω1 such that ∀ μ' in - Ω2, either i) μ and μ' are not compatible, - or - ii) μ and μ' are compatible and - |expr|(merge(μ, μ'), |D|, |G|) is an [=error=], - or - iii) μ and μ' are compatible and - |expr|(merge(μ, μ'), |D|, |G|) is an RDF term |t| for which - EBV(|t|) is not `"true"^^xsd:boolean` }

    +

    Diff(Ω1, Ω2, expr, |D|, |G|) + = { μ in Ω1 | for every μ' in Ω2, + either of the following conditions holds:

    +
      +
    • μ and μ' are not compatible,
    • +
    • μ and μ' are compatible + and |expr|(merge(μ, μ'), |D|, |G|) is an [=error=], or
    • +
    • μ and μ' are compatible + and |expr|(merge(μ, μ'), |D|, |G|) is an RDF term |t| + for which EBV(|t|) is not `"true"^^xsd:boolean`.
    • +
    +

    }

    multiplicity( μ | Diff(Ω1, Ω2, expr, |D|, |G|) ) = multiplicity( μ | Ω1 )

    From a21e4938d4d146b1a70d65d5e3428aea7393d75e Mon Sep 17 00:00:00 2001 From: Olaf Hartig Date: Tue, 30 Sep 2025 01:08:56 +0200 Subject: [PATCH 3/3] Update spec/index.html Co-authored-by: Ted Thibodeau Jr --- spec/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/index.html b/spec/index.html index 2fc1f4c6..bfb76631 100644 --- a/spec/index.html +++ b/spec/index.html @@ -10095,7 +10095,7 @@

    SPARQL Algebra

    We define:

    Diff(Ω1, Ω2, expr, |D|, |G|) = { μ in Ω1 | for every μ' in Ω2, - either of the following conditions holds:

    + any of the following conditions holds: