The Open Anzo Project

Semantic Application Middleware

Ticket #316 (closed defect: fixed)

Opened 8 months ago

Last modified 8 months ago

Incorrect handling of OPTIONAL when in query with textmatch functional predicate

Reported by: jpbetz Assigned to: jpbetz
Priority: minor Milestone: 3.0 milestone2
Component: openanzo-glitter Version: 3.0
Keywords: dataset Cc: rmeschian, lee, mroy, jpbetz

Description (Last modified by jpbetz)

The query:

SELECT DISTINCT ?value
WHERE {
  OPTIONAL { ?value <http://xmlns.com/foaf/0.1/givenname> ?givenname } .
  ?value ?p ?txt .
  ?txt <http://openanzo.org/predicates/textmatch> 'john' .
}

does not run correctly against the dataset:

:graph1 {
 :s dc:title 'john' .
}
:graph2 {
 :s2 foaf:givenname 'jane' .
}

Rather than correctly returning:

?value -> :s

no results are returned. This appears to only happen if the statement in graph2 has the same predicate used in the OPTIONAL.

Change History

05/03/08 19:46:55 changed by jpbetz

  • summary changed from allNamedGraph corruptable by update when used in datasets' defaultNamedGraphs to allNamedGraph corruptable by update when used in datasets' defaultGraphs.

05/03/08 22:09:45 changed by jpbetz

  • description changed.

05/03/08 23:38:29 changed by jpbetz

  • description changed.
  • summary changed from allNamedGraph corruptable by update when used in datasets' defaultGraphs to Incorrect handling of OPTIONAL when in query with textmatch functional predicate.

05/03/08 23:39:55 changed by jpbetz

  • component changed from anzo to anzo-glitter.
  • description changed.

05/03/08 23:41:12 changed by jpbetz

(In [2214]) re #316 reviewer: lee

Add unit test to replicate defect.

05/04/08 01:10:18 changed by jpbetz

  • priority changed from critical to minor.

This issue not occur when the OPTIONAL is below the mandatory triple patterns:

SELECT DISTINCT ?value
WHERE {
  ?value ?p ?txt .
  ?txt <http://openanzo.org/predicates/textmatch> 'john' .
  OPTIONAL { ?value <http://xmlns.com/foaf/0.1/givenname> ?givenname } .
}

correctly returns: ?value -> :s for the dataset containing graph2.

But if the OPTIONAL is above, as in the initial report of this defect, the Glitter AST rewriter do not put the mandatory triple patterns in the OPTIONAL's nodes 'must' child, node, instead the AST looks like:

Group(
  Optional(
    null,
    Group(BGP(TriplePatternNode(?value <http://xmlns.com/foaf/0.1/givenname> ?obj)))),
  BGP(
    TriplePatternNode(?txt <http://openanzo.org/predicates/textmatch> "union"),
    TriplePatternNode(?value ?p ?txt))
)

Where null is the 'must' child of the optional and the mandatory triple patterns are in a separate BGP that will be joined with the results of the optional.

From the SPARQL specification it is unclear to me if this is correct or not. In the spec. example all OPTIONALs appear below mandatory triple patterns, but I do not see any statements in the text restricting order.

I do not see anything in the grammer (looking mostly at 'GraphPatternNotTriples?') that infers meaning from order.

Lee, am I correct asserting that this is a defect?

Rouben, lowering priority to minor since OPTIONAL ordering can be used to avoid issue.

05/04/08 01:29:57 changed by jpbetz

Wow, I must be really tired. Clearly there is a bug since the handling of the query is inconsistent. That query should do the same thing regardless of the presence of graph2.

I'll fix the rewriters to put all mandatory triple patterns in the 'must' child node of the OPTIONALs node.

05/04/08 01:59:25 changed by jpbetz

Okay, now I'm really confused. When attempting to add this query and it's AST to the TestQueryAndAstStrings I get an WellDesignedOptionalsValidator error on the query if the OPTIONALs are at the top. Why don't I get this error when running the same query from an AnzoClient??

05/04/08 11:23:51 changed by jpbetz

WellDesignedOptionalsValidator was disabled in r254, but is still enabled in MockEngineConfig and others. This should be fixed.

The parser requires OPTIONALs be below mandatory triple patterns to work correctly. Currently, it looks like if this is no done that behavior is largely undefined.

In the parser Group.replaceCurrentContentsWithOptional properly organizes an OPTIONAL with all prior graph patterns in the group. Nothing is done to incorporate later graph patterns into the optional. While this strategy seems to work okay for triple patterns (and maybe others) it doesn't work for the textmatch functional predicate.

05/04/08 12:13:40 changed by lee

SPARQL does specifically group triple patterns before the OPTIONAL as the must part of the OPTIONAL. The must part of the OPTIONAL is (itself) optional. So the parsing behavior is correct. Will look into the meat of the bug now.

05/04/08 13:12:08 changed by jpbetz

05/05/08 18:44:53 changed by lee

  • cc changed from rmeschian lee mroy to rmeschian, lee, mroy, jpbetz.
  • owner changed from jpbetz to lee.

The proper behavior here is actually to have no results.

OPTIONAL { TP1 } 

is equivalent to:

  • TP1 if there is at least one solution to TP1
  • {} if there are no solutions to TP1

There is a bug in the Anzo solution generator that handles this incorrectly. I will look at this bug and check in tests for both the correct and buggy cases (now) and a fix for the buggy cases.

05/05/08 19:33:10 changed by lee

(In [2226]) tests and fixes algebra bug surrounding an OPTIONAL with no required part, particularly when the OPTIONAL is the first item in a Group.

(re #316)

05/05/08 19:33:17 changed by lee

(In [2227]) tests and fixes algebra bug surrounding an OPTIONAL with no required part, particularly when the OPTIONAL is the first item in a Group.

(re #316)

05/05/08 19:36:48 changed by lee

  • owner changed from lee to jpbetz.

Joe, please review the tests & (one line) fix and close.

Others: note the clarification & resolution here: OPTIONALs in SPARQL are order dependent.

reviewer: jpbetz

05/05/08 19:36:51 changed by lee

(In [2228]) remove redundant test in TestQueries? that was replaced by tests in [2227]

(re #316)

05/05/08 20:49:23 changed by jpbetz

  • status changed from new to closed.
  • resolution set to fixed.

Nice! I'm very happy to see this solved.

Thanks!

Copyright © 2007 - 2008 OpenAnzo.org