You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@jena.apache.org by "nkaralis (via GitHub)" <gi...@apache.org> on 2025/04/04 07:34:27 UTC

[D] Evaluation of VALUES [jena]

GitHub user nkaralis created a discussion: Evaluation of VALUES

Hello.

I am having trouble understanding the evaluation of the VALUES clause when encountered in this grammar rule `Query ::= Prologue( SelectQuery | ConstructQuery | DescribeQuery | AskQuery ) ValuesClause`.

In section [10.2.2](https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#inline-data-examples), the specification states that, when this rule is used, the `VALUES` clause is to be executed over the results of the `SELECT` query. Provided this statement, I was expecting to be able to run queries as the one provided below.
```
SELECT ?s (MIN(?v) as ?min) WHERE {
    ?s <value> ?v 
}
GROUP BY ?s
VALUES ?min { 2 5 }
```
However, this query is rejected due to `?min` being already in scope when encountered in the `SELECT` clause. If I understand correctly, this is due to the order in which queries are processed; paragraph [18.2.4](https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#convertGroupAggSelectExpressions) states that the `VALUES` clause is processed before the `SELECT` clause.

I was hoping that someone could elaborate on how the `VALUES` clause is evaluated in the precesence of `GROUP BY`. If I understand the function `AggregateJoin` correctly, the `VALUES` clause can only be joined with keys of the `GROUP BY` clause. The example below demonstrates this. 

Is this correct? 
Thank you in advance.
```
# data: agg-numeric.ttl https://github.com/w3c/rdf-tests/blob/main/sparql/sparql11/aggregates/agg-numeric.ttl
# Apache Jena version 5.2.0

./arq --explain --query=test_values.rq --data=agg-numeric.ttl
09:21:11 INFO  exec            :: QUERY
  PREFIX  :     <http://www.example.org/>
  
  SELECT  ?i (MIN(?v) AS ?c)
  WHERE
    { ?i  :int  ?v } # possible bindings for ?v: 1, 2, 3 ; possible bindings for ?i: :ints, :mixed
  GROUP BY ?i
  VALUES ( ?i ?v ) {
    ( :ints 5 )
    ( :ints 6 )
  }
09:21:11 INFO  exec            :: ALGEBRA
  (project (?i ?c)
    (sequence
      (extend ((?c ?.0))
        (group (?i) ((?.0 (min ?v)))
          (bgp (triple ?i <http://www.example.org/int> ?v))))
      (table (vars ?i ?v)
        (row [?i <http://www.example.org/ints>] [?v 5])
        (row [?i <http://www.example.org/ints>] [?v 6])
      )))
09:21:11 INFO  exec            :: BGP ::   ?i <http://www.example.org/int> ?v
09:21:11 INFO  exec            :: Reorder/generic ::   ?i <http://www.example.org/int> ?v
-------------
| i     | c |
=============
| :ints | 1 |
| :ints | 1 |
-------------
```


GitHub link: https://github.com/apache/jena/discussions/3113

----
This is an automatically sent email for issues@jena.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@jena.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [D] Evaluation of VALUES [jena]

Posted by "nkaralis (via GitHub)" <gi...@apache.org>.
GitHub user nkaralis added a comment to the discussion: Evaluation of VALUES

Thank you for the clarification.

GitHub link: https://github.com/apache/jena/discussions/3113#discussioncomment-13067360

----
This is an automatically sent email for issues@jena.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@jena.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [D] Evaluation of VALUES [jena]

Posted by "afs (via GitHub)" <gi...@apache.org>.
GitHub user afs edited a comment on the discussion: Evaluation of VALUES

Hi @nkaralis - thanks for the detailed write-up. 

It looks like the scope checking is wrong in the first (`?min`) case.


GitHub link: https://github.com/apache/jena/discussions/3113#discussioncomment-12730494

----
This is an automatically sent email for issues@jena.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@jena.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [D] Evaluation of VALUES [jena]

Posted by "afs (via GitHub)" <gi...@apache.org>.
GitHub user afs added a comment to the discussion: Evaluation of VALUES

It looks like an error in the spec - I've added https://github.com/w3c/sparql-query/issues/215 to make sure its not forgotten.

(VALUES is suppose to support a distributed query "bind" join but there is little real use of that as far as I'm aware)

GitHub link: https://github.com/apache/jena/discussions/3113#discussioncomment-13067279

----
This is an automatically sent email for issues@jena.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@jena.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [D] Evaluation of VALUES [jena]

Posted by "afs (via GitHub)" <gi...@apache.org>.
GitHub user afs added a comment to the discussion: Evaluation of VALUES

Hi @nkaralis - thanks for the detailed write-up. 

It looks that the scope checking is wrong in the first (`?min`) case.


GitHub link: https://github.com/apache/jena/discussions/3113#discussioncomment-12730494

----
This is an automatically sent email for issues@jena.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@jena.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [D] Evaluation of VALUES [jena]

Posted by "afs (via GitHub)" <gi...@apache.org>.
GitHub user afs added a comment to the discussion: Evaluation of VALUES

#3164 fixes this.

GitHub link: https://github.com/apache/jena/discussions/3113#discussioncomment-13037677

----
This is an automatically sent email for issues@jena.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@jena.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org


Re: [D] Evaluation of VALUES [jena]

Posted by "nkaralis (via GitHub)" <gi...@apache.org>.
GitHub user nkaralis added a comment to the discussion: Evaluation of VALUES

Hello.
Thank you for the update.

I am still puzzled with the evaluation of `VALUES` though.
In particular, from the standard, it is not entirely clear to me when its evaluation should take place.

As mentioned in my original post, paragraph 10.2.2 states that the `VALUES` clause is to be executed over the results of `SELECT` queries.
However, systems should follow paragraph 18.2.4, which states that the `VALUES` clause should be processed before the `SELECT` clause. This means that the `VALUES` clause is not actually evaluated over the results of the `SELECT` clause in the presence of aggregates and `GROUP BY`.
Is this correct?

GitHub link: https://github.com/apache/jena/discussions/3113#discussioncomment-13062342

----
This is an automatically sent email for issues@jena.apache.org.
To unsubscribe, please send an email to: issues-unsubscribe@jena.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org