-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Query Parameterization #57
Comments
+1 I like the idea of standardizing parameterization. However,
More than "frown", I'd consider it really worrisome to break existing queries that happen to use Regarding there being "no value," my recollection is that the two variable syntaxes were introduced to ease use of SPARQL in languages that might have different escaping rules for |
TopQuadrant's approach to this are SPIN templates, originally introduced more than 10 years ago for SPARQL 1.0. It is not a SPARQL extension, but a layer on top of SPARQL. A SPIN template is a resource described in RDF, with properties for the query that we want to parameterise, and for the arguments to be passed in. Here is an illustration—it's not actual SPIN, as some of the naming and design choices in SPIN distract from the core idea:
So we have two arguments, The template can be invoked like so:
This doesn't use the SPARQL endpoint but a separate endpoint for template queries. The main downside of this approach is the relatively verbose syntax, and mixing Turtle and SPARQL in the same file. TopQuadrant has always had IDE support for working with this, so we rarely write/edit these files by hand. A significant advantage is the ability to add arbitrary additional properties, e.g., for documentation, access control, and categorisation of services. The main takeaway is that parameterised queries do not require an extension to SPARQL, but can be done as a layer on top, and this approach has been successfully used in production systems for many years. Half of what's needed to standardise this is already in SHACL. |
another option is to provide for parameters at the protocol level and leave the implementation to perform dynamic binding or query rewriting as it sees fit.
which is
both of
are possible. |
Triply-Dev/YASGUI.YASQE-deprecated#24 is a great discussion |
following on to that discussion, we eventually implemented a mechanism to allow values clauses the mechanism uses the values clause dimensions to perform substitutions in the symbolic sparql expression. |
http://docs.rdf4j.org/rest-api/#_repository_queries is broken. @jeenbroekstra Isn't there an equivalent chapter in rdf4j's new documentation? |
@VladimirAlexiev the more up to date link is https://rdf4j.org/documentation/reference/rest-api/ . |
Is there are list of triplestores that support this REST API? Specifically repository creation: |
Any triplestore that implements the RDF4J Repository or Sail API can be exposed through this REST API using the RDF4J Server application. But if you're asking which stores support this REST API directly, I don't have an exhaustive list I'm afraid. From the top of my head I believe GraphDB, Halyard, and Strabon do so, though I haven't checked or tested this. |
https://afs.github.io/substitute.html covers query parameterization. The difference between EXISTS usage and query parameterization is the treatment of nested SELECT. For query parameterization, it would seem natural to allow substitution by name inside nested SELECT even when the variable is not exposed by the inner project. That's whether to apply the scope-sensitive renaming or not. Example: replacement of ?c in:
|
in relation to jena's notion, the term |
Is the trailing VALUES clause specifically made for this purpose? Because you can just append it to the query. |
a mechanism which accepts a values clause as parameter has a very different behaviour than one which accepts individual variable bindings. |
Not really. The VALUES syntax at that point isn't treated specially to VALUES anywhere else in a query. It is join'ed with the evaluation of results of the query so far (it is after GROUP BY and HAVING, for example). It can't "see" all variables. https://www.w3.org/TR/sparql11-query/#sparqlAlgebraFinalValues It would have an effect of parameterization in some cases but not all. It is different behaviour. I think the user intuition of parameterization of a query is more syntactic - replace a variable by a value at the syntax level before processing the query, replace everywhere in the query, including inside sub-queries. It is on the "input", not the "output". If the replacement is "bad" (e.g. |
some ambiguity in expectations could be traced to the passage in the federation recommendation
|
Why?
Many people can't write SPARQL but can invoke queries written by others.
Then it's important to be able to pass (bind) parameters into the query, eg some fixed object, or a date range.
Previous work
$abc
and?abc
identify the same variable" but some implementations use$var
to indicate a parameter (as opposed to a free var)$var
to be those that are bound before execution and?var
those that are bound during execution (or vice versa). This relies on local convention."$var
: http://docs.rdf4j.org/rest-api/#_repository_queries. The value must be provided in ntriples format?x
) or positional param (bare?
): https://jena.apache.org/documentation/query/parameterized-sparql-strings.html_status
: mandatory plain literal__substatus
: optional plain literal_age_integer
: xsd:integer literal_knows_iri
: IRI_title_en
: literal, to which a lang@en
is tacked_created_xsd_date
: literal, to which a datatype^^xsd:date
is tackeddefaults
to give default values (see example)enumeration
to populate a drop-down (see example)Proposed solution
$var
to mean "query parameter", allow it as a parameter in the SPARQL http protocol and also accepting values in Turtle syntax (so prefixes can be used)Considerations for backward compatibility
$
for this purpose, but IMHO there's no value in having two variable prefix chars.$this
is bound to the resource being evaluated. @pfps has expressed concerns about its semantics. But if the param value is replaced textually in all occurrences of$var
(even in subqueries), I think that's quite clear? That is another argument to remove the meaning "free variable" from$
.The text was updated successfully, but these errors were encountered: