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

Andy Seaborne commented on JENA-2335:
-------------------------------------

Hi [~jmkeil]

This looks like https://github.com/apache/jena/issues/1369

The output from the development code is currently:

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

and the invariant of "same algebra" is maintained:

{code:java}
    public static void main(String...a) {
        String qs = "SELECT ?a ?d WHERE { ?a <http://example.org/p> ?b . 
BIND(?b AS ?c) BIND(?c AS ?d) }";
        Query q1 = QueryFactory.create(qs);
        Op op1 = Algebra.compile(q1);
        Query q2 = OpAsQuery.asQuery(op1);
        Op op2 = Algebra.compile(q2);

        System.out.println(q1);
        System.out.println(q2);
        System.out.println("Algebra equals: "+op1.equals(op2));
    }
{code}
Tests for 1369:
[sparql/algebra/TestOpAsQuery.java|https://github.com/apache/jena/blob/7c0b20742a8fac15da14f256debbbbbeeeb40eaa/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestOpAsQuery.java#L74]



> Query -> Algebra -> Query not equivalent in case of a BIND not in the result 
> vars
> ---------------------------------------------------------------------------------
>
>                 Key: JENA-2335
>                 URL: https://issues.apache.org/jira/browse/JENA-2335
>             Project: Apache Jena
>          Issue Type: Bug
>          Components: ARQ, Optimizer
>    Affects Versions: Jena 4.5.0
>            Reporter: Jan Martin Keil
>            Priority: Major
>
> 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:
> {code:java}
> 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)"));
>       }
> }
> {code}
> This results in the following query:
> {code:sql}
> SELECT  ?a (?c AS ?d)
> WHERE
>   { ?a  <http://example.org/p>  ?b }
> {code}
> 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.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to