Steve,

> On 14 May 2020, at 12:53, Steve Vestal <[email protected]> wrote:
> 
> Thank you very much, very helpful.
> 
> One final question.  When you say a FILTER (such as FILTER
> {!sameTerm(a,b)}) removes certain solutions in a SELECT query, does that
> mean it removes rows that do not pass the FILTER?  It does not try and
> do anything clever about removing individual values within a row?

Yes, correct.

However, it removes rows from the *intermediate result table* at that point in 
the query. After that intermediate result is combined with other intermediate 
results into the final query result, it might seem as if a single value has 
been removed from a row.

Example:

  SELECT * {
      VALUES (?a ?b) { (1 2) (3 4) }
  }

Result:

  ---------
  | a | b |
  =========
  | 1 | 2 |
  | 3 | 4 |
  ---------

Now add an OPTIONAL clause:

  SELECT * {
      VALUES (?a ?b) { (1 2) (3 4) }
      OPTIONAL {
          VALUES (?b ?c) { (2 5) (4 6) }
      }
  }
  -------------
  | a | b | c |
  =============
  | 1 | 2 | 5 |
  | 3 | 4 | 6 |
  -------------

Now add a FILTER inside the OPTIONAL:

  SELECT * {
      VALUES (?a ?b) { (1 2) (3 4) }
      OPTIONAL {
          VALUES (?b ?c) { (2 5) (4 6) }
          FILTER (?c != 6)
      }
  }
  -------------
  | a | b | c |
  =============
  | 1 | 2 | 5 |
  | 3 | 4 |   |
  -------------

This looks as if a single value was removed from a row. But a better way to 
look at it would be to say that the complete second row (?b ?c) = (4 6) was 
removed from the OPTIONAL's intermediate result, and that leads to the single 
missing value after the intermediates are joined to produce the final result.

Richard

Reply via email to