From: <jer...@us...> - 2014-01-07 22:10:41
|
Revision: 7746 http://bigdata.svn.sourceforge.net/bigdata/?rev=7746&view=rev Author: jeremy_carroll Date: 2014-01-07 22:10:34 +0000 (Tue, 07 Jan 2014) Log Message: ----------- Added tests (both runtime and static optimizer) for trac 794 to do with SERVICE and BIND Also modified comment in ASTJoinOrderByTypeOptimizer which is doing the wrong thing. Tests currently disabled since the fix is not yet in. (Note the fix is non-trivial, but not conceptually hard either) Modified Paths: -------------- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/optimizers/ASTBindingAssigner.java branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/optimizers/ASTJoinOrderByTypeOptimizer.java branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/optimizers/AbstractOptimizerTestCase.java branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/AbstractProtocolTest.java branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestNanoSparqlServerWithProxyIndexManager.java Added Paths: ----------- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/optimizers/TestASTMassagedServiceNodeOptimizer.java branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestService794.java Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/optimizers/ASTBindingAssigner.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/optimizers/ASTBindingAssigner.java 2014-01-07 18:34:06 UTC (rev 7745) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/optimizers/ASTBindingAssigner.java 2014-01-07 22:10:34 UTC (rev 7746) @@ -73,7 +73,7 @@ public IQueryNode optimize(final AST2BOpContext context, final IQueryNode queryNode, final IBindingSet[] bindingSet) { - if (bindingSet == null || bindingSet.length > 1) { + if (bindingSet == null || bindingSet.length != 1) { /* * Used iff there is only one input solution. * Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/optimizers/ASTJoinOrderByTypeOptimizer.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/optimizers/ASTJoinOrderByTypeOptimizer.java 2014-01-07 18:34:06 UTC (rev 7745) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/optimizers/ASTJoinOrderByTypeOptimizer.java 2014-01-07 22:10:34 UTC (rev 7746) @@ -183,17 +183,20 @@ * * Required joins: * - * 3. Service calls (Bigdata SEARCH) + * 3. Some Service calls (e.g. Bigdata SEARCH) * 4. Subquery-includes * 5. Statement patterns * 7. Sparql11 subqueries * 8. Non-optional subgroups + * 9. Other service calls * + * TODO: the placement of OPTIONALS should really be more complicated than this. + * e.g. consider interaction with SERVICE calls etc. * Optional joins: - * 9. Simple optionals & optional subgroups + * 10. Simple optionals & optional subgroups * - * 10. Assignments - * 11. Post-conditionals + * 11. Assignments + * 12. Post-conditionals * </pre> * Most of this logic was lifted out of {@link AST2BOpUtility}. * <p> Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/optimizers/AbstractOptimizerTestCase.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/optimizers/AbstractOptimizerTestCase.java 2014-01-07 18:34:06 UTC (rev 7745) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/optimizers/AbstractOptimizerTestCase.java 2014-01-07 22:10:34 UTC (rev 7746) @@ -64,6 +64,7 @@ import com.bigdata.rdf.sparql.ast.UnionNode; import com.bigdata.rdf.sparql.ast.VarNode; import com.bigdata.rdf.sparql.ast.eval.AST2BOpContext; +import com.bigdata.rdf.sparql.ast.service.ServiceNode; public abstract class AbstractOptimizerTestCase extends AbstractASTEvaluationTestCase { @@ -426,6 +427,18 @@ protected FilterNode filter(IValueExpressionNode f) { return new FilterNode(f); } + + protected IValueExpressionNode functionNode(String uri, ValueExpressionNode ... args) { + return new FunctionNode(new URIImpl(uri), null, args); + } + + protected ServiceNode service(TermNode serviceRef, GraphPatternGroup<IGroupMemberNode> groupNode) { + return new ServiceNode(serviceRef, groupNode); + } + + protected AssignmentNode bind(IValueExpressionNode valueNode, VarNode varNode) { + return new AssignmentNode(varNode, valueNode); + } } public AbstractOptimizerTestCase(String name) { Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/optimizers/TestASTMassagedServiceNodeOptimizer.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/optimizers/TestASTMassagedServiceNodeOptimizer.java (rev 0) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/optimizers/TestASTMassagedServiceNodeOptimizer.java 2014-01-07 22:10:34 UTC (rev 7746) @@ -0,0 +1,104 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2014. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/** + * Trac 794 concerns interactions between BIND and SERVICE going to a remote + * SPARQL end-point. The service call must be done last. + */ +package com.bigdata.rdf.sparql.ast.optimizers; + + + + +public class TestASTMassagedServiceNodeOptimizer extends AbstractOptimizerTestCase { + + public TestASTMassagedServiceNodeOptimizer(String name) { + super(name); + } + + public TestASTMassagedServiceNodeOptimizer() { + } + @Override + IASTOptimizer newOptimizer() { + return new ASTJoinOrderByTypeOptimizer(); + } + + public void testLeaveBindBeforeService() { + + new Helper(){{ + + given = select( varNode(z), + where ( + joinGroupNode( + statementPatternNode(varNode(x), constantNode(c), constantNode(d)), + bind(functionNode("eg:foo", varNode(x)), varNode(y) ), + service( constantNode(a), + joinGroupNode( statementPatternNode(varNode(z), constantNode(f), varNode(y)) ) ) + ) + ) ); + + + expected = select( varNode(z), + where ( + joinGroupNode( + statementPatternNode(varNode(x), constantNode(c), constantNode(d)), + bind(functionNode("eg:foo", varNode(x)), varNode(y) ), + service( constantNode(a), + joinGroupNode( statementPatternNode(varNode(z), constantNode(f), varNode(y)) ) ) + ) + ) ); + + + }}.test(); + } + public void testPutBindBeforeService() { + + new Helper(){{ + + given = select( varNode(z), + where ( + joinGroupNode( + service( constantNode(a), + joinGroupNode( statementPatternNode(varNode(z), constantNode(f), varNode(y)) ) ), + statementPatternNode(varNode(x), constantNode(c), constantNode(d)), + bind(functionNode("eg:foo", varNode(x)), varNode(y) ) + ) + ) ); + + + expected = select( varNode(z), + where ( + joinGroupNode( + statementPatternNode(varNode(x), constantNode(c), constantNode(d)), + bind(functionNode("eg:foo", varNode(x)), varNode(y) ), + service( constantNode(a), + joinGroupNode( statementPatternNode(varNode(z), constantNode(f), varNode(y)) ) ) + ) + ) ); + + + }}.test(); + } + +} Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/AbstractProtocolTest.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/AbstractProtocolTest.java 2014-01-07 18:34:06 UTC (rev 7745) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/AbstractProtocolTest.java 2014-01-07 22:10:34 UTC (rev 7746) @@ -114,6 +114,10 @@ }; private RequestFactory requestFactory = GET; + + protected RequestFactory getRequestFactory() { + return requestFactory; + } @Override public void setUp() throws Exception { super.setUp(); Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestNanoSparqlServerWithProxyIndexManager.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestNanoSparqlServerWithProxyIndexManager.java 2014-01-07 18:34:06 UTC (rev 7745) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestNanoSparqlServerWithProxyIndexManager.java 2014-01-07 22:10:34 UTC (rev 7746) @@ -233,6 +233,8 @@ suite.addTestSuite(TestInsertFilterFalse727.class); suite.addTestSuite(TestCBD731.class); + suite.addTestSuite(TestService794.class); + // SPARQL UPDATE test suite. switch(testMode) { Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestService794.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestService794.java (rev 0) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/webapp/TestService794.java 2014-01-07 22:10:34 UTC (rev 7746) @@ -0,0 +1,180 @@ +/** +Copyright (C) SYSTAP, LLC 2014. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package com.bigdata.rdf.sail.webapp; + +import java.io.IOException; + +import junit.framework.Test; + + +/** + * While writing this comment, early January 2014, + * the status is that the two interesting tests + * both fail and are disabled + * {@link #xtestMassageServiceCall()} and {@link #xtestMassageServiceNested1Call()} + * + * Also {@link #xtestServiceSyntaxError()} shows some bug some where in that + * we take legal SPARQL and make it illegal before the service call .... + * + * Some of the other tests show how to use a subselect as a workaround. + * @author jeremycarroll + * + */ +public class TestService794 extends AbstractProtocolTest { + + public TestService794(String name) { + super(name); + } + + + static public Test suite() { + return ProxySuiteHelper.suiteWhenStandalone(TestService794.class,"test.*", + TestMode.quads,TestMode.sids, + TestMode.triples); + } + + /** + * Execute an ASK query including a SERVICE keyword which gets sent back to this server. + * The test succeeeds if the query returns true, and fails otherwise + * @param args + * @throws IOException + */ + private void abstactAskService(String ... args) throws IOException { + + setMethodisPostUrlEncodedData(); + serviceRequest("update","PREFIX eg: <http://example.com/a#> INSERT { eg:a eg:p \"rs123\" ; eg:q 123, 100 } WHERE {}"); + + StringBuilder bld = new StringBuilder(); + // Set the base URI to be our sparql end point, for re-entrant queries, + // using the idiom SERVICE <> + bld.append("base <"); + bld.append(m_serviceURL); + bld.append("/sparql>"); + for (String arg:args) { + bld.append('\n'); + bld.append(arg); + } + + System.err.println(bld.toString()); + String result = serviceRequest("query",bld.toString()); + System.err.println(result); + assertTrue(result.contains("true")); + + } + + /** + * @throws IOException + */ + public void testSimpleServiceCall() throws IOException { + abstactAskService("PREFIX eg: <http://example.com/a#>", + "ASK {", + "?x eg:p ?y ", + " SERVICE <> {", + " FILTER ( true )", + "{ SELECT ?x ?y {", + "?x eg:p ?y ", + "} ORDER BY ?y LIMIT 1 }", + "} }"); + } + + /** + * This one is currently broken, see trac794 + * + * Note also there is something unintersting with syntax + * going wrong with some expressions like + * SERVICE <> { + * { SELECT * { + * ?x eg:q ?y + * } + * } + * } + */ + public void xtestMassageServiceCall() throws IOException { + abstactAskService("PREFIX eg: <http://example.com/a#>", + "prefix xsd: <http://www.w3.org/2001/XMLSchema#>", + "ASK {", + "?x eg:p ?y ", + "BIND (xsd:integer(substr(?y,3)) as ?yy )", + " SERVICE <> {", + " FILTER (true )", + "{ SELECT ?x ?yy {", + "?x eg:q ?yy ", + "} ORDER BY ?yy LIMIT 1 }", + "} }"); + } + /** + * @throws IOException + */ + public void xtestMassageServiceNested1Call() throws IOException { + abstactAskService("PREFIX eg: <http://example.com/a#>", + "prefix xsd: <http://www.w3.org/2001/XMLSchema#>", + "ASK {", + "{ ?x eg:p ?y ", + "BIND (xsd:integer(substr(?y,3)) as ?yy ) }", + " SERVICE <> {", + "{ SELECT ?x ?yy {", + "?x eg:q ?yy ", + "} ORDER BY ?yy LIMIT 1 }", + "} }"); + } + /** + * @throws IOException + */ + public void testMassageServiceNested2Call() throws IOException { + abstactAskService("PREFIX eg: <http://example.com/a#>", + "prefix xsd: <http://www.w3.org/2001/XMLSchema#>", + "ASK {", + "{ SELECT ?x ?yy ", + " { ?x eg:p ?y ", + " BIND (xsd:integer(substr(?y,3)) as ?yy ) } }", + " SERVICE <> {", + "{ SELECT ?x ?yy {", + "?x eg:q ?yy ", + "} ORDER BY ?yy LIMIT 1 }", + "} }"); + } + public void testMassageServiceNested3Call() throws IOException { + abstactAskService("PREFIX eg: <http://example.com/a#>", + "prefix xsd: <http://www.w3.org/2001/XMLSchema#>", + "ASK {", + "{ SELECT ?x (xsd:integer(substr(?y,3)) as ?yy ) ", + " { ?x eg:p ?y } }", + " SERVICE <> {", + "{ SELECT ?x ?yy {", + "?x eg:q ?yy ", + "} ORDER BY ?yy LIMIT 1 }", + "} }"); + } + public void xtestServiceSyntaxError() throws IOException { + abstactAskService("PREFIX eg: <http://example.com/a#>", + "prefix xsd: <http://www.w3.org/2001/XMLSchema#>", + "ASK {", + "{ SELECT ?x (xsd:integer(substr(?y,3)) as ?yy ) ", + " { ?x eg:p ?y } }", + " SERVICE <> {", + "{ SELECT * {", + "?x eg:q ?yy ", + "} ORDER BY ?yy LIMIT 1 }", + "} }"); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |