Uploaded image for project: 'Apache Jena'
  1. Apache Jena
  2. JENA-2335

Query -> Algebra -> Query not equivalent in case of a BIND not in the result vars

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Delivered
    • Jena 4.5.0
    • Jena 4.6.0
    • ARQ, Optimizer
    • None

    Description

      Converting a query into algebra and back results in a not equivalent query, if the query contains a BIND clause thous variable is not part of the result variables, but other variables depend on it. Minimal example:

      import static org.junit.jupiter.api.Assertions.assertTrue;
      
      import org.apache.jena.query.QueryFactory;
      import org.apache.jena.sparql.algebra.AlgebraGenerator;
      import org.apache.jena.sparql.algebra.OpAsQuery;
      import org.junit.jupiter.api.Test;
      
      public class OpTest {
      	@Test
      	public void retainVariables() {
      		String sparqlStrBeforOp = "SELECT ?a ?d WHERE { ?a <http://example.org/p> ?b . BIND(?b AS ?c) BIND(?c AS ?d) }";
      		String sparqlStrAfterOp = OpAsQuery.asQuery(new AlgebraGenerator().compile(QueryFactory.create(sparqlStrBeforOp))).toString();
      		System.out.println(sparqlStrAfterOp);
      		assertTrue(sparqlStrAfterOp.contains("(?b AS ?c)"));
      	}
      }
      

      This results in the following query:

      SELECT  ?a (?c AS ?d)
      WHERE
        { ?a  <http://example.org/p>  ?b }
      

      Use case: I do the conversion back and forth to remove not needed result variables of a given query on algebra level, which is not possible on queries directly.

      Attachments

        Issue Links

          Activity

            People

              andy Andy Seaborne
              jmkeil Jan Martin Keil
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: