Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a SPARQL query builder in all sparql endpoint adapters #318

Open
cmungall opened this issue Oct 18, 2022 · 2 comments
Open

Use a SPARQL query builder in all sparql endpoint adapters #318

cmungall opened this issue Oct 18, 2022 · 2 comments

Comments

@cmungall
Copy link
Collaborator

Currently we use a mixture of rdflib and sparqlwrapper in all sparql implementations (recall we also use sparql for local rdf files as well).

These provide extremely low-level interfaces and assume string construction of SPARQL queries, and leave it to the caller to avoid bobby tables style injections. Additionally, string manipulation of queries is an antipattern. E.g. this kind of thing:'SELECT {" ".join(select_vars)}' + where_clause

To circumvent this we have various helper classes and a simple SPARQL query object dataclasses, e.g

class SparqlQuery:
"""
Represents a SPARQL query
"""
distinct: bool = None
select: List[VAR_NAME] = None
graph: Optional[Union[URI, List[URI]]] = None
where: List[WHERE_CLAUSE] = None
limit: int = None

However, query construction is still fairly low level.

We should use modern query builder patterns here. Options are:

  1. reuse an existing library
  2. generalize the existing helper classes into a separate standalone library that could be used by others

When I last looked into 1, I was disappointed by the current state of python sparql query builders, lots of abandonware. This seems surprising given the maturity of SPARQL. However, we should do another review before deciding on a course of action.

Note that the requirements here are for a query builder library. We have existing template libraries like sparqlfun, but we want to be able to do things like programmatically compose queries.

@matentzn
Copy link
Contributor

@anitacaron cc

We should make sure that we only have one such solution in OAK.. Seems closely related to your work in SSSOM API.

@anitacaron
Copy link
Collaborator

I'm using the SparqlQuery class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants