You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by "Andy Seaborne (JIRA)" <ji...@apache.org> on 2015/01/30 11:22:34 UTC

[jira] [Comment Edited] (JENA-874) Subqueries not functioning properly when Filter clauses are present

    [ https://issues.apache.org/jira/browse/JENA-874?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14298438#comment-14298438 ] 

Andy Seaborne edited comment on JENA-874 at 1/30/15 10:21 AM:
--------------------------------------------------------------

Files {{jena-874*}} are query and data with only relevant features in the FILTER case.

Works:
* Jena 2.12.0
* {{sparql --engine=ref --data jena-874-data.ttl  --query jena-874-query.rq}}
* {{sparql --opt=off --data jena-874-data.ttl  --query jena-874-query.rq}}

Does not work:
* Jena 2.12.1
* Development: {{sparql --data jena-874-data.ttl  --query jena-874-query.rq}}

The critical factor is the use of DISTINCT on the sub-query:

Without DISTINCT:
{noformat}
(sequence
  (project (?id)
    (table (vars ?id)
      (row [?id <http://r1>])
    ))
  (filter (!= ?type <http://type>)
    (bgp (triple ?id <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type))))
{noformat}
and with DISTINCT:
{noformat}
(sequence
  (distinct
    (filter (!= ?type <http://type>)
      (project (?id)
        (table (vars ?id)
          (row [?id <http://r1>])
        ))))
  (bgp (triple ?id <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type)))
{noformat}

i.e. the presence of {{(distinct)}} confuses filter placement.



was (Author: andy.seaborne):
Example with minimal data and query.

> Subqueries not functioning properly when Filter clauses are present
> -------------------------------------------------------------------
>
>                 Key: JENA-874
>                 URL: https://issues.apache.org/jira/browse/JENA-874
>             Project: Apache Jena
>          Issue Type: Bug
>          Components: ARQ
>    Affects Versions: Jena 2.12.2
>            Reporter: Stephen Allen
>            Priority: Blocker
>         Attachments: TestSubquery.java, jena-874-data.ttl, jena-874-query.rq
>
>
> Queries with Subqueries are not functioning properly when a filter clause exists.  This is a regression, as it worked properly in 2.11.2 (I haven't checked 2.12.1).
> Example:
> {code:title=data.ttl}
> <http://r1> a <http://type> .
> <http://r1> a <http://type2> .
> <http://r2> a <http://type> .
> <http://r2> a <http://type2> .
> <http://r3> a <http://type> .
> <http://r3> a <http://type2> .
> {code}
> {code:title=Bind Query}
> select *
> where {
>   graph <http://graph1> {
>     {
>       select distinct (?_id as ?id)
>       where {
>         values ?_type {
>           <http://type2>
>         }
>         ?_id a ?_type .
>         ?_id a <http://type> .
>         filter ( ?_id = <http://r1> || ?_id = <http://r2> )
>       }
>     }
>     ?id a <http://type> . bind (<http://type2> as ?type) . ?id a ?type .
>   }
> }
> order by ?id
> {code}
> {code:title=Bind Algebra}
> (base <http://example/base/>
>   (order (?id)
>     (graph <http://graph1>
>       (join
>         (extend ((?type <http://type2>))
>           (join
>             (distinct
>               (project (?id)
>                 (extend ((?id ?_id))
>                   (filter (|| (= ?_id <http://r1>) (= ?_id <http://r2>))
>                     (join
>                       (table (vars ?_type)
>                         (row [?_type <http://type2>])
>                       )
>                       (bgp
>                         (triple ?_id <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?_type)
>                         (triple ?_id <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://type>)
>                       ))))))
>             (bgp (triple ?id <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://type>))))
>         (bgp (triple ?id <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type))))))
> {code}
> {code:title=Filter Query}
> select *
> where {
>   graph <http://graph1> {
>     {
>       select distinct (?_id as ?id)
>       where {
>         values ?_type {
>           <http://type2>
>         }
>         ?_id a ?_type .
>         ?_id a <http://type> .
>         filter ( ?_id = <http://r1> || ?_id = <http://r2> )
>       }
>     }
>     ?id a <http://type> . ?id a ?type . filter (?type != <http://type> ) .
>   }
> }
> order by ?id
> {code}
> {code:title=Filter Algebra}
> (base <http://example/base/>
>   (order (?id)
>     (graph <http://graph1>
>       (filter (!= ?type <http://type>)
>         (join
>           (distinct
>             (project (?id)
>               (extend ((?id ?_id))
>                 (filter (|| (= ?_id <http://r1>) (= ?_id <http://r2>))
>                   (join
>                     (table (vars ?_type)
>                       (row [?_type <http://type2>])
>                     )
>                     (bgp
>                       (triple ?_id <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?_type)
>                       (triple ?_id <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://type>)
>                     ))))))
>           (bgp
>             (triple ?id <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://type>)
>             (triple ?id <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type)
>           ))))))
> {code}
> For both queries, the results should look like:
> {code}
> --------------------------------
> | id          | type           |
> ================================
> | <http://r1> | <http://type2> |
> | <http://r2> | <http://type2> |
> --------------------------------
> {code}
> However, only the Bind query actually works correctly.  The Filter query returns no rows.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)