diff --git a/spec/index.html b/spec/index.html index 39d9604..ef694e8 100644 --- a/spec/index.html +++ b/spec/index.html @@ -8781,16 +8781,27 @@

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. + + -

The variable 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.

+

The variable 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. +

In 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.

+ in-scope from the preceeding elements in the group graph pattern in which it is used. +

In 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.

+ the clause. +

Converting Graph Patterns

@@ -8860,6 +8871,7 @@
Expand Syntax Forms

Expand abbreviations for IRIs and triple patterns given in Section .

+
Collect FILTER Elements

FILTER expressions apply to the whole group graph pattern in which they @@ -8875,13 +8887,120 @@

Collect FILTER Elements
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

The set of filter expressions FS is used later.

+ +
+ Prepare EXISTS and NOT EXISTS +

prepare(EXISTS{P})

+ +
+

@@ Scoping rule already done (grammar note).
+ Prepare FILTER for exists. +

+
    +
  • A1 = translate(P) without applying simplification
  • +
  • A2 = A1 rewritten to include access current binding
  • +
  • A3 = A2 Remapped hidden-scope variables (if we do that)
  • +
+ +
+
+ Definition: Access to the current binding +

+ During translation to the SPARQL algebra +

+
+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()) .
+
+
+ c.f. section Translate Graph Patterns + where an empty basic graph pattern start any + GroupGraphPattern. + It happens before the simplification step. +
+
+ +
+

+ 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.
+ A current-row stack in EXISTS isless intrusive. +

+
+ +
+ Definition: Projection Expression Variable Remapping +

+ 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:

+
+ Definition: Variable Remapping +

+ 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. +

+

+ This operation is as part of the translation to the SPARQL + algebra. +

+
+
+
+ +
Translate Property Path Expressions

The following table gives the translation @@ -9078,7 +9197,6 @@

Translate Graph Patterns

If the form is 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
@@ -9139,14 +9257,17 @@ 
Filters of Group
Simplification step
-

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:

 Replace Join(Z, A) by A
-Replace Join(A, Z) by A
-
+Replace Join(A, Z) by A
@@ -10454,6 +10575,12 @@

Evaluation Semantics

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 @@ -10469,6 +10596,9 @@

Evaluation Semantics

Definition: Evaluation of Exists

+ +

@@ Update

+

Let μ be the current solution mapping for a filter and |P| a graph pattern:

The value exists(|P|), given |D|(|G|) is true if and only if eval( |D|(|G|), substitute(|P|, μ)) is @@ -10593,6 +10723,7 @@

Evaluation Semantics

+

Extending SPARQL Basic Graph Matching

The overall SPARQL design can be used for queries which assume a more elaborate form of @@ -10946,52 +11077,95 @@

Grammar

section 6 Notation.

Notes:

    -
  1. Keywords are matched in a case-insensitive manner with the exception of +
  2. + Keywords are matched in a case-insensitive manner with the exception of the keyword '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).
  3. -
  4. Escape sequences are case sensitive.
  5. -
  6. When tokenizing the input and choosing grammar rules, the longest match is chosen.
  7. -
  8. The SPARQL grammar is LL(1) when the rules with uppercased names are used as terminals.
  9. -
  10. There are two entry points into the grammar: QueryUnit for the SPARQL query language - and UpdateUnit for the SPARQL update language.
  11. -
  12. In signed numbers, no white space is allowed between the sign and the number. + (in full, http://www.w3.org/1999/02/22-rdf-syntax-ns#type). +
  13. +
  14. + Escape sequences are case sensitive. +
  15. +
  16. + When tokenizing the input and choosing grammar rules, the longest match is chosen. +
  17. +
  18. + The SPARQL grammar is LL(1) when the rules with uppercased names are used as terminals. +
  19. +
  20. + There are two entry points into the grammar: QueryUnit for the SPARQL query language + and UpdateUnit for the SPARQL update language. +
  21. +
  22. + In signed numbers, no white space is allowed between the sign and the number. The 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.
  23. -
  24. The tokens INSERT DATA, + produce an addition or subtraction of the unsigned number as appropriate. +
  25. +
  26. + The tokens 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.
  27. -
  28. The QuadData and + The single space version is used in the grammar for clarity. +
  29. +
  30. + The 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.
  31. -
  32. Blank node syntax is not allowed in DELETE WHERE, + must not allow variables in the quad patterns. +
  33. +
  34. + Blank node syntax is not allowed in DELETE WHERE, the DeleteClause for DELETE, - nor in DELETE DATA.
  35. -
  36. Rules for limiting the use of blank node identifiers are given in section 19.6.
  37. -
  38. The number of variables in the variable list of VALUES block - must be the same as the number of each list of associated values in the DataBlock.
  39. -
  40. Variables introduced by AS in a SELECT clause - must not already be in-scope.
  41. -
  42. The variable assigned in a BIND clause must not be already + nor in DELETE DATA. +
  43. +
  44. + Rules for limiting the use of blank node identifiers are given in + section 19.6. +
  45. +
  46. + The number of variables in the variable list of VALUES block + must be the same as the number of each list of associated values in + the DataBlock. +
  47. +
  48. + Variables introduced by AS in a SELECT clause + must not already be in-scope. +
  49. +
  50. + The variable assigned in a BIND clause must not be already in-use within the immediately preceding TriplesBlock within a - GroupGraphPattern.
  51. -
  52. Aggregate functions can be one of the + GroupGraphPattern. +
  53. +
  54. + Any variable that is assigned to in the graph pattern of `EXISTS` or `NOT EXISTS` + must not be in-scope. This applies to `BIND`, + variables introduced by `AS` in a `SELECT` clause, + variables introduced by `AS` in `GROUP BY`, + and variables in a `VALUES` clause. +
  55. +
  56. + Aggregate functions can be one of the built-in keywords for aggregates or a custom aggregate, which is syntactically a function call. Aggregate functions may only be used in SELECT, HAVING - and ORDER BY clauses.
  57. -
  58. The expression argument of an aggregate function can not contain an aggregate function.
  59. -
  60. Only custom aggregate functions use the DISTINCT keyword - in a function call.
  61. -
  62. A reifier or + and ORDER BY clauses. +
  63. +
  64. + The expression argument of an aggregate function can not contain an aggregate function. +
  65. +
  66. + Only custom aggregate functions use the DISTINCT keyword + in a function call. +
  67. +
  68. + A reifier or annotation syntax is only permitted after a triple when the property position is a simple path (an IRI, the keyword a, or a variable),