Great, thanks. Is this the recommended way to do substitutions now? Compared to syntax-based ones like the ParameterizedSparqlString.
On Mon, Nov 25, 2024 at 12:55 PM Andy Seaborne <a...@apache.org> wrote: > > > > On 25/11/2024 11:14, Martynas Jusevičius wrote: > > Thanks Andy. > > > > I cannot directly use QueryExecution because I'm executing remotely > > using my own HTTP client (Jersey client). > > > > But I suppose I can do to the query string what ExecHTTPBuilder is > > doing to it? Is it as simple as > > > > queryActual = QueryTransformOps.transform(queryActual, substitutionMap); > > > > ? I'm looking here: > > https://github.com/apache/jena/blob/main/jena-arq/src/main/java/org/apache/jena/http/sys/ExecHTTPBuilder.java#L331C13-L331C85 > > Yes. > > > > > On Mon, Nov 25, 2024 at 12:03 PM Andy Seaborne <a...@apache.org> wrote: > >> > >> Another way is at execution time: > >> > >> QueryExecution.... > >> .query(query string or object) > >> .substitution(varName, value); > >> > >> which uses QueryTransformOps. > >> > >> Andy > >> > >> > >> On 25/11/2024 08:40, Martynas Jusevičius wrote: > >>> Hi Lorenz, > >>> > >>> thanks, but wouldn't these methods append VALUES at the end of the > >>> query? Which would not be equivalent to having it injected at the > >>> beginning? > >>> > >>> I don't want to build the whole query with Java -- I already have a > >>> query string. > >>> > >>> Martynas > >>> > >>> On Mon, Nov 25, 2024 at 7:58 AM Lorenz Buehmann > >>> <buehm...@informatik.uni-leipzig.de> wrote: > >>>> > >>>> Hi, > >>>> > >>>> you mentioned a query builder, so did you try to use the Jena query > >>>> builder already? If so, > >>>> > >>>> the method addWhereValueVars on the SelectBuilder[1] or directly on the > >>>> WhereBuilder[2] would be the way to go. > >>>> > >>>> > >>>> Cheers, > >>>> > >>>> Lorenz > >>>> > >>>> [1] > >>>> https://jena.apache.org/documentation/javadoc/extras/querybuilder/org.apache.jena.querybuilder/org/apache/jena/arq/querybuilder/SelectBuilder.html#addWhereValueVars(java.util.Map) > >>>> > >>>> > >>>> [2] > >>>> https://jena.apache.org/documentation/javadoc/extras/querybuilder/org.apache.jena.querybuilder/org/apache/jena/arq/querybuilder/WhereBuilder.html#addWhereValueVars(java.util.Map) > >>>> > >>>> > >>>> On 25.11.24 01:02, David Habgood wrote: > >>>>> Hi Martynas, > >>>>> > >>>>> Do you know ahead of time which variable(s) you're going to be injecting > >>>>> the VALUES clause for? > >>>>> > >>>>> I've been using a pattern where I add VALUES ?this { UNDEF } in > >>>>> "template" > >>>>> queries, then at runtime parse the query and replace "UNDEF" (where all > >>>>> of > >>>>> the DataBlockValue > >>>>> <https://www.w3.org/TR/sparql11-query/#rDataBlockValue>s > >>>>> in a binding within a InlineDataFull are "UNDEF") with a set of bindings > >>>>> supplied at runtime. This has the benefit that if you do not supply a > >>>>> binding for ?this, UNDEF means it is left unbound. > >>>>> > >>>>> Thanks, > >>>>> > >>>>> On Mon, Nov 25, 2024 at 9:40 AM Martynas Jusevičius > >>>>> <marty...@atomgraph.com> > >>>>> wrote: > >>>>> > >>>>>> Hi, > >>>>>> > >>>>>> What would be the simplest way to safely (i.e. using query builder or > >>>>>> algebra) to inject a VALUES block at the beginning of a query? > >>>>>> > >>>>>> For example > >>>>>> > >>>>>> SELECT * > >>>>>> { > >>>>>> ?this ?p ?o > >>>>>> } > >>>>>> > >>>>>> should become > >>>>>> > >>>>>> SELECT * > >>>>>> { > >>>>>> VALUES ?this <http://localhost> > >>>>>> ?this ?p ?o > >>>>>> } > >>>>>> > >>>>>> after the injection. > >>>>>> > >>>>>> Thanks, > >>>>>> > >>>>>> Martynas > >>>>>> > >>>> -- > >>>> Lorenz Bühmann > >>>> Research Associate/Scientific Developer > >>>> > >>>> Email buehm...@infai.org > >>>> > >>>> Institute for Applied Informatics e.V. (InfAI) | Goerdelerring 9 | 04109 > >>>> Leipzig | Germany > >>>> > >> >