aio-libs / aiosparql

An asynchronous SPARQL client library using aiohttp
Apache License 2.0
26 stars 10 forks source link

KeyError when query includes "UNION" #96

Open BAAngelos opened 3 years ago

BAAngelos commented 3 years ago

pretty much the title.

I'm a big fan of this package, it helped me alot in my Masterthesis but today I seemed to have trouble with it.

from aiosparql.client import SPARQLClient

async with SPARQLClient("https://dbpedia.org/sparql") as client:
       result = await client.query("select ?redirects where {{?redirects dbo:wikiPageRedirects dbr:Big_Trout_Lake} union {dbr:Big_Trout_Lake dbo:wikiPageRedirects ?redirects}}")

this query seems to break and infact every query that includes "UNION". For now I will try to work around it by quering the endpoint two times and concatinate the results afterwards but it would be cool if you could fix that issue.

BAAngelos commented 3 years ago

Querying the endpoint two times and then combining the results afterwards was no problem. But it basically halves the amount of queries I can do per second because now I need two queries instead of one to resolve one task.

Nevertheless, I found a way to combine the queries in one without causing the KeyError Bug for anyone having the same problem

SELECT * WHERE {
       { select ?redirects where 
                {dbr:Big_Trout_Lake dbo:wikiPageRedirects ?redirects}
        }
UNION
        { select ?redirects where 
              { ?redirects dbo:wikiPageRedirects dbr:Big_Trout_Lake}
        }
}
asvetlov commented 2 years ago

@BAAngelos if you create a pull request I'm happy to review, merge and publish a new release.