On 08/09/2022 09:54, 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.
The contract on QueryCompare is "same syntax".
*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'.
There's isn't anything for such semantic equivalence, including the
simple cases of BGP order.
*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.
For optimization, ARQ's query tranform mechinary works on the query
algebra, not the surface syntax. While there is some for syntax rewrite,
most is with the org.apache.jena.sparql.algebra.Transform interface, not
ElementTransform.
There is OpAsQuery which converts an algebra expression into query syntax.
Is there any existing way of checking query equivalence?
Only by writing some code. You write something that check equivalence of
known cases (BGP order, UNION)
Andy
Thanks in advance,
Rushikesh