Page MenuHomePhabricator

MWAPI service throws “could not find binding for parameter” if optimizer is not disabled
Closed, ResolvedPublic


The following query:

# trying to use mwapi to get (license) categories of commons images
# see
  BIND(wd:Q668563 as ?leinestr) # random item with picture
  ?leinestr wdt:P18 ?picture.

  BIND(STRAFTER(str(?picture), "Special:FilePath/") AS ?filename)
  BIND(CONCAT("File:", wikibase:decodeUri(?filename)) AS ?file)

  SERVICE wikibase:mwapi {
    bd:serviceParam wikibase:api "Categories".
    bd:serviceParam wikibase:endpoint "".
    bd:serviceParam mwapi:titles ?file. # throws IllegalArgumentException: Could not find binding for parameter titles
    ?cat wikibase:apiOutput mwapi:category.

results in the following error:

Caused by: java.lang.IllegalArgumentException: Could not find binding for parameter titles
at org.wikidata.query.rdf.blazegraph.mwapi.MWApiServiceCall.getRequestParams(
at org.wikidata.query.rdf.blazegraph.mwapi.MWApiServiceCall.getHttpRequest(
at org.wikidata.query.rdf.blazegraph.mwapi.MWApiServiceCall.access$000(
at org.wikidata.query.rdf.blazegraph.mwapi.MWApiServiceCall$MultiSearchIterator.doSearchFromBinding(
at org.wikidata.query.rdf.blazegraph.mwapi.MWApiServiceCall$MultiSearchIterator.doNextSearch(
at org.wikidata.query.rdf.blazegraph.mwapi.MWApiServiceCall$MultiSearchIterator.<init>(
at com.bigdata.bop.controller.ServiceCallJoin$ChunkTask$ServiceCallTask.doBigdataServiceCall(

If the optimizer is disabled via query hint, the query works (though it finds no results, but that’s another topic: T168877), so it looks like the optimizer reorders the query in such a way that the service doesn’t have access to the ?file binding.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Smalyshev triaged this task as Medium priority.Jun 26 2017, 5:44 PM

This is the result of query being reordered, but I'm not sure why - input parameters should be bound by the time SERVICE is run. I'll check why it doesn't happen and see what can be done.

Looking at the binding set incoming to service, I see:

{ leinestr=Vocab(2)[]:XSDUnsignedInt(668563), picture=TermId(1U)[], filename=TermId(0L)[U-Bahn%20Berlin%20Leinestra%C3%9Fe.JPG] }

So the order is right (since other vars are bound) but somehow ?file is missing from bindings. I wonder is Optimizer somehow drops it and whether I should tell it somehow not to do it.

Looks like Optimizer for some reason puts the second BIND after the service. Not sure why. Workaround for this one would be:

hint:Prior hint:runLast true .

after the service, but this of course is just a workaround, not a fix.

Change 533116 had a related patch set uploaded (by Igor Kim; owner: Igor Kim):
[wikidata/query/rdf@master] Fix “could not find binding for parameter” in MWAPI

Change 533116 merged by jenkins-bot:
[wikidata/query/rdf@master] Fix “could not find binding for parameter” in MWAPI

debt claimed this task.