The general query containment and equivalence problem is undecidable.  There is some work on doing this when restrictions are placed on the queries.  Here is one paper on the subject: https://hal.inria.fr/file/index/docid/691610/filename/RR-7942.pdf

On 9/8/2022 3:54 AM, Rushikesh Halle wrote:
Hello community,

How to check equivalence of two sparql queries ?
We have tried the QueryCompare.equals(), Op.equalTo() methods. But they
seem to be sensitive to the order of operands in joins, unions.

*Example: *The following queries are equivalent, because irrespective of
the order of operands to the UNION operator, the query should give the same
solution set. But, the QueryCompare.equals(query1, query2) operation
returns 'false'.

*query1:*

PREFIX dc10:  <http://purl.org/dc/elements/1.0/>
PREFIX dc11:  <http://purl.org/dc/elements/1.1/>

SELECT ?title WHERE  {
     { ?book dc10:title  ?title }
     UNION
     { ?book dc11:title  ?title }
}

*query2:*

PREFIX dc10:  <http://purl.org/dc/elements/1.0/>
PREFIX dc11:  <http://purl.org/dc/elements/1.1/>

SELECT ?title WHERE  {
     { ?book dc11:title  ?title }
     UNION
     { ?book dc10:title  ?title }
}


*Use Case:* Currently we are writing our own query transformer for
domain specific optimisation. We want to check the equivalence of queries
for Unit testing. The test should pass if the expected and actual queries
are equivalent.

Is there any existing way of checking query equivalence?

Thanks in advance,
Rushikesh

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to