|
From: <tho...@us...> - 2014-01-27 21:23:44
|
Revision: 7834
http://bigdata.svn.sourceforge.net/bigdata/?rev=7834&view=rev
Author: thompsonbry
Date: 2014-01-27 21:23:38 +0000 (Mon, 27 Jan 2014)
Log Message:
-----------
Bug fix for [1]. The root cause was an incorrect AST generated from the SPARQL parser. I have added test cases for this to TestSubqueryPatterns. With this fix, the test case in TestTickets for #806 now runs correctly. The entire AST SPARQL test suite is green. Committed to CI.
See #806 (Incorrect AST generated for OPTIONAL { SELECT })
Modified Paths:
--------------
branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestTickets.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/sparql/GroupGraphPatternBuilder.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/sparql/TestGroupGraphPatternBuilder.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/sparql/TestSubqueryPatterns.java
Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestTickets.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestTickets.java 2014-01-27 16:55:56 UTC (rev 7833)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestTickets.java 2014-01-27 21:23:38 UTC (rev 7834)
@@ -320,9 +320,8 @@
}
/**
- * @see <a href="https://sourceforge.net/apps/trac/bigdata/ticket/806" >
- * Incorrect computation of shared variables when lifting out named
- * subqueries </a>
+ * @see <a href="https://sourceforge.net/apps/trac/bigdata/ticket/806>
+ * Incorrect AST generated for OPTIONAL { SELECT }</a>
*/
public void test_ticket_806() throws Exception {
Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/sparql/GroupGraphPatternBuilder.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/sparql/GroupGraphPatternBuilder.java 2014-01-27 16:55:56 UTC (rev 7833)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/java/com/bigdata/rdf/sail/sparql/GroupGraphPatternBuilder.java 2014-01-27 21:23:38 UTC (rev 7834)
@@ -273,20 +273,41 @@
graphPattern = new GroupGraphPattern(parentGP);
// visit the children.
- super.visit(node, null);
+ final Object tmp = super.visit(node, null);
final JoinGroupNode joinGroup = new JoinGroupNode();
joinGroup.setOptional(true);
-
- @SuppressWarnings("rawtypes")
- final GroupNodeBase group = graphPattern.buildGroup(joinGroup);
- parentGP.add(group);
+ if (tmp instanceof SubqueryRoot) {
+
+ /**
+ * Sub-Select
+ *
+ * @see <a
+ * href="https://sourceforge.net/apps/trac/bigdata/ticket/806>
+ * Incorrect computation of shared variables when lifting out named
+ * subqueries </a>
+ */
+ joinGroup.addChild((SubqueryRoot) tmp);
+ } else {
+
+ // GraphPattern
+
+ @SuppressWarnings("rawtypes")
+ final GroupNodeBase group = graphPattern.buildGroup(joinGroup);
+
+ assert group == joinGroup;// should be the same reference.
+
+ }
+
+ parentGP.add(joinGroup);
+
graphPattern = parentGP;
return null;
+
}
/**
Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/sparql/TestGroupGraphPatternBuilder.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/sparql/TestGroupGraphPatternBuilder.java 2014-01-27 16:55:56 UTC (rev 7833)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/sparql/TestGroupGraphPatternBuilder.java 2014-01-27 21:23:38 UTC (rev 7834)
@@ -1298,4 +1298,53 @@
}
+ /**
+ * A unit test for an OPTIONAL wrapping a SERVICE.
+ */
+ public void test_optional_SERVICE() throws MalformedQueryException,
+ TokenMgrError, ParseException {
+
+ final String serviceExpr = "service ?s { ?s ?p ?o }";
+
+ final String sparql = "select ?s where { optional { " + serviceExpr
+ + " } }";
+
+ final QueryRoot expected = new QueryRoot(QueryType.SELECT);
+ final ServiceNode service;
+ {
+
+ {
+ final Map<String, String> prefixDecls = new LinkedHashMap<String, String>();
+ expected.setPrefixDecls(prefixDecls);
+ }
+
+ {
+ final ProjectionNode projection = new ProjectionNode();
+ projection.addProjectionVar(new VarNode("s"));
+ expected.setProjection(projection);
+
+ final JoinGroupNode whereClause = new JoinGroupNode();
+ expected.setWhereClause(whereClause);
+
+ final JoinGroupNode serviceGraph = new JoinGroupNode();
+ serviceGraph.addChild(new StatementPatternNode(
+ new VarNode("s"), new VarNode("p"), new VarNode("o"),
+ null/* c */, Scope.DEFAULT_CONTEXTS));
+
+ service = new ServiceNode(new VarNode("s"), serviceGraph);
+ service.setExprImage(serviceExpr);
+
+ final JoinGroupNode wrapperGroup = new JoinGroupNode(true/* optional */);
+ whereClause.addChild(wrapperGroup);
+ wrapperGroup.addChild(service);
+ }
+
+ }
+
+ final QueryRoot actual = parse(sparql, baseURI);
+
+ assertSameAST(sparql, expected, actual);
+
+ }
+
}
Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/sparql/TestSubqueryPatterns.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/sparql/TestSubqueryPatterns.java 2014-01-27 16:55:56 UTC (rev 7833)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/sparql/TestSubqueryPatterns.java 2014-01-27 21:23:38 UTC (rev 7834)
@@ -146,6 +146,71 @@
}
/**
+ * Unit test for simple optional subquery without anything else in the outer
+ * join group.
+ *
+ * <pre>
+ * SELECT ?s where { OPTIONAL {SELECT ?s where {?s ?p ?o}}}
+ * </pre>
+ *
+ * Note: This requires recursion back in through the
+ * {@link BigdataExprBuilder}.
+ *
+ * @see <a href="https://sourceforge.net/apps/trac/bigdata/ticket/806>
+ * Incorrect AST generated for OPTIONAL { SELECT }</a>
+ */
+ public void test_optional_subSelect() throws MalformedQueryException,
+ TokenMgrError, ParseException {
+
+ final String sparql = "select ?s where { optional {select ?s where { ?s ?p ?o } } }";
+
+ final QueryRoot expected = new QueryRoot(QueryType.SELECT);
+ final SubqueryRoot subSelect;
+ {
+
+ {
+ final Map<String, String> prefixDecls = new LinkedHashMap<String, String>();
+ expected.setPrefixDecls(prefixDecls);
+ }
+
+ {
+ final ProjectionNode projection = new ProjectionNode();
+ projection.addProjectionVar(new VarNode("s"));
+ expected.setProjection(projection);
+
+ final JoinGroupNode whereClause = new JoinGroupNode();
+ expected.setWhereClause(whereClause);
+
+ subSelect = new SubqueryRoot(QueryType.SELECT);
+// whereClause.addChild(subSelect);
+
+ final JoinGroupNode wrapperGroup = new JoinGroupNode(true/* optional */);
+ whereClause.addChild(wrapperGroup);
+ wrapperGroup.addChild(subSelect);
+ }
+ {
+
+ final ProjectionNode projection2 = new ProjectionNode();
+ projection2.addProjectionVar(new VarNode("s"));
+ subSelect.setProjection(projection2);
+
+ final JoinGroupNode whereClause2 = new JoinGroupNode();
+ subSelect.setWhereClause(whereClause2);
+
+ whereClause2.addChild(new StatementPatternNode(
+ new VarNode("s"), new VarNode("p"), new VarNode("o"),
+ null/* c */, Scope.DEFAULT_CONTEXTS));
+
+ }
+ }
+
+ final QueryRoot actual = parse(sparql, baseURI);
+
+ assertSameAST(sparql, expected, actual);
+
+ }
+
+ /**
* Unit test for simple subquery joined with a triple pattern in the outer
* join group.
*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|