Page MenuHomePhabricator

NotMaterializedException (Vocab(2):<various>) on combination of subquery, limit, triple, and label service
Closed, ResolvedPublic

Description

SELECT ?person ?personLabel WHERE {
  {
    SELECT ?person WHERE {
      BIND(wd:Q23 AS ?person).
      ?person wdt:P31 wd:Q5.
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    }
    LIMIT 1
  }
}

Query link

Caused by: com.bigdata.rdf.internal.NotMaterializedException: Vocab(2):XSDUnsignedByte(23)
at com.bigdata.rdf.internal.impl.AbstractIV.getValue(AbstractIV.java:993)
at com.bigdata.rdf.sail.Bigdata2Sesame2BindingSetIterator.getBindingSet(Bigdata2Sesame2BindingSetIterator.java:298)
at com.bigdata.rdf.sail.Bigdata2Sesame2BindingSetIterator.hasNext(Bigdata2Sesame2BindingSetIterator.java:140)
... 11 more

Some similar queries have an XSDUnsignedInt instead of the XSDUnsignedByte in the error message.

Removing pretty much anything from the query above – any of the selected variables in either query, the limit, the subquery, the ?person wdt:P31 wd:Q5. triple, the label service – makes the error disappear, so some very strange combination of factors seems to be happening here. The only exception is the BIND() form, which is merely an optimization – without it, the query will take a while before it produces the same error.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

This query doesn't look right. It should be:

SELECT ?person ?personLabel WHERE {
  {
    SELECT ?person WHERE {
      BIND(wd:Q23 AS ?person).
      ?person wdt:P31 wd:Q5.
    }
    LIMIT 1
  }
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

instead. If you need label outside subquery, service should be outside too. In this form it works just fine.

Hrm, perhaps I over-reduced it. In the original query, I of course select ?personLabel in the inner query as well – I only noticed that it wasn’t necessary to get the error message, so I threw it out.

But anyways, the only reason I’m bothering with a subquery is so that I get the labels in a proper materialized form that I can use in expressions. Usually, variables from the label service can’t be used in, for example, SELECT (?xLabel AS ?foo) or SELECT (CONCAT("«", ?xLabel, "»") AS ?bar). That’s why I need the label service inside the subquery, so that in the outer query there are no such problems anymore.

Can you provide the original query?

Alright, sure, I’m going to publish it anyways :D

# People who received awards from two separate countries
# blocked by https://phabricator.wikimedia.org/T147577
SELECT
?person ?personLabel
(CONCAT(?award1Label, " (", ?country1Label, ")") AS ?award1)
(CONCAT(?award2Label, " (", ?country2Label, ")") AS ?award2)
WHERE {
  {
    SELECT ?person ?personLabel ?award1Label ?country1Label ?award2Label ?country2Label WHERE {
      ?person wdt:P31 wd:Q5;
              wdt:P166 ?award1, ?award2.
      FILTER(?award1 != ?award2).
      ?award1 wdt:P17 ?country1.
      ?award2 wdt:P17 ?country2.
      FILTER(?country1 != ?country2).
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    }
    LIMIT 25
  }
}

Query link

In this case, if you move the SERVICE outside (Query link), you get a NotMaterializedException with a TermId(…) instead of an XSDUnsignedSomething(…).

Yes, looks like a bug. Even funnier, projecting both ?person and ?personLabel does not work, but each of them alone work. Something is going on there, filed https://jira.blazegraph.com/browse/BLZG-2098

Smalyshev triaged this task as Medium priority.Oct 7 2016, 12:19 AM
Smalyshev moved this task from Incoming to Blazegraph on the Wikidata-Query-Service board.

Workaround: add this to query:

hint:Query hint:analytic "false" .
Smalyshev claimed this task.

Fixed in BG 2.1.5

This does not seem fully fixed yet: https://www.wikidata.org/wiki/Wikidata_talk:SPARQL_query_service#Possible_bug. Example from that post:

SELECT ?item ?itemLabel ?linkTo {
  ?item wdt:P780/wdt:P31*/wdt:P279* wd:Q737460, wd:Q86, wd:Q21120251.
  SERVICE wikibase:label {bd:serviceParam wikibase:language "en" }
}

This has the same behaviour, it is fixed by the workaround and also projecting just item or itemLabel works fine. Upstream bug also has some reports of issues still.

Well, that query is pretty different from the one in the task description (no subquery, no limit), so I’d file it as a separate bug.