From: <tho...@us...> - 2011-03-29 12:13:47
|
Revision: 4344 http://bigdata.svn.sourceforge.net/bigdata/?rev=4344&view=rev Author: thompsonbry Date: 2011-03-29 12:13:40 +0000 (Tue, 29 Mar 2011) Log Message: ----------- I've refactored the rewrite logic out of the BigdataSailConnection and into its own class (BigdataValueReplacer) and prepared the skeleton of a test suite for the rewrite logic (TestBigdataValueReplacer) such that it is possible to write unit tests against the rewriter without running a query against the Sail. I've incorporated a unit test into TestBigdataValueReplacer which replicates the problem described in [1]. Before going further, I would like to clarify whether we should simply filter out bindings not used by the query or also reintroduce those bindings when translating the query solutions into openrdf binding sets. [1] https://sourceforge.net/apps/trac/bigdata/ticket/271 Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailEmbeddedFederationWithQuads.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuads.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithSids.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithoutSids.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestPruneBindingSets.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataValueReplacer.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataValueReplacer.java Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java 2011-03-28 20:15:45 UTC (rev 4343) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java 2011-03-29 12:13:40 UTC (rev 4344) @@ -3481,251 +3481,15 @@ * as a variable! * * @return yucky hack, need to return a new dataset and a new binding - * set. dataset is [0], binding set is [1] + * set. dataset is [0], binding set is [1] */ - protected Object[] replaceValues(Dataset dataset, - final TupleExpr tupleExpr, BindingSet bindings) + protected Object[] replaceValues(final Dataset dataset, + final TupleExpr tupleExpr, final BindingSet bindings) throws SailException { - /* - * Resolve the values used by this query. - * - * Note: If any value can not be resolved, then its term identifer - * will remain ZERO (0L) (aka NULL). Except within OPTIONALs, this - * indicates that the query CAN NOT be satisified by the data since - * one or more required terms are unknown to the database. - */ - final HashMap<Value, BigdataValue> values = new HashMap<Value, BigdataValue>(); - - final BigdataValueFactory valueFactory = database.getValueFactory(); - - if (dataset != null) { - - for(URI uri : dataset.getDefaultGraphs()) - values.put(uri, valueFactory.asValue(uri)); - - for(URI uri : dataset.getNamedGraphs()) - values.put(uri, valueFactory.asValue(uri)); - - } - - tupleExpr.visit(new QueryModelVisitorBase<SailException>() { - - @Override - public void meet(final Var var) { - - if (var.hasValue()) { - - final Value val = var.getValue(); - - // add BigdataValue variant of the var's Value. - values.put(val, valueFactory.asValue(val)); - - } - - } - - @Override - public void meet(final ValueConstant constant) { - - if (constant.getParentNode() instanceof LangMatches) { - /* Don't try to resolve for lang matches. - * - * Note: Sesame will sometimes use a Literal to represent - * a constant parameter to a function, such as LangMatches. - * For such uses, we DO NOT want to attempt to resolve the - * Literal against the lexicon. Instead, it should just be - * passed through. BigdataSailEvaluationStrategy is then - * responsible for recognizing cases where the lack of an - * IV on a constant is associated with such function calls - * rather than indicating that the Value is not known to - * the KB. - */ - return; - } - - final Value val = constant.getValue(); - - // add BigdataValue variant of the var's Value. - values.put(val, valueFactory.asValue(val)); - - } - - }); + return new BigdataValueReplacer(database).replaceValues(dataset, + tupleExpr, bindings); - if (bindings != null) { - - Iterator<Binding> it = bindings.iterator(); - - while (it.hasNext()) { - - final Binding binding = it.next(); - - final Value val = binding.getValue(); - - // add BigdataValue variant of the var's Value. - values.put(val, valueFactory.asValue(val)); - - } - - } - - /* - * Batch resolve term identifiers for those BigdataValues. - * - * Note: If any value does not exist in the lexicon then its term - * identifier will be ZERO (0L). - */ - { - - final BigdataValue[] terms = values.values().toArray( - new BigdataValue[] {}); - - database.getLexiconRelation().addTerms(terms, terms.length, - true/* readOnly */); - - } - - /* - * Replace the values with BigdataValues having their resolve term - * identifiers. - */ - tupleExpr.visit(new QueryModelVisitorBase<SailException>() { - - @Override - public void meet(Var var) { - - if (var.hasValue()) { - - // the Sesame Value object. - final Value val = var.getValue(); - - // Lookup the resolve BigdataValue object. - final BigdataValue val2 = values.get(val); - - assert val2 != null : "value not found: "+var.getValue(); - - if (log.isDebugEnabled()) - log.debug("value: " + val + " : " + val2 + " (" - + val2.getIV() + ")"); - - if (val2.getIV() == null) { - - /* - * Since the term identifier is NULL this value is - * not known to the kb. - */ - - if(log.isInfoEnabled()) - log.info("Not in knowledge base: " + val2); - - } - - // replace the constant in the query. - var.setValue(val2); - - } - } - - @Override - public void meet(ValueConstant constant) { - - if (constant.getParentNode() instanceof LangMatches) { - /* Note: This is parallel to the meet in the visit - * pattern above. - */ - return; - } - - // the Sesame Value object. - final Value val = constant.getValue(); - - // Lookup the resolve BigdataValue object. - final BigdataValue val2 = values.get(val); - - assert val2 != null : "value not found: "+constant.getValue(); - - if (log.isDebugEnabled()) - log.debug("value: " + val + " : " + val2 + " (" - + val2.getIV() + ")"); - - if (val2.getIV() == null) { - - /* - * Since the term identifier is NULL this value is - * not known to the kb. - */ - - if(log.isInfoEnabled()) - log.info("Not in knowledge base: " + val2); - - } - - // replace the constant in the query. - constant.setValue(val2); - - } - - }); - - if (bindings != null) { - - MapBindingSet bindings2 = new MapBindingSet(); - - Iterator<Binding> it = bindings.iterator(); - - while (it.hasNext()) { - - final BindingImpl binding = (BindingImpl) it.next(); - - final Value val = binding.getValue(); - - // Lookup the resolve BigdataValue object. - final BigdataValue val2 = values.get(val); - - assert val2 != null : "value not found: "+binding.getValue(); - - if (log.isDebugEnabled()) - log.debug("value: " + val + " : " + val2 + " (" - + val2.getIV() + ")"); - - if (val2.getIV() == null) { - - /* - * Since the term identifier is NULL this value is - * not known to the kb. - */ - - if(log.isInfoEnabled()) - log.info("Not in knowledge base: " + val2); - - } - - // replace the constant in the query. - bindings2.addBinding(binding.getName(), val2); - - } - - bindings = bindings2; - - } - - if (dataset != null) { - - final DatasetImpl dataset2 = new DatasetImpl(); - - for(URI uri : dataset.getDefaultGraphs()) - dataset2.addDefaultGraph((URI)values.get(uri)); - - for(URI uri : dataset.getNamedGraphs()) - dataset2.addNamedGraph((URI)values.get(uri)); - - dataset = dataset2; - - } - - return new Object[] { dataset, bindings }; - } /** Added: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataValueReplacer.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataValueReplacer.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataValueReplacer.java 2011-03-29 12:13:40 UTC (rev 4344) @@ -0,0 +1,338 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2011. 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 Mar 29, 2011 + */ + +package com.bigdata.rdf.sail; + +import java.util.HashMap; +import java.util.Iterator; + +import org.apache.log4j.Logger; +import org.openrdf.model.URI; +import org.openrdf.model.Value; +import org.openrdf.query.Binding; +import org.openrdf.query.BindingSet; +import org.openrdf.query.Dataset; +import org.openrdf.query.algebra.LangMatches; +import org.openrdf.query.algebra.StatementPattern; +import org.openrdf.query.algebra.TupleExpr; +import org.openrdf.query.algebra.ValueConstant; +import org.openrdf.query.algebra.Var; +import org.openrdf.query.algebra.helpers.QueryModelVisitorBase; +import org.openrdf.query.impl.BindingImpl; +import org.openrdf.query.impl.DatasetImpl; +import org.openrdf.query.impl.MapBindingSet; +import org.openrdf.sail.SailException; + +import com.bigdata.rdf.model.BigdataValue; +import com.bigdata.rdf.model.BigdataValueFactory; +import com.bigdata.rdf.store.AbstractTripleStore; + +/** + * Utility class to manage the efficient translation of openrdf {@link Value}s + * in a {@link TupleExpr} or {@link BindingSet} into the {@link BigdataValue}s + * used internally by bigdata. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + */ +public class BigdataValueReplacer { + + private final static Logger log = Logger + .getLogger(BigdataValueReplacer.class); + + private final AbstractTripleStore database; + + public BigdataValueReplacer(final AbstractTripleStore database) { + + if(database == null) + throw new IllegalArgumentException(); + + this.database = database; + + } + + /** + * Batch resolve and replace all {@link Value} objects stored in variables + * or in the {@link Dataset} with {@link BigdataValue} objects, which have + * access to the 64-bit internal term identifier associated with each value + * in the database. + * <p> + * Note: The native rule execution must examine the resulting + * {@link BigdataValue}s. If any value does not exist in the lexicon then + * its term identifier will be ZERO (0L). {@link StatementPattern}s with + * term identifiers of ZERO (0L) WILL NOT match anything in the data and + * MUST NOT be executed since a ZERO (0L) will be interpreted as a variable! + * + * @return yucky hack, need to return a new dataset and a new binding set. + * dataset is [0], binding set is [1] + */ + public Object[] replaceValues(Dataset dataset, + final TupleExpr tupleExpr, BindingSet bindings) + throws SailException { + + /* + * Resolve the values used by this query. + * + * Note: If any value can not be resolved, then its term identifer + * will remain ZERO (0L) (aka NULL). Except within OPTIONALs, this + * indicates that the query CAN NOT be satisified by the data since + * one or more required terms are unknown to the database. + */ + final HashMap<Value, BigdataValue> values = new HashMap<Value, BigdataValue>(); + + final BigdataValueFactory valueFactory = database.getValueFactory(); + + if (dataset != null) { + + for(URI uri : dataset.getDefaultGraphs()) + values.put(uri, valueFactory.asValue(uri)); + + for(URI uri : dataset.getNamedGraphs()) + values.put(uri, valueFactory.asValue(uri)); + + } + + tupleExpr.visit(new QueryModelVisitorBase<SailException>() { + + @Override + public void meet(final Var var) { + + if (var.hasValue()) { + + final Value val = var.getValue(); + + // add BigdataValue variant of the var's Value. + values.put(val, valueFactory.asValue(val)); + + } + + } + + @Override + public void meet(final ValueConstant constant) { + + if (constant.getParentNode() instanceof LangMatches) { + /* Don't try to resolve for lang matches. + * + * Note: Sesame will sometimes use a Literal to represent + * a constant parameter to a function, such as LangMatches. + * For such uses, we DO NOT want to attempt to resolve the + * Literal against the lexicon. Instead, it should just be + * passed through. BigdataSailEvaluationStrategy is then + * responsible for recognizing cases where the lack of an + * IV on a constant is associated with such function calls + * rather than indicating that the Value is not known to + * the KB. + */ + return; + } + + final Value val = constant.getValue(); + + // add BigdataValue variant of the var's Value. + values.put(val, valueFactory.asValue(val)); + + } + + }); + + if (bindings != null) { + + Iterator<Binding> it = bindings.iterator(); + + while (it.hasNext()) { + + final Binding binding = it.next(); + + final Value val = binding.getValue(); + + // add BigdataValue variant of the var's Value. + values.put(val, valueFactory.asValue(val)); + + } + + } + + /* + * Batch resolve term identifiers for those BigdataValues. + * + * Note: If any value does not exist in the lexicon then its term + * identifier will be ZERO (0L). + */ + { + + final BigdataValue[] terms = values.values().toArray( + new BigdataValue[] {}); + + database.getLexiconRelation().addTerms(terms, terms.length, + true/* readOnly */); + + } + + /* + * Replace the values with BigdataValues having their resolve term + * identifiers. + */ + tupleExpr.visit(new QueryModelVisitorBase<SailException>() { + + @Override + public void meet(Var var) { + + if (var.hasValue()) { + + // the Sesame Value object. + final Value val = var.getValue(); + + // Lookup the resolve BigdataValue object. + final BigdataValue val2 = values.get(val); + + assert val2 != null : "value not found: "+var.getValue(); + + if (log.isDebugEnabled()) + log.debug("value: " + val + " : " + val2 + " (" + + val2.getIV() + ")"); + + if (val2.getIV() == null) { + + /* + * Since the term identifier is NULL this value is + * not known to the kb. + */ + + if(log.isInfoEnabled()) + log.info("Not in knowledge base: " + val2); + + } + + // replace the constant in the query. + var.setValue(val2); + + } + } + + @Override + public void meet(ValueConstant constant) { + + if (constant.getParentNode() instanceof LangMatches) { + /* Note: This is parallel to the meet in the visit + * pattern above. + */ + return; + } + + // the Sesame Value object. + final Value val = constant.getValue(); + + // Lookup the resolve BigdataValue object. + final BigdataValue val2 = values.get(val); + + assert val2 != null : "value not found: "+constant.getValue(); + + if (log.isDebugEnabled()) + log.debug("value: " + val + " : " + val2 + " (" + + val2.getIV() + ")"); + + if (val2.getIV() == null) { + + /* + * Since the term identifier is NULL this value is + * not known to the kb. + */ + + if(log.isInfoEnabled()) + log.info("Not in knowledge base: " + val2); + + } + + // replace the constant in the query. + constant.setValue(val2); + + } + + }); + + if (bindings != null) { + + MapBindingSet bindings2 = new MapBindingSet(); + + Iterator<Binding> it = bindings.iterator(); + + while (it.hasNext()) { + + final BindingImpl binding = (BindingImpl) it.next(); + + final Value val = binding.getValue(); + +// Lookup the resolve BigdataValue object. + final BigdataValue val2 = values.get(val); + + assert val2 != null : "value not found: "+binding.getValue(); + + if (log.isDebugEnabled()) + log.debug("value: " + val + " : " + val2 + " (" + + val2.getIV() + ")"); + + if (val2.getIV() == null) { + + /* + * Since the term identifier is NULL this value is + * not known to the kb. + */ + + if(log.isInfoEnabled()) + log.info("Not in knowledge base: " + val2); + + } + + // replace the constant in the query. + bindings2.addBinding(binding.getName(), val2); + + } + + bindings = bindings2; + + } + + if (dataset != null) { + + final DatasetImpl dataset2 = new DatasetImpl(); + + for(URI uri : dataset.getDefaultGraphs()) + dataset2.addDefaultGraph((URI)values.get(uri)); + + for(URI uri : dataset.getNamedGraphs()) + dataset2.addNamedGraph((URI)values.get(uri)); + + dataset = dataset2; + + } + + return new Object[] { dataset, bindings }; + + } + +} Property changes on: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataValueReplacer.java ___________________________________________________________________ Added: svn:keywords + Id Date Revision Author HeadURL Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailEmbeddedFederationWithQuads.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailEmbeddedFederationWithQuads.java 2011-03-28 20:15:45 UTC (rev 4343) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailEmbeddedFederationWithQuads.java 2011-03-29 12:13:40 UTC (rev 4344) @@ -85,6 +85,9 @@ final ProxyTestSuite suite = new ProxyTestSuite(delegate, "SAIL with Quads (embedded federation)"); + // test rewrite of RDF Value => BigdataValue for binding set and tuple expr. + suite.addTestSuite(TestBigdataValueReplacer.class); + // test pruning of variables not required for downstream processing. suite.addTestSuite(TestPruneBindingSets.class); Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuads.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuads.java 2011-03-28 20:15:45 UTC (rev 4343) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuads.java 2011-03-29 12:13:40 UTC (rev 4344) @@ -67,6 +67,9 @@ final ProxyTestSuite suite = new ProxyTestSuite(delegate, "SAIL with Quads (pipeline joins)"); + // test rewrite of RDF Value => BigdataValue for binding set and tuple expr. + suite.addTestSuite(TestBigdataValueReplacer.class); + // test pruning of variables not required for downstream processing. suite.addTestSuite(TestPruneBindingSets.class); Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithSids.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithSids.java 2011-03-28 20:15:45 UTC (rev 4343) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithSids.java 2011-03-29 12:13:40 UTC (rev 4344) @@ -61,6 +61,9 @@ final ProxyTestSuite suite = new ProxyTestSuite(delegate, "SAIL with Triples (with SIDs)"); + // test rewrite of RDF Value => BigdataValue for binding set and tuple expr. + suite.addTestSuite(TestBigdataValueReplacer.class); + // test pruning of variables not required for downstream processing. suite.addTestSuite(TestPruneBindingSets.class); Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithoutSids.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithoutSids.java 2011-03-28 20:15:45 UTC (rev 4343) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithoutSids.java 2011-03-29 12:13:40 UTC (rev 4344) @@ -61,6 +61,9 @@ final ProxyTestSuite suite = new ProxyTestSuite(delegate, "SAIL with Triples (no SIDs)"); + // test rewrite of RDF Value => BigdataValue for binding set and tuple expr. + suite.addTestSuite(TestBigdataValueReplacer.class); + // test pruning of variables not required for downstream processing. suite.addTestSuite(TestPruneBindingSets.class); Added: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataValueReplacer.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataValueReplacer.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataValueReplacer.java 2011-03-29 12:13:40 UTC (rev 4344) @@ -0,0 +1,158 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2011. 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 Mar 29, 2011 + */ + +package com.bigdata.rdf.sail; + +import java.util.Properties; + +import org.openrdf.model.Value; +import org.openrdf.model.impl.LiteralImpl; +import org.openrdf.model.impl.URIImpl; +import org.openrdf.query.MalformedQueryException; +import org.openrdf.query.QueryEvaluationException; +import org.openrdf.query.QueryLanguage; +import org.openrdf.query.TupleQuery; +import org.openrdf.query.TupleQueryResult; +import org.openrdf.repository.RepositoryException; +import org.openrdf.sail.SailException; + +import com.bigdata.rdf.axioms.NoAxioms; +import com.bigdata.rdf.model.BigdataValue; +import com.bigdata.rdf.vocab.NoVocabulary; + +/** + * Test suite for the logic which rewrites a query, replacing {@link Value} + * constants with {@link BigdataValue} constants which have been resolved + * against the database. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + */ +public class TestBigdataValueReplacer extends ProxyBigdataSailTestCase { + + /** + * + */ + public TestBigdataValueReplacer() { + } + + /** + * @param name + */ + public TestBigdataValueReplacer(String name) { + super(name); + } + + @Override + public Properties getProperties() { + + Properties props = super.getProperties(); + + props.setProperty(BigdataSail.Options.TRUTH_MAINTENANCE, "false"); + props.setProperty(BigdataSail.Options.AXIOMS_CLASS, NoAxioms.class.getName()); + props.setProperty(BigdataSail.Options.VOCABULARY_CLASS, NoVocabulary.class.getName()); + props.setProperty(BigdataSail.Options.JUSTIFY, "false"); + props.setProperty(BigdataSail.Options.TEXT_INDEX, "false"); + + return props; + + } + + /** + * Unit test for bindings passed into a query which are not used by the + * query. + * + * @throws RepositoryException + * @throws SailException + * @throws MalformedQueryException + * @throws QueryEvaluationException + * + * @see https://sourceforge.net/apps/trac/bigdata/ticket/271 + */ + public void test_bug() throws RepositoryException, SailException, + MalformedQueryException, QueryEvaluationException { + + final BigdataSail sail = getSail(); + + try { + + sail.initialize(); + final BigdataSailRepository repo = new BigdataSailRepository(sail); + final BigdataSailRepositoryConnection cxn = (BigdataSailRepositoryConnection) repo + .getConnection(); + try { + + cxn.setAutoCommit(false); + + /* + * Add a statement so the query does not get short circuited + * because some of the terms in the query are undefined in the + * database. + */ + cxn.add(new URIImpl("s:1"), new URIImpl("p:1"), new URIImpl( + "s:2")); + + final String query = "select ?a ?b WHERE {?a <p:1> ?b}"; + + final TupleQuery q = cxn.prepareTupleQuery( + QueryLanguage.SPARQL, query); + + /* + * Setup some bindings. + */ + // bind to a term in the database. + q.setBinding("a", new URIImpl("s:2")); + // bind to a term in the database. + q.setBinding("b", new URIImpl("s:2")); + // bind to a term NOT found in the database. + q.setBinding("notused", new LiteralImpl("lit")); + + /* + * Evaluate the query. + */ + final TupleQueryResult result = q.evaluate(); + try { + // @todo verify that the binding was passed along unchanged. + } finally { + result.close(); + } + + } finally { + + cxn.close(); + + } + + } finally { + + sail.__tearDownUnitTest(); + + } + + } + +} Property changes on: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataValueReplacer.java ___________________________________________________________________ Added: svn:keywords + Id Date Revision Author HeadURL Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestPruneBindingSets.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestPruneBindingSets.java 2011-03-28 20:15:45 UTC (rev 4343) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestPruneBindingSets.java 2011-03-29 12:13:40 UTC (rev 4344) @@ -82,14 +82,16 @@ public void testPruneBindingSets() throws Exception { final BigdataSail sail = getSail(); - sail.initialize(); - final BigdataSailRepository repo = new BigdataSailRepository(sail); - final BigdataSailRepositoryConnection cxn = - (BigdataSailRepositoryConnection) repo.getConnection(); - cxn.setAutoCommit(false); try { + sail.initialize(); + final BigdataSailRepository repo = new BigdataSailRepository(sail); + final BigdataSailRepositoryConnection cxn = + (BigdataSailRepositoryConnection) repo.getConnection(); + try { + cxn.setAutoCommit(false); + URI x = new URIImpl("_:X"); URI a = new URIImpl("_:A"); URI b = new URIImpl("_:B"); @@ -139,9 +141,12 @@ compare(result, solution); } + } finally { + + cxn.close(); + } } finally { - cxn.close(); sail.__tearDownUnitTest(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |