From: <tho...@us...> - 2014-01-23 11:34:06
|
Revision: 7819 http://bigdata.svn.sourceforge.net/bigdata/?rev=7819&view=rev Author: thompsonbry Date: 2014-01-23 11:33:50 +0000 (Thu, 23 Jan 2014) Log Message: ----------- Added unit tests for #801 (Adding optional removes solutions). Modified Paths: -------------- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestSubQuery.java Added Paths: ----------- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/test_ticket_801_complex_optionals.nt branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/test_ticket_801_complex_optionals.srx branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/test_ticket_801a_complex_optionals.rq branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/test_ticket_801b_complex_optionals.rq Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestSubQuery.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestSubQuery.java 2014-01-23 00:11:09 UTC (rev 7818) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestSubQuery.java 2014-01-23 11:33:50 UTC (rev 7819) @@ -29,9 +29,11 @@ import org.openrdf.model.Value; +import com.bigdata.BigdataStatics; import com.bigdata.bop.BOpUtility; import com.bigdata.rdf.sparql.ast.NamedSubqueryRoot; import com.bigdata.rdf.sparql.ast.QueryHints; +import com.bigdata.rdf.sparql.ast.optimizers.ASTComplexOptionalOptimizer; import com.bigdata.rdf.sparql.ast.optimizers.ASTSparql11SubqueryOptimizer; import com.bigdata.rdf.sparql.ast.optimizers.TestASTSparql11SubqueryOptimizer; @@ -298,4 +300,113 @@ } + /** + * This ticket is for a bug when the {@link ASTComplexOptionalOptimizer} + * runs. If that optimizer is disabled, then the query is fine. There are + * two versions for this method. One in which one of the OPTIONALs is turned + * into a required join. In this case, the problem is not demonstrated since + * the {@link ASTComplexOptionalOptimizer} does not run. In the other case, + * the join group is OPTIONAL rather than required and the problem is + * demonstrated. + * + * <pre> + * select ?name + * { + * { + * select ?p + * { + * ?p a <http://www.example.org/schema/Person> . + * optional{?p <http://www.example.org/schema/age> ?age.} + * } + * LIMIT 1 + * } + * + * {?p <http://www.example.org/schema/name> ?name.} + * + * #OPTIONAL + * { ?post a <http://www.example.org/schema/Post> . + * ?post <http://www.example.org/schema/postedBy> ?p. + * ?post <http://www.example.org/schema/content> ?postContent. + * } + * OPTIONAL{ + * ?comment a <http://www.example.org/schema/Comment> . + * ?comment <http://www.example.org/schema/parentPost> ?post. + * ?cperson a <http://www.example.org/schema/Person> . + * ?comment <http://www.example.org/schema/postedBy> ?cperson . + * } + * } + * </pre> + * + * @see <a href="https://sourceforge.net/apps/trac/bigdata/ticket/801" > + * Adding OPTIONAL removes solutions</a> + */ + public void test_ticket_801a_complex_optionals() throws Exception { + + final TestHelper h = new TestHelper( + "test_ticket_801a_complex_optionals", // testURI, + "test_ticket_801a_complex_optionals.rq",// queryFileURL + "test_ticket_801_complex_optionals.nt",// dataFileURL + "test_ticket_801_complex_optionals.srx"// resultFileURL + ); + + // Run test. + h.runTest(); + + } + + /** + * In this variant, one of the child join groups is OPTIONAL rather than + * required. This shows the problem reported in the ticket where adding an + * OPTIONAL join group reduces the number of solutions. + * + * <pre> + * select ?name + * { + * { + * select ?p + * { + * ?p a <http://www.example.org/schema/Person> . + * optional{?p <http://www.example.org/schema/age> ?age.} + * } + * LIMIT 1 + * } + * + * {?p <http://www.example.org/schema/name> ?name.} + * + * OPTIONAL + * { ?post a <http://www.example.org/schema/Post> . + * ?post <http://www.example.org/schema/postedBy> ?p. + * ?post <http://www.example.org/schema/content> ?postContent. + * } + * OPTIONAL{ + * ?comment a <http://www.example.org/schema/Comment> . + * ?comment <http://www.example.org/schema/parentPost> ?post. + * ?cperson a <http://www.example.org/schema/Person> . + * ?comment <http://www.example.org/schema/postedBy> ?cperson . + * } + * } + * </pre> + */ + public void test_ticket_801b_complex_optionals() throws Exception { + + if (!BigdataStatics.runKnownBadTests) { + /* + * FIXME Add this test to CI once we make some more progress + * against the underlying issue. + */ + return; + } + + final TestHelper h = new TestHelper( + "test_ticket_801b_complex_optionals", // testURI, + "test_ticket_801b_complex_optionals.rq",// queryFileURL + "test_ticket_801_complex_optionals.nt",// dataFileURL + "test_ticket_801_complex_optionals.srx"// resultFileURL + ); + + // Run test. + h.runTest(); + + } + } Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/test_ticket_801_complex_optionals.nt =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/test_ticket_801_complex_optionals.nt (rev 0) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/test_ticket_801_complex_optionals.nt 2014-01-23 11:33:50 UTC (rev 7819) @@ -0,0 +1,35 @@ +<http://www.example.com/person1> <http://www.example.org/schema/age> "39"^^<http://www.w3.org/2001/XMLSchema#integer> . +<http://www.example.com/person1> <http://www.example.org/schema/name> "Person #1"^^<http://www.w3.org/2001/XMLSchema#string> . +<http://www.example.com/person1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.org/schema/Person> . + +<http://www.example.com/person2> <http://www.example.org/schema/age> "29"^^<http://www.w3.org/2001/XMLSchema#integer> . +<http://www.example.com/person2> <http://www.example.org/schema/name> "Person #2"^^<http://www.w3.org/2001/XMLSchema#string> . +<http://www.example.com/person2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.org/schema/Person> . + +<http://www.example.com/person3> <http://www.example.org/schema/age> "19"^^<http://www.w3.org/2001/XMLSchema#integer> . +<http://www.example.com/person3> <http://www.example.org/schema/name> "Person #3"^^<http://www.w3.org/2001/XMLSchema#string> . +<http://www.example.com/person3> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.org/schema/Person> . + +<http://www.example.com/post1> <http://www.example.org/schema/content> "Post 1 content"^^<http://www.w3.org/2001/XMLSchema#string> . +<http://www.example.com/post1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.org/schema/Post> . +<http://www.example.com/post1> <http://www.example.org/schema/postedBy> <http://www.example.com/person1>. + +<http://www.example.com/post2> <http://www.example.org/schema/content> "Post 2 content"^^<http://www.w3.org/2001/XMLSchema#string> . +<http://www.example.com/post2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.org/schema/Post> . +<http://www.example.com/post2> <http://www.example.org/schema/postedBy> <http://www.example.com/person1>. + +<http://www.example.com/comment1> <http://www.example.org/schema/content> "Comment 1 content"^^<http://www.w3.org/2001/XMLSchema#string> . +<http://www.example.com/comment1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.org/schema/Comment> . +<http://www.example.com/comment1> <http://www.example.org/schema/parentPost> <http://www.example.com/post1> . +<http://www.example.com/comment1> <http://www.example.org/schema/postedBy> <http://www.example.com/person2>. + +<http://www.example.com/comment2> <http://www.example.org/schema/content> "Comment 2 content"^^<http://www.w3.org/2001/XMLSchema#string> . +<http://www.example.com/comment2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.org/schema/Comment> . +<http://www.example.com/comment2> <http://www.example.org/schema/parentPost> <http://www.example.com/post1> . +<http://www.example.com/comment2> <http://www.example.org/schema/postedBy> <http://www.example.com/person3>. + + + + + + Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/test_ticket_801_complex_optionals.srx =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/test_ticket_801_complex_optionals.srx (rev 0) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/test_ticket_801_complex_optionals.srx 2014-01-23 11:33:50 UTC (rev 7819) @@ -0,0 +1,26 @@ +<?xml version="1.0"?> +<sparql + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:xs="http://www.w3.org/2001/XMLSchema#" + xmlns="http://www.w3.org/2005/sparql-results#" > + <head> + <variable name="name"/> + </head> + <results> + <result> + <binding name="name"> + <literal datatype="http://www.w3.org/2001/XMLSchema#string">Person #1</literal> + </binding> + </result> + <result> + <binding name="name"> + <literal datatype="http://www.w3.org/2001/XMLSchema#string">Person #1</literal> + </binding> + </result> + <result> + <binding name="name"> + <literal datatype="http://www.w3.org/2001/XMLSchema#string">Person #1</literal> + </binding> + </result> + </results> +</sparql> Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/test_ticket_801a_complex_optionals.rq =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/test_ticket_801a_complex_optionals.rq (rev 0) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/test_ticket_801a_complex_optionals.rq 2014-01-23 11:33:50 UTC (rev 7819) @@ -0,0 +1,27 @@ +# See #801 (Adding OPTIONAL removes solutions) +# +select ?name +{ + { + select ?p + { + ?p a <http://www.example.org/schema/Person> . + optional{?p <http://www.example.org/schema/age> ?age.} + } + LIMIT 1 + } + + {?p <http://www.example.org/schema/name> ?name.} + + #OPTIONAL + { ?post a <http://www.example.org/schema/Post> . + ?post <http://www.example.org/schema/postedBy> ?p. + ?post <http://www.example.org/schema/content> ?postContent. + } + OPTIONAL{ + ?comment a <http://www.example.org/schema/Comment> . + ?comment <http://www.example.org/schema/parentPost> ?post. + ?cperson a <http://www.example.org/schema/Person> . + ?comment <http://www.example.org/schema/postedBy> ?cperson . + } +} \ No newline at end of file Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/test_ticket_801b_complex_optionals.rq =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/test_ticket_801b_complex_optionals.rq (rev 0) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/test_ticket_801b_complex_optionals.rq 2014-01-23 11:33:50 UTC (rev 7819) @@ -0,0 +1,27 @@ +# See #801 (Adding OPTIONAL removes solutions) +# +select ?name +{ + { + select ?p + { + ?p a <http://www.example.org/schema/Person> . + optional{?p <http://www.example.org/schema/age> ?age.} + } + LIMIT 1 + } + + {?p <http://www.example.org/schema/name> ?name.} + + OPTIONAL + { ?post a <http://www.example.org/schema/Post> . + ?post <http://www.example.org/schema/postedBy> ?p. + ?post <http://www.example.org/schema/content> ?postContent. + } + OPTIONAL{ + ?comment a <http://www.example.org/schema/Comment> . + ?comment <http://www.example.org/schema/parentPost> ?post. + ?cperson a <http://www.example.org/schema/Person> . + ?comment <http://www.example.org/schema/postedBy> ?cperson . + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |