From: <jer...@us...> - 2013-11-21 16:48:26
|
Revision: 7577 http://bigdata.svn.sourceforge.net/bigdata/?rev=7577&view=rev Author: jeremy_carroll Date: 2013-11-21 16:48:15 +0000 (Thu, 21 Nov 2013) Log Message: ----------- Reverted static flag to control Join mode during eval testing. Refactored AbstractDataDrivenSPARQLTestCase to allow for subclasses that have test data inline as well as in separate files. Migrated TestUnionMinus to inline test data. Added additional MINUS test cases Modified Paths: -------------- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/ArbitraryLengthPathNode.java branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/eval/AST2BOpContext.java branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/AbstractDataDrivenSPARQLTestCase.java branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestAll.java branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestInclude.java branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestTCK.java 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/TestUnionMinus.java branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/service/TestServiceRegistry.java Added Paths: ----------- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/AbstractDataAndSPARQLTestCase.java branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/AbstractInlineSELECTTestCase.java Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/ArbitraryLengthPathNode.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/ArbitraryLengthPathNode.java 2013-11-20 22:41:35 UTC (rev 7576) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/ArbitraryLengthPathNode.java 2013-11-21 16:48:15 UTC (rev 7577) @@ -11,7 +11,6 @@ import com.bigdata.rdf.sparql.ast.PathNode.PathMod; import com.bigdata.rdf.sparql.ast.eval.AST2BOpBase; import com.bigdata.rdf.sparql.ast.optimizers.StaticOptimizer; -import com.bigdata.rdf.store.ITripleStore; /** * A special kind of AST node that represents the SPARQL 1.1 arbitrary length Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/eval/AST2BOpContext.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/eval/AST2BOpContext.java 2013-11-20 22:41:35 UTC (rev 7576) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/eval/AST2BOpContext.java 2013-11-21 16:48:15 UTC (rev 7577) @@ -53,11 +53,6 @@ * FIXME Rolling back r7319 which broke UNION processing. */ public class AST2BOpContext implements IdFactory, IEvaluationContext { - - /** - * This field is public non-final so that we can change its value during testing. - */ - public static boolean DEFAULT_NATIVE_HASH_JOINS = QueryHints.DEFAULT_NATIVE_HASH_JOINS; /** * The {@link ASTContainer} @@ -153,7 +148,7 @@ * * @see QueryHints#NATIVE_HASH_JOINS */ - public boolean nativeHashJoins = DEFAULT_NATIVE_HASH_JOINS; + public boolean nativeHashJoins = QueryHints.DEFAULT_NATIVE_HASH_JOINS; /** * When <code>true</code>, a merge-join pattern will be recognized if it Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/AbstractDataAndSPARQLTestCase.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/AbstractDataAndSPARQLTestCase.java (rev 0) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/AbstractDataAndSPARQLTestCase.java 2013-11-21 16:48:15 UTC (rev 7577) @@ -0,0 +1,224 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2013. 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 +*/ +/* + * Created Nov 2013 + */ + +/* +Portions of this code are: + +Copyright Aduna (http://www.aduna-software.com/) � 2001-2007 + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ +package com.bigdata.rdf.sparql.ast.eval; + +import java.io.IOException; +import java.io.InputStream; + +import org.openrdf.model.Resource; +import org.openrdf.model.Statement; +import org.openrdf.model.URI; +import org.openrdf.model.Value; +import org.openrdf.model.impl.URIImpl; +import org.openrdf.query.QueryEvaluationException; +import org.openrdf.query.TupleQueryResult; +import org.openrdf.rio.RDFFormat; +import org.openrdf.rio.RDFHandlerException; +import org.openrdf.rio.RDFParser; +import org.openrdf.rio.RDFParserRegistry; +import org.openrdf.rio.helpers.RDFHandlerBase; + +import com.bigdata.bop.engine.AbstractQueryEngineTestCase; +import com.bigdata.rdf.model.StatementEnum; +import com.bigdata.rdf.rio.StatementBuffer; +import com.bigdata.rdf.sparql.ast.ASTContainer; +import com.bigdata.rdf.sparql.ast.AbstractASTEvaluationTestCase; +import com.bigdata.rdf.store.AbstractTripleStore; + +public abstract class AbstractDataAndSPARQLTestCase extends AbstractASTEvaluationTestCase { + + public class AbsHelper { + + protected final String queryStr; + /** + * This is the astContainer of the last query executed. + */ + protected ASTContainer astContainer; + + public AbsHelper(String queryStr) { + this.queryStr = queryStr; + } + + protected AbstractTripleStore getTripleStore() { + + return store; + + } + + protected void compareTupleQueryResults(final TupleQueryResult queryResult, final TupleQueryResult expectedResult, final boolean checkOrder) + throws QueryEvaluationException { + AbstractQueryEngineTestCase.compareTupleQueryResults(getName(), + "", store, astContainer, queryResult, expectedResult, + false, checkOrder); + } + + + long loadData(final InputStream is, RDFFormat format, String uri) { + final RDFParser rdfParser = RDFParserRegistry.getInstance().get(format).getParser(); + + rdfParser.setValueFactory(store.getValueFactory()); + + rdfParser.setVerifyData(true); + + rdfParser.setStopAtFirstError(true); + + rdfParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); + + final AddStatementHandler handler = new AddStatementHandler(); + + handler.setContext(new URIImpl(uri)); + + rdfParser.setRDFHandler(handler); + + /* + * Run the parser, which will cause statements to be inserted. + */ + + + try { + + rdfParser.parse(is, baseURI); + + return handler.close(); + + } catch (Exception e) { + + throw new RuntimeException(e); + + } finally { + + try { + + is.close(); + + } catch (IOException e) { + + throw new RuntimeException(e); + + } + + } + } + + /** + * Helper class adds statements to the sail as they are visited by a + * parser. + */ + private class AddStatementHandler extends RDFHandlerBase { + + private final StatementBuffer<Statement> buffer; + + private Resource context = null; + + private long n = 0L; + + public AddStatementHandler() { + + buffer = new StatementBuffer<Statement>(store, 100/* capacity */); + + } + + public void setContext(final Resource context) { + + this.context = context; + + } + + public void handleStatement(final Statement stmt) + throws RDFHandlerException { + + final Resource s = stmt.getSubject(); + final URI p = stmt.getPredicate(); + final Value o = stmt.getObject(); + final Resource c = stmt.getContext() == null ? this.context + : stmt.getContext(); + +// if (log.isDebugEnabled()) +// log.debug("<" + s + "," + p + "," + o + "," + c + ">"); + + buffer.add(s, p, o, c, StatementEnum.Explicit); + + n++; + + } + + /** + * + * @return The #of statements visited by the parser. + */ + public long close() { + + buffer.flush(); + + return n; + + } + + } + + } + + public AbstractDataAndSPARQLTestCase() { + } + + public AbstractDataAndSPARQLTestCase(String name) { + super(name); + } + +} Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/AbstractDataDrivenSPARQLTestCase.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/AbstractDataDrivenSPARQLTestCase.java 2013-11-20 22:41:35 UTC (rev 7576) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/AbstractDataDrivenSPARQLTestCase.java 2013-11-21 16:48:15 UTC (rev 7577) @@ -106,6 +106,7 @@ import com.bigdata.rdf.sparql.ast.ASTContainer; import com.bigdata.rdf.sparql.ast.AbstractASTEvaluationTestCase; import com.bigdata.rdf.sparql.ast.QueryRoot; +import com.bigdata.rdf.sparql.ast.eval.AbstractDataAndSPARQLTestCase.AbsHelper; import com.bigdata.rdf.store.AbstractTripleStore; /** @@ -120,7 +121,7 @@ * TODO Support manifest driven test suite. */ public class AbstractDataDrivenSPARQLTestCase extends - AbstractASTEvaluationTestCase { + AbstractDataAndSPARQLTestCase { private static final Logger log = Logger .getLogger(AbstractDataDrivenSPARQLTestCase.class); @@ -144,21 +145,14 @@ * Note: This class was derived from the openrdf SPARQLQueryTest file (Aduna * BSD style license). */ - public class TestHelper { + public class TestHelper extends AbsHelper { - private final String testURI; - private final String queryFileURL; - private final String[] dataFileURLs; private final String resultFileURL; - private final boolean laxCardinality; private final boolean checkOrder; - private final String queryStr; - - private final ASTContainer astContainer; -// private final AST2BOpContext context; + // private final PipelineOp queryPlan; @@ -174,6 +168,7 @@ } + /** * * @param testURI @@ -199,7 +194,7 @@ throws Exception { this(testURI, queryFileURL, dataFileURL, resultFileURL, - false/* laxCardinality */, false/* checkOrder */); + false/* checkOrder */); } @@ -208,17 +203,17 @@ throws Exception { this(testURI, queryFileURL, dataFileURLs, resultFileURL, - false/* laxCardinality */, false/* checkOrder */); + false/* checkOrder */); } public TestHelper(final String testURI, final String queryFileURL, final String dataFileURL, final String resultFileURL, - final boolean laxCardinality, final boolean checkOrder) + final boolean checkOrder) throws Exception { this(testURI, queryFileURL, new String[] { dataFileURL }, - resultFileURL, laxCardinality, checkOrder); + resultFileURL, checkOrder); } @@ -229,26 +224,21 @@ * @param queryFileURL * @param dataFileURLs * @param resultFileURL - * @param laxCardinality * @param checkOrder * @throws Exception */ public TestHelper(final String testURI, final String queryFileURL, final String[] dataFileURLs, final String resultFileURL, - final boolean laxCardinality, final boolean checkOrder) + final boolean checkOrder) throws Exception { + super(getResourceAsString(queryFileURL)); if (log.isInfoEnabled()) log.info("\ntestURI:\n" + testURI); - this.testURI = testURI; - this.queryFileURL = queryFileURL; - this.dataFileURLs = dataFileURLs; this.resultFileURL = resultFileURL; - this.laxCardinality = laxCardinality; this.checkOrder = checkOrder; - this.queryStr = getResourceAsString(queryFileURL); if (log.isInfoEnabled()) log.info("\nquery:\n" + queryStr); @@ -514,9 +504,7 @@ final TupleQueryResult expectedResult) throws QueryEvaluationException { - AbstractQueryEngineTestCase.compareTupleQueryResults(getName(), - testURI, store, astContainer, queryResult, expectedResult, - laxCardinality, checkOrder); + compareTupleQueryResults(queryResult, expectedResult, checkOrder); } @@ -527,116 +515,53 @@ expectedResult); } - protected InputStream getResourceAsStream(final String resource) { - - // try the classpath - InputStream is = getClass().getResourceAsStream(resource); - - if (is == null) { - - // Searching for the resource from the root of the class - // returned - // by getClass() (relative to the class' package) failed. - // Next try searching for the desired resource from the root - // of the jar; that is, search the jar file for an exact match - // of the input string. - is = getClass().getClassLoader().getResourceAsStream(resource); - - } - - if (is == null) { - - final File file = new File(resource); - - if (file.exists()) { - - try { - - is = new FileInputStream(resource); - - } catch (FileNotFoundException e) { - - throw new RuntimeException(e); - - } - - } - - } - - if (is == null) { - - try { - - is = new URL(resource).openStream(); - - } catch (MalformedURLException e) { - - /* - * Ignore. we will handle the problem below if this was not - * a URL. - */ - - } catch (IOException e) { - - throw new RuntimeException(e); - - } - - } - - if (is == null) - throw new RuntimeException("Not found: " + resource); - - return is; - - } - /** - * Return the contents of the resource. + * Load some RDF data. * * @param resource - * The resource. + * The resource whose data will be loaded. * - * @return It's contents. + * @return The #of statements parsed from the source. If there are + * duplicate told statements, then there may be fewer statements + * written onto the KB. */ - protected String getResourceAsString(final String resource) { + protected long loadData(final String resource) { - final StringBuilder sb = new StringBuilder(); + return loadData(getResourceAsStream(resource), RDFFormat.forFileName(resource), new File(resource).toURI().toString()); + + } + + } + - final InputStream is = getResourceAsStream(resource); + private static InputStream getResourceAsStream(final String resource) { - if (is == null) - throw new RuntimeException("Not found: " + resource); + // try the classpath + InputStream is = AbstractDataDrivenSPARQLTestCase.class.getResourceAsStream(resource); - try { + if (is == null) { - final LineNumberReader r = new LineNumberReader( - new InputStreamReader(is)); + // Searching for the resource from the root of the class + // returned + // by getClass() (relative to the class' package) failed. + // Next try searching for the desired resource from the root + // of the jar; that is, search the jar file for an exact match + // of the input string. + is = AbstractDataDrivenSPARQLTestCase.class.getClassLoader().getResourceAsStream(resource); - String s; - while ((s = r.readLine()) != null) { + } - sb.append(s); + if (is == null) { - sb.append("\n"); + final File file = new File(resource); - } + if (file.exists()) { - return sb.toString(); - - } catch (IOException e) { - - throw new RuntimeException(e); - - } finally { - try { - if (is != null) - is.close(); + is = new FileInputStream(resource); - } catch (IOException e) { + } catch (FileNotFoundException e) { throw new RuntimeException(e); @@ -646,122 +571,81 @@ } - /** - * Load some RDF data. - * - * @param resource - * The resource whose data will be loaded. - * - * @return The #of statements parsed from the source. If there are - * duplicate told statements, then there may be fewer statements - * written onto the KB. - */ - protected long loadData(final String resource) { + if (is == null) { - final RDFFormat rdfFormat = RDFFormat.forFileName(resource); - - final RDFParserFactory rdfParserFactory = RDFParserRegistry - .getInstance().get(rdfFormat); - - final RDFParser rdfParser = rdfParserFactory.getParser(); - - rdfParser.setValueFactory(store.getValueFactory()); - - rdfParser.setVerifyData(true); - - rdfParser.setStopAtFirstError(true); - - rdfParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); - - final AddStatementHandler handler = new AddStatementHandler(); - - handler.setContext(new URIImpl(new File(resource).toURI().toString())); - - rdfParser.setRDFHandler(handler); - - /* - * Run the parser, which will cause statements to be inserted. - */ - - final InputStream is = getResourceAsStream(resource); - try { - rdfParser.parse(is, baseURI); + is = new URL(resource).openStream(); - return handler.close(); + } catch (MalformedURLException e) { - } catch (Exception e) { + /* + * Ignore. we will handle the problem below if this was not + * a URL. + */ + } catch (IOException e) { + throw new RuntimeException(e); - } finally { + } - try { + } - is.close(); + if (is == null) + throw new RuntimeException("Not found: " + resource); - } catch (IOException e) { + return is; - throw new RuntimeException(e); + } - } + /** + * Return the contents of the resource. + * + * @param resource + * The resource. + * + * @return It's contents. + */ + private static String getResourceAsString(final String resource) { - } + final StringBuilder sb = new StringBuilder(); - } + final InputStream is = getResourceAsStream(resource); - /** - * Helper class adds statements to the sail as they are visited by a - * parser. - */ - private class AddStatementHandler extends RDFHandlerBase { + if (is == null) + throw new RuntimeException("Not found: " + resource); - private final StatementBuffer<Statement> buffer; + try { - private Resource context = null; - - private long n = 0L; + final LineNumberReader r = new LineNumberReader( + new InputStreamReader(is)); - public AddStatementHandler() { + String s; + while ((s = r.readLine()) != null) { - buffer = new StatementBuffer<Statement>(store, 100/* capacity */); + sb.append(s); - } + sb.append("\n"); - public void setContext(final Resource context) { - - this.context = context; - } - - public void handleStatement(final Statement stmt) - throws RDFHandlerException { - final Resource s = stmt.getSubject(); - final URI p = stmt.getPredicate(); - final Value o = stmt.getObject(); - final Resource c = stmt.getContext() == null ? this.context - : stmt.getContext(); + return sb.toString(); - if (log.isDebugEnabled()) - log.debug("<" + s + "," + p + "," + o + "," + c + ">"); + } catch (IOException e) { - buffer.add(s, p, o, c, StatementEnum.Explicit); + throw new RuntimeException(e); - n++; + } finally { - } + try { - /** - * - * @return The #of statements visited by the parser. - */ - public long close() { + if (is != null) + is.close(); - buffer.flush(); + } catch (IOException e) { - return n; + throw new RuntimeException(e); } @@ -769,4 +653,6 @@ } + + } Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/AbstractInlineSELECTTestCase.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/AbstractInlineSELECTTestCase.java (rev 0) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/AbstractInlineSELECTTestCase.java 2013-11-21 16:48:15 UTC (rev 7577) @@ -0,0 +1,266 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2013. 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 +*/ +/* +Portions of this code are: + +Copyright Aduna (http://www.aduna-software.com/) � 2001-2007 + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ +/* + * Created Nov 2013 + */ + +package com.bigdata.rdf.sparql.ast.eval; + +import info.aduna.iteration.Iterations; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.LineNumberReader; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.log4j.Logger; +import org.openrdf.model.Resource; +import org.openrdf.model.Statement; +import org.openrdf.model.URI; +import org.openrdf.model.Value; +import org.openrdf.model.impl.URIImpl; +import org.openrdf.query.GraphQueryResult; +import org.openrdf.query.MalformedQueryException; +import org.openrdf.query.QueryEvaluationException; +import org.openrdf.query.TupleQueryResult; +import org.openrdf.query.algebra.evaluation.QueryBindingSet; +import org.openrdf.query.dawg.DAWGTestResultSetUtil; +import org.openrdf.query.impl.TupleQueryResultBuilder; +import org.openrdf.query.resultio.BooleanQueryResultFormat; +import org.openrdf.query.resultio.BooleanQueryResultParserRegistry; +import org.openrdf.query.resultio.QueryResultIO; +import org.openrdf.query.resultio.TupleQueryResultFormat; +import org.openrdf.query.resultio.TupleQueryResultParser; +import org.openrdf.rio.RDFFormat; +import org.openrdf.rio.RDFHandlerException; +import org.openrdf.rio.RDFParser; +import org.openrdf.rio.RDFParser.DatatypeHandling; +import org.openrdf.rio.RDFParserFactory; +import org.openrdf.rio.RDFParserRegistry; +import org.openrdf.rio.Rio; +import org.openrdf.rio.helpers.RDFHandlerBase; +import org.openrdf.rio.helpers.StatementCollector; + +import com.bigdata.rdf.model.StatementEnum; +import com.bigdata.rdf.rio.StatementBuffer; +import com.bigdata.rdf.sail.sparql.Bigdata2ASTSPARQLParser; +import com.bigdata.rdf.sparql.ast.AbstractASTEvaluationTestCase; +import com.bigdata.rdf.sparql.ast.QueryRoot; + +/** + * The idea here is that the subclasses provide the data for the test + * (i.e. the triples, the query and the results) inline and not in separate + * files. One goal is to reduce the level of redundant comments + * that can be out of sync. + * + * See {@link AbstractDataDrivenSPARQLTestCase} for the out-of-line files based approach, + * which may be more suitable for larger queries, test data or results. + * @author jeremycarroll + */ +public abstract class AbstractInlineSELECTTestCase extends AbstractDataAndSPARQLTestCase + { + + private static final Logger log = Logger + .getLogger(AbstractInlineSELECTTestCase.class); + + private final Map<String,String> prefixes = new HashMap<String,String>(); + /** + * + */ + public AbstractInlineSELECTTestCase() { + } + + /** + * @param name + */ + public AbstractInlineSELECTTestCase(String name) { + super(name); + addPrefix("","http://example.org/banana#"); + addPrefix("rdf","http://www.w3.org/1999/02/22-rdf-syntax-ns#"); + addPrefix("rdfs","http://www.w3.org/2000/01/rdf-schema#"); + addPrefix("xsd","http://www.w3.org/2001/XMLSchema#"); + } + + public void addPrefix(String prefix, String namespace) { + prefixes.put(prefix, namespace); + } + + public class Execute extends AbsHelper { + + + private static final String FILL_IN_URI = "http://please-do-not-user-relative-uris/"; + + + private TupleQueryResult executeSelect(String sparql) throws QueryEvaluationException, MalformedQueryException { + String prefixes = sparqlPrefixes(); + astContainer = new Bigdata2ASTSPARQLParser(store).parseQuery2(prefixes+sparql, FILL_IN_URI); + return ASTEvalHelper.evaluateTupleQuery(store, astContainer, new QueryBindingSet()); + } + + /** + * + * See http://stackoverflow.com/a/7716231/2276263 + * @param testURI + * @throws Exception + * + */ + public Execute(final String queryStr) throws Exception { + super(queryStr); + + + + if (log.isInfoEnabled()) + log.info("\nquery:\n" + queryStr); + } + + /** + * Load some RDF data. + * + * @param data + * The in-line data to be loaded. + * + * @return The #of statements parsed from the source. If there are + * duplicate told statements, then there may be fewer statements + * written onto the KB. + * @throws UnsupportedEncodingException + */ + private long loadData(String data) throws UnsupportedEncodingException { + + if (data == null || data.length() == 0) { + return 0; + } + + data = ttlPrefixes() + data; + + byte utf8Data[] = data.getBytes("utf-8"); + final InputStream is = new ByteArrayInputStream(utf8Data); + String uri = FILL_IN_URI; + + RDFFormat format = RDFFormat.TRIG; + return loadData(is, format, uri); + + } + + public void expectResultSet(String vars, String ... bindings) throws Exception { + final TupleQueryResult expectedResult = expectedTupleQueryResult(vars, bindings); + + loadData(trigData()); + + final TupleQueryResult queryResult = executeSelect(queryStr); + compareTupleQueryResults(queryResult, expectedResult, false); + } + + private TupleQueryResult expectedTupleQueryResult(String vars, String ...bindings ) throws QueryEvaluationException, MalformedQueryException { + StringBuilder sb = new StringBuilder(); + sb.append("SELECT "); + sb.append(vars); + sb.append("\n{} BINDINGS "); + sb.append(vars); + sb.append("{\n"); + for (String binding:bindings) { + sb.append(" ( "); + sb.append(binding); + sb.append(" )\n"); + } + sb.append("}\n"); + return executeSelect( sb.toString()); + } + + protected String trigData() { + return AbstractInlineSELECTTestCase.this.trigData(); + } + + } + + protected abstract String trigData(); + + public String sparqlPrefixes() { + StringBuilder sb = new StringBuilder(); + for (Map.Entry<String, String> entry: prefixes.entrySet()) { + sb.append("PREFIX "); + sb.append(entry.getKey()); + sb.append(": <"); + sb.append(entry.getValue()); + sb.append(">\n"); + } + sb.append("\n"); + return sb.toString(); + } + + public String ttlPrefixes() { + StringBuilder sb = new StringBuilder(); + for (Map.Entry<String, String> entry: prefixes.entrySet()) { + sb.append("@prefix "); + sb.append(entry.getKey()); + sb.append(": <"); + sb.append(entry.getValue()); + sb.append(">.\n"); + } + sb.append("\n"); + return sb.toString(); + } + +} Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestAll.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestAll.java 2013-11-20 22:41:35 UTC (rev 7576) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestAll.java 2013-11-21 16:48:15 UTC (rev 7577) @@ -26,7 +26,6 @@ import com.bigdata.rdf.sparql.ast.QueryHints; import com.bigdata.rdf.sparql.ast.eval.reif.TestReificationDoneRightEval; -import junit.extensions.TestSetup; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; @@ -56,7 +55,7 @@ * Returns a test that will run each of the implementation specific test * suites in turn. */ - private static TestSuite coreSuite() + public static Test suite() { final TestSuite suite = new TestSuite("AST Evaluation"); @@ -182,31 +181,4 @@ } - - /** - * Returns a test that will run each of the implementation specific test - * suites in turn. - */ - public static Test suite() - { - - final TestSuite suite = new TestSuite("AST Evaluation (all)"); - final TestSuite tHash = coreSuite(); - tHash.setName("AST Evaluation (tHash)"); - suite.addTest(new TestSetup(tHash) { - - protected void setUp() throws Exception { - AST2BOpContext.DEFAULT_NATIVE_HASH_JOINS = true; - } - protected void tearDown() throws Exception { - AST2BOpContext.DEFAULT_NATIVE_HASH_JOINS = false; - } - - }); - final TestSuite jvmHash = coreSuite(); - jvmHash.setName("AST Evaluation (jvmHash)"); - suite.addTest(jvmHash); - return suite; - } - } Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestInclude.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestInclude.java 2013-11-20 22:41:35 UTC (rev 7576) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestInclude.java 2013-11-21 16:48:15 UTC (rev 7577) @@ -127,7 +127,6 @@ "include_01.rq",// query URL "include_01.trig",// data URL "include_01.srx",// results URL - false,// lax cardinality true // check order(!) ); @@ -238,7 +237,6 @@ "include_02.rq",// query URL "include_02.trig",// data URL "include_02.srx",// results URL - false,// lax cardinality true // check order(!) ); @@ -372,7 +370,6 @@ "include_03a.rq",// query URL "include_03.trig",// data URL "include_03.srx",// results URL - false,// lax cardinality false // check order ); @@ -519,7 +516,6 @@ "include_03.rq",// query URL "include_03.trig",// data URL "include_03.srx",// results URL - false,// lax cardinality false // check order ); Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestTCK.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestTCK.java 2013-11-20 22:41:35 UTC (rev 7576) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestTCK.java 2013-11-21 16:48:15 UTC (rev 7577) @@ -757,7 +757,6 @@ "sparql11-order-02.rq",// queryFileURL "sparql11-order-02.ttl",// dataFileURL "sparql11-order-02.srx"// resultFileURL - ,false// laxCardinality ,true// checkOrder ).runTest(); @@ -782,7 +781,6 @@ "sparql11-order-02-workaround.rq",// queryFileURL "sparql11-order-02.ttl",// dataFileURL "sparql11-order-02.srx"// resultFileURL - ,false// laxCardinality ,true// checkOrder ).runTest(); @@ -806,7 +804,6 @@ "sparql11-order-03.rq",// queryFileURL "sparql11-order-03.ttl",// dataFileURL "sparql11-order-03.srx"// resultFileURL - ,false// laxCardinality ,true// checkOrder ).runTest(); @@ -859,7 +856,6 @@ "join_with_no_shared_variables.rq",// queryFileURL "join_with_no_shared_variables.ttl",// dataFileURL "join_with_no_shared_variables.srx"// resultFileURL - ,false// laxCardinality ,false// checkOrder ).runTest(); 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 2013-11-20 22:41:35 UTC (rev 7576) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestTickets.java 2013-11-21 16:48:15 UTC (rev 7577) @@ -27,8 +27,6 @@ package com.bigdata.rdf.sparql.ast.eval; -import com.bigdata.BigdataStatics; - /** * Test suite for tickets at <href a="http://sourceforge.net/apps/trac/bigdata"> * trac </a>. @@ -180,11 +178,6 @@ } public void test_ticket_748() throws Exception { - // Concerning omitting the test with hash joins, see Trac776 and - // com.bigdata.rdf.internal.encoder.AbstractBindingSetEncoderTestCase.test_solutionWithOneMockIV() - - if(AST2BOpContext.DEFAULT_NATIVE_HASH_JOINS && !BigdataStatics.runKnownBadTests) - return; new TestHelper("ticket748-subselect",// testURI, "ticket748-subselect.rq",// queryFileURL @@ -197,9 +190,6 @@ public void test_ticket_748a() throws Exception { - if(AST2BOpContext.DEFAULT_NATIVE_HASH_JOINS && !BigdataStatics.runKnownBadTests) - return; - new TestHelper("ticket748A-subselect",// testURI, "ticket748A-subselect.rq",// queryFileURL "ticket748-subselect.ttl",// dataFileURL @@ -210,9 +200,6 @@ public void test_ticket_two_subselects_748() throws Exception { - if(AST2BOpContext.DEFAULT_NATIVE_HASH_JOINS && !BigdataStatics.runKnownBadTests) - return; - new TestHelper("ticket748-two-subselects",// testURI, "ticket748-two-subselects.rq",// queryFileURL "ticket748-two-subselects.ttl",// dataFileURL @@ -224,9 +211,6 @@ public void test_ticket_two_subselects_748a() throws Exception { - if(AST2BOpContext.DEFAULT_NATIVE_HASH_JOINS && !BigdataStatics.runKnownBadTests) - return; - new TestHelper("ticket748A-two-subselects",// testURI, "ticket748A-two-subselects.rq",// queryFileURL "ticket748-two-subselects.ttl",// dataFileURL @@ -263,7 +247,6 @@ "ticket563-DistinctOrderBy.rq",// queryFileURL "ticket563-DistinctOrderBy.n3",// dataFileURL "ticket563-DistinctOrderBy.srx",// resultFileURL - false, // laxCardinality true // checkOrder ).runTest(); @@ -276,7 +259,6 @@ "aggregate-min.rq",// queryFileURL "aggregate-min-max.ttl",// dataFileURL "aggregate-min.srx",// resultFileURL - false, // laxCardinality true // checkOrder ).runTest(); @@ -288,7 +270,6 @@ "aggregate-max.rq",// queryFileURL "aggregate-min-max.ttl",// dataFileURL "aggregate-max.srx",// resultFileURL - false, // laxCardinality true // checkOrder ).runTest(); @@ -300,7 +281,6 @@ "aggregate-min1.rq",// queryFileURL "aggregate-min-max.ttl",// dataFileURL "aggregate-min1.srx",// resultFileURL - false, // laxCardinality true // checkOrder ).runTest(); @@ -312,7 +292,6 @@ "aggregate-max1.rq",// queryFileURL "aggregate-min-max.ttl",// dataFileURL "aggregate-max1.srx",// resultFileURL - false, // laxCardinality true // checkOrder ).runTest(); @@ -324,7 +303,6 @@ "aggregate-min2.rq",// queryFileURL "aggregate-min-max.ttl",// dataFileURL "aggregate-min2.srx",// resultFileURL - false, // laxCardinality true // checkOrder ).runTest(); @@ -336,7 +314,6 @@ "aggregate-max2.rq",// queryFileURL "aggregate-min-max.ttl",// dataFileURL "aggregate-max2.srx",// resultFileURL - false, // laxCardinality true // checkOrder ).runTest(); Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestUnionMinus.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestUnionMinus.java 2013-11-20 22:41:35 UTC (rev 7576) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/TestUnionMinus.java 2013-11-21 16:48:15 UTC (rev 7577) @@ -27,12 +27,14 @@ package com.bigdata.rdf.sparql.ast.eval; +import com.bigdata.BigdataStatics; + /** * Test suite for UNION and MINUS combined, see * https://sourceforge.net/apps/trac/bigdata/ticket/767 * */ -public class TestUnionMinus extends AbstractDataDrivenSPARQLTestCase { +public class TestUnionMinus extends AbstractInlineSELECTTestCase { /** * @@ -47,39 +49,179 @@ super(name); } - /** -SELECT ?s -WHERE { - { - BIND ( :bob as ?s ) - } UNION { - } - MINUS { - BIND ( :bob as ?s ) - } -} LIMIT 10 - */ + @Override + public String trigData() { + return ""; + } + + public void test_union_minus_01() throws Exception { + // Concerning omitting the test with hash joins, see Trac776 and + // com.bigdata.rdf.internal.encoder.AbstractBindingSetEncoderTestCase.test_solutionWithOneMockIV() + + new Execute( + "SELECT ?s \r\n" + + "WHERE { \r\n" + + " { \r\n" + + " BIND ( :bob as ?s ) \r\n" + + " } UNION { \r\n" + + " } \r\n" + + " MINUS { \r\n" + + " BIND ( :bob as ?s ) \r\n" + + " } \r\n" + + "}").expectResultSet("?s","UNDEF"); + + } - new TestHelper("union_minus_01").runTest(); + + public void test_union_minus_02() throws Exception { + + new Execute( + "SELECT ?s\r\n" + + "WHERE {\r\n" + + " { \r\n" + + " BIND ( :bob as ?s )\r\n" + + " } UNION {\r\n" + + " }\r\n" + + " FILTER (!BOUND(?s) || ?s != :bob)\r\n" + + "}").expectResultSet("?s","UNDEF"); } + public void test_union_minus_03() throws Exception { - /** -SELECT ?s -WHERE { - { - BIND ( :bob as ?s ) - } UNION { - } - FILTER (!BOUND(?s) || ?s != :bob) -} + new Execute( + "SELECT ?s \r\n" + + "WHERE { \r\n" + + " { \r\n" + + " BIND ( 2 as ?s ) \r\n" + + " } UNION { \r\n" + + " } \r\n" + + " MINUS { \r\n" + + " BIND ( 2 as ?s ) \r\n" + + " } \r\n" + + "}").expectResultSet("?s","UNDEF"); + + } + public void test_union_minus_04() throws Exception { - */ - public void test_union_minus_02() throws Exception { + new Execute( + "SELECT ?x \r\n" + + "WHERE { \r\n" + + " BIND ( 3 as ?x ) \r\n" + + " { BIND ( 4 as ?x ) \r\n" + + " } UNION { \r\n" + + " MINUS { \r\n" + + " BIND ( 3 as ?x ) \r\n" + + " } \r\n" + + " BIND (3 as ?x) \r\n" + + " } \r\n" + + "}").expectResultSet("?x","3"); + + } + public void test_union_minus_05() throws Exception { - new TestHelper("union_minus_02").runTest(); + new Execute( + "SELECT ?x \r\n" + + "WHERE { \r\n" + + " BIND ( 3 as ?x ) \r\n" + + " { BIND ( 4 as ?x ) \r\n" + + " } UNION { \r\n" + + " MINUS { \r\n" + + " BIND ( 3 as ?x ) \r\n" + + " } \r\n" + + " } \r\n" + + "}").expectResultSet("?x","3"); } + public void test_union_minus_06() throws Exception { + + new Execute( + "SELECT ?x \r\n" + + "WHERE { \r\n" + + " BIND ( 3 as ?x ) \r\n" + + " { BIND ( 4 as ?x ) \r\n" + + " } UNION { \r\n" + + " BIND (3 as ?x) \r\n" + + " MINUS { \r\n" + + " BIND ( 3 as ?x ) \r\n" + + " } \r\n" + + " } \r\n" + + "}").expectResultSet("?x"); + + } + + public void test_union_minus_07() throws Exception { + + new Execute( + "SELECT ?x \r\n" + + "WHERE { \r\n" + + " BIND ( 3 as ?x ) \r\n" + + " { BIND ( 4 as ?x ) \r\n" + + " } UNION { \r\n" + + " BIND ( 3 as ?x ) \r\n" + + " MINUS { \r\n" + + " { \r\n" + + " BIND ( 3 as ?x ) \r\n" + + " } UNION { \r\n" + + " BIND ( 4 as ?y ) \r\n" + + " } \r\n" + + " } \r\n" + + " } \r\n" + + "}").expectResultSet("?x"); + + } + + public void test_union_minus_08() throws Exception { + + new Execute( + "SELECT ?x \r\n" + + "WHERE { \r\n" + + " BIND ( 3 as ?x ) \r\n" + + " { BIND ( 4 as ?x ) \r\n" + + " } UNION { \r\n" + + " BIND ( 3 as ?x ) \r\n" + + " MINUS { \r\n" + + " { \r\n" + + " BIND ( 3 as ?x ) \r\n" + + " } UNION { \r\n" + + " } \r\n" + + " } \r\n" + + " } \r\n" + + "}").expectResultSet("?x"); + + } + + public void test_union_minus_09() throws Exception { + + new Execute( + "SELECT ?x \r\n" + + "WHERE { \r\n" + + " BIND ( 3 as ?x ) \r\n" + + " { BIND ( 4 as ?x ) \r\n" + + " } UNION { \r\n" + + " BIND ( 3 as ?x ) \r\n" + + " MINUS { \r\n" + + " } \r\n" + + " } \r\n" + + "}").expectResultSet("?x","3"); + + } + + public void test_union_minus_10() throws Exception { + + new Execute( + "SELECT ?x \r\n" + + "WHERE { \r\n" + + " { BIND ( 3 as ?x ) } \r\n" + + " UNION \r\n" + + " { BIND ( 4 as ?y ) } \r\n" + + " MINUS { \r\n" + + " { BIND ( 3 as ?x ) } \r\n" + + " UNION \r\n" + + " { BIND ( 4 as ?y ) } \r\n" + + " } \r\n" + + "}").expectResultSet("?x","3"); + + } } Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/service/TestServiceRegistry.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/service/TestServiceRegistry.java 2013-11-20 22:41:35 UTC (rev 7576) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/sparql/ast/eval/service/TestServiceRegistry.java 2013-11-21 16:48:15 UTC (rev 7577) @@ -300,7 +300,6 @@ // De-register alias ServiceRegistry.getInstance().remove(serviceURI1); - ServiceRegistry.getInstance().remove(serviceURI2); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |