Uploaded image for project: 'Blazegraph (by SYSTAP)'
  1. Blazegraph (by SYSTAP)
  2. BLZG-887

Incorrect AST generated for OPTIONAL { SELECT }

    XMLWordPrintable

    Details

      Description

      We expect all 3 projected variables to be bound for the particular binding. However, legalName is left unbound ? it does not exist in the same named graph as fullName.

      If we remove one of the optionals, or rename the variables in the nested subselects, we get the expected result.

      When looking at the query plan, the nested subselects are being lifted out; and opt2 has ?a and ?g in the list of projectInVars ? even though those variables are clearly not shared.

      Query:

      PREFIX g: <http://example.org/graphs#>
      PREFIX d: <http://example.org/data#>
      PREFIX p: <http://example.org/person#>
      
      # since all 3 predicates are used in the test data, all 3 variables should end up bound here
      SELECT ?id ?fullName ?legalName {
        {select ?entity ?id {
            graph ?g { ?entity p:id ?id }
            graph g:pointers { ?entity ?a ?g }
        }}
      
        # ?a and ?g end up being projected into the next query
        # changing ?a => ?a1; ?g => ?g1 fixes this
        optional {
          select ?entity ?fullName {
              graph g:pointers { ?entity ?a ?g }
              graph ?g { ?entity p:fullName ?fullName  }
          }
        }
      
        optional {
          select ?entity ?legalName {
              graph ?g { ?entity p:legalName ?legalName  }
              graph g:pointers { ?entity ?a ?g }
          }
        }
      }
      

      Data (trig)

      @prefix g: <http://example.org/graphs#> .
      @prefix d: <http://example.org/data#> .
      @prefix p: <http://example.org/person#> .
      
      g:graph1 {
        d:foo p:id "123"
      }
      
      g:graph2 {
        d:foo p:fullName "Bryan Thompson"
      }
      
      g:graph3 {
        d:foo p:legalName "Bryan Thompson 123"
      }
      
      g:pointers {
        d:foo d:a g:graph1 .
        d:foo d:b g:graph2 .
        d:foo d:c g:graph3
      }
      

      Expected results:

      <?xml version='1.0' encoding='UTF-8'?>
      <sparql xmlns='http://www.w3.org/2005/sparql-results#'>
          <head>
              <variable name='id'/>
              <variable name='fullName'/>
              <variable name='legalName'/>
          </head>
          <results>
              <result>
                  <binding name='id'>
                      <literal>123</literal>
                  </binding>
                  <binding name='fullName'>
                      <literal>Bryan Thompson</literal>
                  </binding>
                  <binding name='legalName'>
                      <literal>Bryan Thompson 123</literal>
                  </binding>
              </result>
          </results>
      </sparql>
      

        Attachments

          Activity

            People

            Assignee:
            bryanthompson bryanthompson
            Reporter:
            bryanthompson bryanthompson
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: