From: <mrp...@us...> - 2010-10-25 15:43:24
|
Revision: 3844 http://bigdata.svn.sourceforge.net/bigdata/?rev=3844&view=rev Author: mrpersonick Date: 2010-10-25 15:43:17 +0000 (Mon, 25 Oct 2010) Log Message: ----------- testing single tail rules Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestMultiGraphs.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/tck/BigdataSparqlTest.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/org/openrdf/query/parser/sparql/SPARQLQueryTest.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestSesameMultiGraphs.java Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl.java 2010-10-25 15:40:55 UTC (rev 3843) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl.java 2010-10-25 15:43:17 UTC (rev 3844) @@ -466,7 +466,7 @@ return new EmptyIteration<BindingSet, QueryEvaluationException>(); } - return execute(query, bindings); + return execute(query); } catch (UnknownOperatorException ex) { @@ -577,7 +577,7 @@ return new EmptyIteration<BindingSet, QueryEvaluationException>(); } - return execute(query, bindings); + return execute(query); } catch (UnknownOperatorException ex) { @@ -683,7 +683,7 @@ return new EmptyIteration<BindingSet, QueryEvaluationException>(); } - return execute(query, bindings); + return execute(query); } catch (UnknownOperatorException ex) { @@ -1668,16 +1668,8 @@ * * @throws QueryEvaluationException */ -// protected CloseableIteration<BindingSet, QueryEvaluationException> execute( -// final IStep step) -// throws Exception { -// -// return execute(step, null); -// -// } - protected CloseableIteration<BindingSet, QueryEvaluationException> execute( - final IStep step, final BindingSet constants) + final IStep step) throws Exception { final QueryEngine queryEngine = tripleSource.getSail().getQueryEngine(); @@ -1721,7 +1713,7 @@ CloseableIteration<BindingSet, QueryEvaluationException> result = new Bigdata2Sesame2BindingSetIterator<QueryEvaluationException>( new BigdataBindingSetResolverator(database, it2).start(database - .getExecutorService()), constants); + .getExecutorService())); try { // Wait for the Future (checks for errors). @@ -1842,6 +1834,10 @@ final StatementPattern sp, final BindingSet bindings) throws QueryEvaluationException { + if (sp.getParentNode() instanceof Projection) { + return evaluateSingleTailRule(sp, bindings); + } + if (log.isDebugEnabled()) { log.debug("evaluating statement pattern:\n" + sp); } @@ -1873,39 +1869,38 @@ } -// /** -// * Override evaluation of StatementPatterns to recognize magic search -// * predicate. -// */ -// @Override -// public CloseableIteration<BindingSet, QueryEvaluationException> evaluate( -// final StatementPattern sp, final BindingSet bindings) -// throws QueryEvaluationException { -// -// // no check against the nativeJoins property here because we are simply -// // using the native execution model to take care of magic searches. -// -// if (log.isDebugEnabled()) { -// log.debug("evaluating statement pattern:\n" + sp); -// } -// -// final IStep query = createNativeQuery(sp); -// -// if (query == null) { -// return new EmptyIteration<BindingSet, QueryEvaluationException>(); -// } -// -// try { -// -// return execute(query, bindings); -// -// } catch (Exception ex) { -// -// throw new QueryEvaluationException(ex); -// -// } -// -// } + /** + * Override evaluation of StatementPatterns to recognize magic search + * predicate. + */ + public CloseableIteration<BindingSet, QueryEvaluationException> evaluateSingleTailRule( + final StatementPattern sp, final BindingSet bindings) + throws QueryEvaluationException { + + // no check against the nativeJoins property here because we are simply + // using the native execution model to take care of magic searches. + + if (log.isDebugEnabled()) { + log.debug("evaluating statement pattern:\n" + sp); + } + + final IStep query = createNativeQuery(sp); + + if (query == null) { + return new EmptyIteration<BindingSet, QueryEvaluationException>(); + } + + try { + + return execute(query); + + } catch (Exception ex) { + + throw new QueryEvaluationException(ex); + + } + + } /** Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestMultiGraphs.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestMultiGraphs.java 2010-10-25 15:40:55 UTC (rev 3843) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestMultiGraphs.java 2010-10-25 15:43:17 UTC (rev 3844) @@ -163,7 +163,7 @@ "PREFIX rdfs: <"+RDFS.NAMESPACE+"> " + "PREFIX ns: <"+ns+"> " + - "select ?p ?o " + + "select distinct ?p ?o " + "WHERE { " + // " ?s rdf:type ns:Person . " + " ns:Mike ?p ?o . " + Added: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestSesameMultiGraphs.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestSesameMultiGraphs.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestSesameMultiGraphs.java 2010-10-25 15:43:17 UTC (rev 3844) @@ -0,0 +1,163 @@ +/** +Copyright (C) SYSTAP, LLC 2006-2007. 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 on Sep 16, 2009 + */ + +package com.bigdata.rdf.sail; + +import org.openrdf.model.URI; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.vocabulary.RDF; +import org.openrdf.model.vocabulary.RDFS; +import org.openrdf.query.QueryLanguage; +import org.openrdf.query.TupleQuery; +import org.openrdf.query.TupleQueryResult; +import org.openrdf.repository.sail.SailRepository; +import org.openrdf.repository.sail.SailRepositoryConnection; +import org.openrdf.sail.Sail; +import org.openrdf.sail.memory.MemoryStore; + +/** + * @author <a href="mailto:mrp...@us...">Mike Personick</a> + * @version $Id$ + */ +public class TestSesameMultiGraphs { + + public static void main(String[] args) throws Exception { + + final Sail sail; + final SailRepository repo; + final SailRepositoryConnection cxn; + + sail = new MemoryStore(); + repo = new SailRepository(sail); + + repo.initialize(); + cxn = repo.getConnection(); + cxn.setAutoCommit(false); + + try { + + final ValueFactory vf = sail.getValueFactory(); + + final String ns = "http://namespace/"; + + URI a = vf.createURI(ns+"a"); + URI b = vf.createURI(ns+"b"); + URI c = vf.createURI(ns+"c"); + URI g1 = vf.createURI(ns+"graph1"); + URI g2 = vf.createURI(ns+"graph2"); +/**/ + cxn.setNamespace("ns", ns); + + cxn.add(a, b, c, g1, g2); + + /* + * Note: The either flush() or commit() is required to flush the + * statement buffers to the database before executing any operations + * that go around the sail. + */ + cxn.commit();// + + { + + String query = + "PREFIX rdf: <"+RDF.NAMESPACE+"> " + + "PREFIX rdfs: <"+RDFS.NAMESPACE+"> " + + "PREFIX ns: <"+ns+"> " + + + "select ?p ?o " + + "WHERE { " + + " ns:a ?p ?o . " + + "}"; + + final TupleQuery tupleQuery = + cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); + TupleQueryResult result = tupleQuery.evaluate(); + + System.err.println("no dataset specified, RDF-MERGE, should produce one solution:"); + while (result.hasNext()) { + System.err.println(result.next()); + } + + } + + { + + String query = + "PREFIX rdf: <"+RDF.NAMESPACE+"> " + + "PREFIX rdfs: <"+RDFS.NAMESPACE+"> " + + "PREFIX ns: <"+ns+"> " + + + "select ?p ?o " + + "from <"+g1+">" + + "from <"+g2+">" + + "WHERE { " + + " ns:a ?p ?o . " + + "}"; + + final TupleQuery tupleQuery = + cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); + TupleQueryResult result = tupleQuery.evaluate(); + + System.err.println("default graph query, RDF-MERGE, should produce one solution:"); + while (result.hasNext()) { + System.err.println(result.next()); + } + + } + + { + + String query = + "PREFIX rdf: <"+RDF.NAMESPACE+"> " + + "PREFIX rdfs: <"+RDFS.NAMESPACE+"> " + + "PREFIX ns: <"+ns+"> " + + + "select ?p ?o " + + "from named <"+g1+">" + + "from named <"+g2+">" + + "WHERE { " + + " graph ?g { ns:a ?p ?o . } " + + "}"; + + final TupleQuery tupleQuery = + cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); + TupleQueryResult result = tupleQuery.evaluate(); + + System.err.println("named graph query, no RDF-MERGE, should produce two solutions:"); + while (result.hasNext()) { + System.err.println(result.next()); + } + + } + + } finally { + cxn.close(); + sail.shutDown(); + } + + } + +} Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/tck/BigdataSparqlTest.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/tck/BigdataSparqlTest.java 2010-10-25 15:40:55 UTC (rev 3843) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/tck/BigdataSparqlTest.java 2010-10-25 15:43:17 UTC (rev 3844) @@ -28,6 +28,7 @@ package com.bigdata.rdf.sail.tck; import info.aduna.io.IOUtil; +import info.aduna.iteration.Iterations; import java.io.InputStream; import java.io.InputStreamReader; @@ -36,15 +37,27 @@ import java.util.Collection; import java.util.Enumeration; import java.util.Properties; +import java.util.Set; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.log4j.Logger; +import org.openrdf.model.Statement; +import org.openrdf.query.BooleanQuery; import org.openrdf.query.Dataset; +import org.openrdf.query.GraphQuery; +import org.openrdf.query.GraphQueryResult; +import org.openrdf.query.Query; +import org.openrdf.query.QueryLanguage; +import org.openrdf.query.TupleQuery; +import org.openrdf.query.TupleQueryResult; import org.openrdf.query.parser.sparql.ManifestTest; import org.openrdf.query.parser.sparql.SPARQLQueryTest; import org.openrdf.repository.Repository; +import org.openrdf.repository.RepositoryConnection; import org.openrdf.repository.RepositoryException; +import org.openrdf.repository.RepositoryResult; import org.openrdf.repository.dataset.DatasetRepository; import org.openrdf.repository.sail.SailRepository; import org.openrdf.sail.memory.MemoryStore; @@ -65,6 +78,9 @@ */ public class BigdataSparqlTest extends SPARQLQueryTest { + static protected final Logger log = Logger.getLogger(BigdataSparqlTest.class); + + /** * We cannot use inlining for these test because we do normalization on * numeric values and these tests test for syntatic differences, i.e. @@ -168,22 +184,22 @@ * run. */ static final Collection<String> testURIs = Arrays.asList(new String[] { -/* + // busted with EvalStrategy1 - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/algebra/manifest#nested-opt-2", - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/algebra/manifest#filter-scope-1", - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/algebra/manifest#join-scope-1", - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/optional/manifest#dawg-optional-complex-4", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/algebra/manifest#nested-opt-2", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/algebra/manifest#filter-scope-1", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/algebra/manifest#join-scope-1", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/optional/manifest#dawg-optional-complex-4", // busted with EvalStrategy2 with LeftJoin enabled - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/open-world/manifest#open-eq-12", - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/algebra/manifest#nested-opt-1", - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/algebra/manifest#opt-filter-1", - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/algebra/manifest#opt-filter-2", - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/optional/manifest#dawg-optional-complex-3", - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/optional-filter/manifest#dawg-optional-filter-001", - "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/optional-filter/manifest#dawg-optional-filter-004", -*/ +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/open-world/manifest#open-eq-12", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/algebra/manifest#nested-opt-1", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/algebra/manifest#opt-filter-1", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/algebra/manifest#opt-filter-2", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/optional/manifest#dawg-optional-complex-3", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/optional-filter/manifest#dawg-optional-filter-001", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/optional-filter/manifest#dawg-optional-filter-004", + // Dataset crap // "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/i18n/manifest#normalization-1", @@ -207,6 +223,7 @@ // "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/basic/manifest#prefix-name-1",//OK // "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/basic/manifest#spoo-1",//BOOM +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/graph/manifest#dawg-graph-05", }); /** @@ -424,11 +441,6 @@ super.setUp(); } - @Override - public void runTest() throws Exception { - super.runTest(); - } - public Repository getRepository() { return dataRep; } @@ -448,5 +460,43 @@ } +// @Override +// protected void runTest() +// throws Exception +// { +// RepositoryConnection con = getQueryConnection(dataRep); +// try { +// +// log.info("database dump:"); +// RepositoryResult<Statement> stmts = con.getStatements(null, null, null, false); +// while (stmts.hasNext()) { +// log.info(stmts.next()); +// } +// log.info("dataset:\n" + dataset); +// +// String queryString = readQueryString(); +// log.info("query:\n" + getQueryString()); +// +// Query query = con.prepareQuery(QueryLanguage.SPARQL, queryString, queryFileURL); +// if (dataset != null) { +// query.setDataset(dataset); +// } +// +// if (query instanceof TupleQuery) { +// TupleQueryResult queryResult = ((TupleQuery)query).evaluate(); +// while (queryResult.hasNext()) { +// log.info("query result:\n" + queryResult.next()); +// } +// } +// +// } +// finally { +// con.close(); +// } +// +// super.runTest(); +// } + + } Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/org/openrdf/query/parser/sparql/SPARQLQueryTest.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/org/openrdf/query/parser/sparql/SPARQLQueryTest.java 2010-10-25 15:40:55 UTC (rev 3843) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/org/openrdf/query/parser/sparql/SPARQLQueryTest.java 2010-10-25 15:43:17 UTC (rev 3844) @@ -435,7 +435,7 @@ } } - private String readQueryString() + protected String readQueryString() throws IOException { InputStream stream = new URL(queryFileURL).openStream(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |