Skip to content

?Bug in appling FILTER to results when using UNION #7

Description

@AntonHelfie

When running a query where FILTER is used in one group of a UNION and makes use of a variable bound outside either group, results from the other half of the union appear to be discarded.

RDF:

@base <http:>.

<test> 
     <has> "1";
     <knows> <A> .

<A>
    <has> "2";
    <knows> <test> ;
    <knows> <B> .

<B>
    <has> "1";
   <knows> <test> ;
    <knows> <A> .

<C>
    <has> "2";
    <knows> <A> .

QUERY:



BASE <http:>

SELECT ?person ?num 
WHERE {
    ?person <has> ?num .
    {
         ?person <knows> <test>.
    }
   UNION
    {
         ?person <has> ?num FILTER (?num = "2").
    }  
}

RESULTS:

<http:A> | "2"
<http:C> | "2"

EXPECTED RESULTS (by changing ?num variable name in the second union group):

<http:A> | "2"
<http:B> | "1"
<http:A> | "2"
<http:C> | "2"

I have tested this here: https://www.leskoff.com/s02217-0
My query does produce the intended results there.

RDF

@base <http:a\>.


<:test> 
     <:has> "1";
     <:knows> <:A> .

<:A>
    <:has> "2";
    <:knows> <:test> ;
    <:knows> <:B> .

<:B>
    <:has> "1";
   <:knows> <:test> ;
    <:knows> <:A> .

<:C>
    <:has> "2";
    <:knows> <:A> .

QUERY

SELSELECT ?person ?num 
WHERE {
  
    ?person <:has> ?num .
    {
?person <:knows> <:test>.
     
    }
   UNION
    {
      ?person <:has> ?num FILTER (?num = "2").
    }  
}

RESULTS

?person | ?num

<:B> | "1"
<:A> | "2"
<:A> | "2"
<:C> | "2"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions