From 2c1e0a7c01fa0d66901c5080e9b4eaf5b351f50b Mon Sep 17 00:00:00 2001
From: Andy Seaborne Evaluation Semantics
eval( |D|(|G|), Slice(|L|, |start|, |length|) ) = Slice( eval(|D|(|G|), |L|), |start|, |length| )
The following subsections contain draft of material for a revised + "`exists`" operation. +
++ Background: SPARQL CG SEP-0007 +
+Additional [[[#sparqlGrammar]]] note:
++ Any variable that is assigned to in the graph pattern of `EXISTS`/`NOT EXISTS` must not be in-scope. + This applies to `BIND`, variables introduced by `AS` in a `SELECT` clause, variables in a `VALUES` + clause, and variables introduced by `AS` in `GROUP BY`. ++
Extend the "in-scope" rules to include the variables in-scope from the current row:
+Syntax Form | +In-scope variables | +
---|---|
`EXISTS` and `NOT EXISTS` filters | +v is in-scope if it is in-scope for the pattern to which the `FILTER` is applied.
+ |
+
+ This restriction means that values inserted + do not conflict with values assigned to variables within the pattern. +
++ Remapping ensures that a variable name used inside a project expression, + but which is not part of the results of the evaluation of the project expression, + does not coincide with a variable mentioned anywhere else in the + algebra expression of a query. +
++ Renaming these variables does not change the results of evaluating + the project expresssion. +
++ For a projection algebra operation #sparqlProjection `Project(A, PV)` acting on algreg express `A` and with set of variables `PV`, define + a partial mapping `F` from + `V`, + the set of all variables, to `V` where: +
+F(v) = v1 if v is in PV, where v1 is a fresh variable +F(v) = v if v is not in PV+
+ Define the Projection Expression Variable Remapping `ProjectMap(P,PV)` +
+ProjectMap(Project(A, PV)) = Project(A1, PV) + where A1 is the result of applying F + to every variable mentioned in A. ++
+ The Projection Expression Variable Remapping yields an algrebra expression that + evaluates to the same results as the Project argument. No variable of `ProjectMap(Project(A, PV))` + that is not in `PV` is mentioned anywhere else in the algebra expression for the query. +
+This process is applied throughout the graph pattern of EXISTS
:
+ For any algebra expression `X`, define the Variable Remapping `PrjMap(X)` + of algebra expression `X`: +
+PrjMap(X) = replace all project operations Project(P, PV) + with ProjectMap(P, PV) for each projection in X.+
+ The outcome of `PrjMap` is independent of the order of replacement + (e.g. bottom-up or top-down). + Replacements may happen several times, depending on recursive order + but each time a replacement is made, the variable not used anywhere else. +
+ ++ A variable inside a project expression that is not in the variables projected + is not affected by the values insertion operation because it is renamed apart. +
++ Define the Values Insertion function `ValuesInsert(X, μ)` +
+Let Table(μ) = { μ } and multiplicity( μ | Table(μ) = { μ } ) = 1 + +Replace each occurence of `Y` in X where `Y` is one of + Basic Graph Pattern, + Property Path Expression, + `Graph(Var, pattern)`, + Inline Data +with `join(Y, Table(μ))`.+ +
@@ rename as ???correllate
++ Examples +
++ Let `μ` be the current solution mapping for a filter, and `X` a graph pattern, + define the Evaluation of Exists `exists(X)` +
+exists(X) = true + if eval( D(G), ValuesInsert(PrjMap(X), μ) ) + is a non-empty solution sequence. +exists(X) = false otherwise+
The overall SPARQL design can be used for queries which assume a more elaborate form of
From 4730d145eeae72afcfa172e4ebfc12a956e064fc Mon Sep 17 00:00:00 2001
From: Andy Seaborne The following subsections contain draft of material for a revised
+ The following subsections contain draft material for a revised
"`exists`" operation.
@@ -10612,7 +10612,10 @@ Extend the "in-scope" rules to include the variables in-scope from the current row:
+ Extend the "in-scope" rules to include the possible
+ variables that are in-scope for the current row:
+
- This restriction means that values inserted
- do not conflict with values assigned to variables within the pattern.
-
+ This restriction means that values inserted
+ do not conflict with values assigned to variables within the pattern.
+
+ This operation is performed as part of query parsing.
+
For a projection algebra operation #sparqlProjection `Project(A, PV)` acting on algreg express `A` and with set of variables `PV`, define
a partial mapping `F` from
@@ -10654,7 +10662,7 @@
- Define the Projection Expression Variable Remapping `ProjectMap(P,PV)`
+ Define the Projection Expression Variable Remapping `ProjectMap(P, PV)`
This process is applied throughout the graph pattern of
For any algebra expression `X`, define the Variable Remapping `PrjMap(X)`
of algebra expression `X`:
@@ -10682,31 +10690,57 @@
- A variable inside a project expression that is not in the variables projected
- is not affected by the values insertion operation because it is renamed apart.
-
+ A variable inside a project expression that is not in the variables projected
+ is not affected by the values insertion operation because it is renamed apart.
+
+ This operation is as part of the translation to the SPARQL
+ algebra.
+
+ Alternative 1: rewrite the algebra during
+ translation to the SPARQL algebra
+ to include a function that evaluates to the current row.
+
- Define the Values Insertion function `ValuesInsert(X, μ)`
+ Define the function `BindingInScope()`.
+ Evaluation of `BindingInScope()` results in a table of one row,
+ being the current binding of the enclosing filter.
+ During translation to the SPARQL algebra
+ @@ rename as ???correllate
+ Alternative 2: rewrite the algebra during execution. This corresponds to the
+ original SEP-0007 proposal.
+
+ Define the Values Insertion function `ValuesInsert(X, μ)`
+
Let `μ` be the current solution mapping for a filter, and `X` a graph pattern,
define the Evaluation of Exists `exists(X)`
- This restriction means that values inserted
+ This restriction means that inserted values
do not conflict with values assigned to variables within the pattern.
@@ -10654,13 +10654,14 @@
- For a projection algebra operation #sparqlProjection `Project(A, PV)` acting on algreg express `A` and with set of variables `PV`, define
- a partial mapping `F` from
- `V`,
- the set of all variables, to `V` where:
+ For a projection algebra operation
+ `Project(A, PV)` acting on algebra expression `A` and with set of variables `PV`,
+ define a mapping `F` from `V`,
+ the set of all variables,
+ to `V` where:
Define the Projection Expression Variable Remapping `ProjectMap(P, PV)`
- For any algebra expression `X`, define the Variable Remapping `PrjMap(X)`
+ For any algebra expression `X`, define the Variable Remapping `PrjMap(X)`
of algebra expression `X`:
The outcome of `PrjMap` is independent of the order of replacement
- (e.g. bottom-up or top-down).
+ (whether "bottom-up" or "top-down") order.
Replacements may happen several times, depending on recursive order
but each time a replacement is made, the variable not used anywhere else.
Need to define `BindingInScope`
During translation to the SPARQL algebra
Define putting in the `BindingInScope` operator
- Define the Values Insertion function `ValuesInsert(X, μ)`
+ Define the function `InsertValues(X, μ)`
+ @@ Set up the current row for `BindingdInScope`.
+ The variable The variable In In If the form is Notes: Expand abbreviations for IRIs and triple patterns given in
Section . The set of filter expressions prepare(EXISTS{P}) @@ Scoping rule already done (grammar note).
+ During translation to the SPARQL algebra
+
+ One way to provide `BindingInScope` is to change `eval` to also have the current row
+ as an argument or a "null" token. . Normally this the "null" token. This would be set in
+ eval-filter.
+
+ Another way is to have a global (to the execution) variable. In eval-exists, the
+ old value is recorded, the global set to the new value, and reset on exit - this forms a
+ stack for nested EXISTS.
+
+ Modifing `eval` is better prepartion for other correlted operations.
+ For a projection algebra operation #sparqlProjection `Project(A, PV)` acting on algreg express `A` and with set of variables `PV`, define
+ a partial mapping `F` from
+ `V`,
+ the set of all variables, to `V` where:
+
+ Define the Projection Expression Variable Remapping `ProjectMap(P, PV)`
+
+ The Projection Expression Variable Remapping yields an algrebra expression that
+ evaluates to the same results as the Project argument. No variable of `ProjectMap(Project(A, PV))`
+ that is not in `PV` is mentioned anywhere else in the algebra expression for the query.
+ This process is applied throughout the graph pattern of
+ For any algebra expression `X`, define the Variable Remapping `PrjMap(X)`
+ of algebra expression `X`:
+
+ The outcome of `PrjMap` is independent of the order of replacement
+ (e.g. bottom-up or top-down).
+ Replacements may happen several times, depending on recursive order
+ but each time a replacement is made, the variable not used anywhere else.
+
+ A variable inside a project expression that is not in the variables projected
+ is not affected by the values insertion operation because it is renamed apart.
+
+ This operation is as part of the translation to the SPARQL
+ algebra.
+ The following table gives the translation
@@ -9149,14 +9257,17 @@ Some groups of one graph pattern become Join(|Z|, |A|), where |Z| is the empty basic graph
+
+ @@ Move out of the general `translate()` process and
+ perform once after top level translation only
+ Some groups of one graph pattern become
+ Join(|Z|, |A|), where |Z| is the empty basic graph
pattern (which is the empty set). These are replaced by |A|. The empty
graph pattern |Z| is the identity for join: Definition: Evaluation of Filter @@ Make current μ available. Or use current language in Exist.
+ Long term: change eval() to be arity three - 3rd argument is "current row".
+ editors note.
+ eval( |D|(|G|), Filter(|F|, |P|) ) = Filter( |F|, eval(|D|(|G|), |P|), |D|(|G|) ) 'substitute' is a filter function in support of the evaluation of
@@ -10479,6 +10596,9 @@ Definition: Evaluation of Exists @@ Update Let μ be the current solution mapping for a filter and |P| a graph pattern: The following subsections contain draft material for a revised
- "`exists`" operation.
-
- Background: SPARQL CG SEP-0007
- Additional [[[#sparqlGrammar]]] note:
- Extend the "in-scope" rules to include the possible
- variables that are in-scope for the current row:
-
- This restriction means that inserted values
- do not conflict with values assigned to variables within the pattern.
-
- This operation is performed as part of query parsing.
-
- Remapping ensures that a variable name used inside a project expression,
- but which is not part of the results of the evaluation of the project expression,
- does not coincide with a variable mentioned anywhere else in the
- algebra expression of a query.
-
- Renaming these variables does not change the results of evaluating
- the project expresssion.
-
- For a projection algebra operation
- `Project(A, PV)` acting on algebra expression `A` and with set of variables `PV`,
- define a mapping `F` from `V`,
- the set of all variables,
- to `V` where:
-
- Define the Projection Expression Variable Remapping `ProjectMap(P, PV)`
-
- The Projection Expression Variable Remapping yields an algrebra expression that
- evaluates to the same results as the Project argument. No variable of `ProjectMap(Project(A, PV))`
- that is not in `PV` is mentioned anywhere else in the algebra expression for the query.
- This process is applied throughout the graph pattern of
- For any algebra expression `X`, define the Variable Remapping `PrjMap(X)`
- of algebra expression `X`:
-
- The outcome of `PrjMap` is independent of the order of replacement
- (whether "bottom-up" or "top-down") order.
- Replacements may happen several times, depending on recursive order
- but each time a replacement is made, the variable not used anywhere else.
-
- A variable inside a project expression that is not in the variables projected
- is not affected by the values insertion operation because it is renamed apart.
-
- This operation is as part of the translation to the SPARQL
- algebra.
-
- Alternative 1: rewrite the algebra during
- translation to the SPARQL algebra
- to include a function that evaluates to the current row.
-
- Define the function `BindingInScope()`.
- Evaluation of `BindingInScope()` results in a table of one row,
- being the current binding of the enclosing filter.
- Need to define `BindingInScope`
- During translation to the SPARQL algebra
- Define putting in the `BindingInScope` operator
- Examples
-
- Alternative 2: rewrite the algebra during execution. This corresponds to the
- original SEP-0007 proposal.
-
- Define the function `InsertValues(X, μ)`
-
- Let `μ` be the current solution mapping for a filter, and `X` a graph pattern,
- define the Evaluation of Exists `exists(X)`
-
- @@ Set up the current row for `BindingdInScope`.
- Evaluation Semantics
Values Insertion and `EXISTS`
Syntax Restriction
This applies to `BIND`, variables introduced by `AS` in a `SELECT` clause, variables in a `VALUES`
clause, and variables introduced by `AS` in `GROUP BY`.
-
-
@@ -10626,10 +10629,15 @@
Syntax Restriction
Remapping
@@ -10644,7 +10652,7 @@ Remapping
the project expresssion.
Remapping
F(v) = v1 if v is in PV, where v1 is a fresh variable
F(v) = v if v is not in PV
ProjectMap(Project(A, PV)) = Project(A1, PV)
where A1 is the result of applying F
@@ -10668,7 +10676,7 @@
Remapping
EXISTS
:Remapping
Replacements may happen several times, depending on recursive order
but each time a replacement is made, the variable not used anywhere else.
-
- Values Insertion
+ Let Table(μ) = { μ } and multiplicity( μ | Table(μ) = { μ } ) = 1
+
Replace each occurence of `Y` in X where `Y` is one of
Basic Graph Pattern,
Property Path Expression,
`Graph(Var, pattern)`,
Inline Data
-with `join(Y, Table(μ))`.
-
+ with `join(Y, BindingInScope())`.
+ Values Insertion
Examples
Let Table(μ) = { μ } and multiplicity( μ | Table(μ) = { μ } ) = 1
+
+Replace each occurence of `Y` in X where `Y` is one of
+ Basic Graph Pattern,
+ Property Path Expression,
+ `Graph(Var, pattern)`,
+ Inline Data
+with `join(Y, Table(μ))`.
+
+ Evaluation of EXISTS
exists(X) = true
- if eval( D(G), ValuesInsert(PrjMap(X), μ) )
+ if eval( D(G), ValuesInScope(PrjMap(X)), μ)
is a non-empty solution sequence.
exists(X) = false otherwise
Syntax Restriction
Remapping
F(v) = v1 if v is in PV, where v1 is a fresh variable
-F(v) = v if v is not in PV
+ F(v) = v1 if v is not in PV, where v1 is a fresh variable
+F(v) = v if v is in PV
Remapping
PrjMap(X) = replace all project operations Project(P, PV)
- with ProjectMap(P, PV) for each projection in X.
+ with ProjectMap(Project(A, PV), PV) for each projection in X.
Values Insertion
being the current binding of the enclosing filter.
Values Insertion
-Replace each occurence of `Y` in X where `Y` is one of
+Replace each occurence of Y where Y is one of
Basic Graph Pattern,
- Property Path Expression,
- `Graph(Var, pattern)`,
+ Property Path Patterns,
+ Graph(Var, pattern),
Inline Data
- with `join(Y, BindingInScope())`.
+ with join(Y, BindingInScope()).
Values Insertion
Let Table(μ) = { μ } and multiplicity( μ | Table(μ) = { μ } ) = 1
-Replace each occurence of `Y` in X where `Y` is one of
+Replace each occurence of Y in X where Y is one of
Basic Graph Pattern,
- Property Path Expression,
- `Graph(Var, pattern)`,
+ Property Path Patterns,
+ Graph(Var, pattern),
Inline Data
-with `join(Y, Table(μ))`.
+ with join(Y, Table(μ)).
Evaluation of EXISTS
Let `μ` be the current solution mapping for a filter, and `X` a graph pattern,
define the Evaluation of Exists `exists(X)`
+ exists(X) = true
- if eval( D(G), ValuesInScope(PrjMap(X)), μ)
+ if eval( D(G), μ)
is a non-empty solution sequence.
exists(X) = false otherwise
Variable Scope
VALUES varlist { values }
+ v
is in-scope if v
is in varlist
+
- `EXISTS` and `NOT EXISTS` filters
+
+
+ v
is in-scope if it is in-scope for the
+ solution mapping
+ where the `FILTER` containing `EXISTS` or `NOT EXISTS` is applied.
+ v
must not be in-scope at the point of the (expr AS
- v)
form. The scoping for (expr AS v)
applies immediately in
- SELECT
expressions.v
must not be in-scope at the point of the
+ (expr AS v)
form. The scoping for (expr AS v)
+ applies immediately in SELECT
expressions.
+ BIND (expr AS v)
requires that the variable v
is not
- in-scope from the preceeding elements in the group graph pattern in which it is used.SELECT
, the variable v
must not be in-scope in the graph
pattern of the SELECT
clause, nor used in another select expression earlier in
- the clause.Converting Graph Patterns
@@ -9078,7 +9089,6 @@ Translate Graph Patterns
GroupGraphPattern
:
-Let FS := the empty set
Let G := the empty pattern, a basic graph pattern which is the empty set.
For each element E in the sequence of elements in the GroupGraphPattern
@@ -11150,52 +11160,95 @@
Grammar
section 6 Notation.
-
a
' which, in line with Turtle and N3, is used
in place of the IRI rdf:type
- (in full, http://www.w3.org/1999/02/22-rdf-syntax-ns#type
).QueryUnit
for the SPARQL query language
- and UpdateUnit
for the SPARQL update language.http://www.w3.org/1999/02/22-rdf-syntax-ns#type
).
+ QueryUnit
for the SPARQL query language
+ and UpdateUnit
for the SPARQL update language.
+ AdditiveExpression
grammar rule allows for this by
covering the two cases of an expression followed by a signed number. These
- produce an addition or subtraction of the unsigned number as appropriate.INSERT DATA
,
+ produce an addition or subtraction of the unsigned number as appropriate.
+ INSERT DATA
,
DELETE DATA
and
DELETE WHERE
allow any amount of white space between the words.
- The single space version is used in the grammar for clarity.QuadData
and
+ The single space version is used in the grammar for clarity.
+ QuadData
and
QuadPattern
rules both use rule Quads
. The rule
QuadData
, used in
INSERTDATA
and
DELETE DATA
,
- must not allow variables in the quad patterns.DELETE WHERE
,
+ must not allow variables in the quad patterns.
+ DELETE WHERE
,
the DeleteClause
for
DELETE
,
- nor in DELETE DATA
.VALUES
block
- must be the same as the number of each list of associated values in the DataBlock
.AS
in a SELECT
clause
- must not already be in-scope.BIND
clause must not be already
+ nor in DELETE DATA
.
+ VALUES
block
+ must be the same as the number of each list of associated values in
+ the DataBlock
.
+ AS
in a SELECT
clause
+ must not already be in-scope.
+ BIND
clause must not be already
in-use within the immediately preceding TriplesBlock
within a
- GroupGraphPattern
.GroupGraphPattern
.
+ DISTINCT
keyword
- in a function call.DISTINCT
keyword
+ in a function call.
+ a
, or a variable),
From 1a0a79f708d4a1cdbdca73ea8242ec81271d80fc Mon Sep 17 00:00:00 2001
From: Andy Seaborne Expand Syntax Forms
Collect
FILTER
ElementsFILTER
expressions apply to the whole group graph pattern in which they
@@ -8886,13 +8887,120 @@ Collect
Let FS := empty set
For each form FILTER(expr) in the group graph pattern
In expr, replace NOT EXISTS{P} with fn:not(exists(translate(P)))
- In expr, replace EXISTS{P} with exists(translate(P))
+ In expr, replace EXISTS{P} with prepare(EXISTS{P})
FS := FS ∪ {expr}
End
FILTER
ElementsFS
is used
later.
+ Prepare FILTER for exists.
+
+
+
+
+Replace each occurence of `Y` in X where `Y` is one of
+ Basic Graph Pattern,
+ Property Path Expression,
+ Graph(Var, pattern),
+ Inline Data
+ with join(Y, BindingInScope()) .
+
+ A current-row stack in EXISTS isless intrusive.
+ F(v) = v1 if v is in PV, where v1 is a fresh variable
+F(v) = v if v is not in PV
+ ProjectMap(Project(A, PV)) = Project(A1, PV)
+ where A1 is the result of applying F
+ to every variable mentioned in A.
+ EXISTS
:PrjMap(X) = replace all project operations Project(P, PV)
+ with ProjectMap(P, PV) for each projection in X.
+ Translate Property Path Expressions
Filters of Group
Simplification step
-
Replace Join(Z, A) by A
-Replace Join(A, Z) by A
-
+Replace Join(A, Z) by A
Evaluation Semantics
Evaluation Semantics
The value exists(|P|), given |D|(|G|) is true if and only if eval( |D|(|G|), substitute(|P|, μ)) is
@@ -10602,209 +10722,6 @@
Evaluation Semantics
eval( |D|(|G|), Slice(|L|, |start|, |length|) ) = Slice( eval(|D|(|G|), |L|), |start|, |length| )
Values Insertion and `EXISTS`
- Syntax Restriction
-
- Any variable that is assigned to in the graph pattern of `EXISTS`/`NOT EXISTS` must not be in-scope.
- This applies to `BIND`, variables introduced by `AS` in a `SELECT` clause, variables in a `VALUES`
- clause, and variables introduced by `AS` in `GROUP BY`.
-
-
-
-
-
-
- Syntax Form
- In-scope variables
-
-
-
- `EXISTS` and `NOT EXISTS` filters
-
- v
is in-scope if it is in-scope for the pattern to which the `FILTER` is applied.
- Remapping
- F(v) = v1 if v is not in PV, where v1 is a fresh variable
-F(v) = v if v is in PV
- ProjectMap(Project(A, PV)) = Project(A1, PV)
- where A1 is the result of applying F
- to every variable mentioned in A.
-
- EXISTS
:PrjMap(X) = replace all project operations Project(P, PV)
- with ProjectMap(Project(A, PV), PV) for each projection in X.
- Values Insertion
-
-Replace each occurence of Y where Y is one of
- Basic Graph Pattern,
- Property Path Patterns,
- Graph(Var, pattern),
- Inline Data
- with join(Y, BindingInScope()).
- Let Table(μ) = { μ } and multiplicity( μ | Table(μ) = { μ } ) = 1
-
-Replace each occurence of Y in X where Y is one of
- Basic Graph Pattern,
- Property Path Patterns,
- Graph(Var, pattern),
- Inline Data
- with join(Y, Table(μ)).
-
- Evaluation of EXISTS
- exists(X) = true
- if eval( D(G), μ)
- is a non-empty solution sequence.
-exists(X) = false otherwise
-