|
From: <mrp...@us...> - 2014-04-07 20:33:34
|
Revision: 8076
http://sourceforge.net/p/bigdata/code/8076
Author: mrpersonick
Date: 2014-04-07 20:33:31 +0000 (Mon, 07 Apr 2014)
Log Message:
-----------
fixed ticket 831, opened ticket 874
Modified Paths:
--------------
branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/optimizers/ASTBindingAssigner.java
Added Paths:
-----------
branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/831.rq
branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/831.ttl
branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/874.rq
branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/874.ttl
branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket831.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket874.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-04-07 20:22:03 UTC (rev 8075)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/sparql/ast/optimizers/ASTBindingAssigner.java 2014-04-07 20:33:31 UTC (rev 8076)
@@ -27,6 +27,7 @@
package com.bigdata.rdf.sparql.ast.optimizers;
+import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -55,6 +56,11 @@
import com.bigdata.rdf.sparql.ast.VarNode;
import com.bigdata.rdf.sparql.ast.eval.AST2BOpContext;
+import cutthecrap.utils.striterators.EmptyIterator;
+import cutthecrap.utils.striterators.Expander;
+import cutthecrap.utils.striterators.SingleValueIterator;
+import cutthecrap.utils.striterators.Striterator;
+
/**
* Examines the source {@link IBindingSet}[]. If there is a single binding set
* in the source, then any variable bound in that input is rewritten in the AST
@@ -152,15 +158,25 @@
final GroupNodeBase<IGroupMemberNode> whereClause,
final IBindingSet bset) {
+ doBindingAssignment(whereClause, Collections.EMPTY_MAP, bset);
+
+ }
+
+ private void doBindingAssignment(
+ final GroupNodeBase<IGroupMemberNode> whereClause,
+ final Map<VarNode, ConstantNode> parentReplacements,
+ final IBindingSet bset) {
+
final Map<VarNode, ConstantNode> replacements = new LinkedHashMap<VarNode, ConstantNode>();
+
+ replacements.putAll(parentReplacements);
- final Iterator<BOp> itr = BOpUtility
- .preOrderIterator((BOp) whereClause);
+ final Iterator<BOp> itr = iterateExcludeGroups(whereClause);
while (itr.hasNext()) {
+
+ final BOp node = itr.next();
- final BOp node = (BOp) itr.next();
-
if (node instanceof FilterNode) {
/*
@@ -213,9 +229,110 @@
if (log.isInfoEnabled())
log.info("Replaced " + ntotal + " instances of "
+ replacements.size() + " bound variables with constants");
+
+ // recurse into the childen
+ for (IGroupMemberNode node : whereClause) {
+ if (node instanceof GroupNodeBase) {
+
+ doBindingAssignment((GroupNodeBase<IGroupMemberNode>) node, replacements, bset);
+
+ }
+
+ }
+
}
+
+ /**
+ * Visits the children (recursively) using pre-order traversal, but does NOT
+ * visit this node.
+ *
+ * @param stack
+ */
+ @SuppressWarnings("unchecked")
+ private Iterator<BOp> iterateExcludeGroups(final BOp op) {
+
+ return iterateExcludeGroups(0, op);
+
+ }
+
+ /**
+ * Visits the children (recursively) using pre-order traversal, but does NOT
+ * visit this node.
+ *
+ * @param stack
+ */
+ @SuppressWarnings("unchecked")
+ private Iterator<BOp> iterateExcludeGroups(final int depth, final BOp op) {
+ /*
+ * Iterator visits the direct children, expanding them in turn with a
+ * recursive application of the pre-order iterator.
+ */
+
+ // mild optimization when no children are present.
+ if (op == null || op.arity() == 0)
+ return EmptyIterator.DEFAULT;
+
+ if (depth > 0 && op instanceof GroupNodeBase)
+ return EmptyIterator.DEFAULT;
+
+ return new Striterator(op.argIterator()).addFilter(new Expander() {
+
+ private static final long serialVersionUID = 1L;
+
+ /*
+ * Expand each child in turn.
+ */
+ protected Iterator expand(final Object childObj) {
+
+ /*
+ * A child of this node.
+ */
+
+ final BOp child = (BOp) childObj;
+
+ /*
+ * TODO The null child reference which can occur here is the [c]
+ * of the StatementPatternNode. We might want to make [c] an
+ * anonymous variable instead of having a [null].
+ */
+ if (child != null && child.arity() > 0) {
+
+ /*
+ * The child is a Node (has children).
+ *
+ * Visit the children (recursive pre-order traversal).
+ */
+
+ // append this node in pre-order position.
+ final Striterator itr = new Striterator(
+ new SingleValueIterator(child));
+
+ // append children
+ itr.append(iterateExcludeGroups(depth + 1, child));
+
+ return itr;
+
+ } else {
+
+ /*
+ * The child is a leaf.
+ */
+
+ // Visit the leaf itself.
+ return new SingleValueIterator(child);
+
+ }
+
+ }
+
+ });
+
+ }
+
+
+
/**
* Gather the VarNodes for variables which have bindings.
*
Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/831.rq
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/831.rq (rev 0)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/831.rq 2014-04-07 20:33:31 UTC (rev 8076)
@@ -0,0 +1,20 @@
+PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
+PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+
+select ?s ?p ?o
+
+where {
+
+ {
+ ?s ?p ?o.
+ filter(?s = <http://example.org/data/person1>)
+ }
+ UNION
+ {
+ ?s ?p ?o.
+ filter(?s = <http://example.org/data/person2>)
+
+ }
+
+}
\ No newline at end of file
Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/831.ttl
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/831.ttl (rev 0)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/831.ttl 2014-04-07 20:33:31 UTC (rev 8076)
@@ -0,0 +1,11 @@
+@prefix : <http://example.org/data/> .
+
+:person1
+ a :Person ;
+ :age 21;
+ :name "Person 1".
+
+:person2
+ a :Person ;
+ :age 11;
+ :name "Person 2".
\ No newline at end of file
Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/874.rq
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/874.rq (rev 0)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/874.rq 2014-04-07 20:33:31 UTC (rev 8076)
@@ -0,0 +1,17 @@
+prefix xsd: <http://www.w3.org/2001/XMLSchema#>
+SELECT *
+where {
+?user <http://arvados.org/schema/api_token> <token:ckedd> .
+{
+ ?user <http://arvados.org/schema/user_is_admin> true .
+ ?s ?p ?o .
+ FILTER strStarts(str(?s), "http://arvados.org/schema/modified") .
+}
+union
+{
+ ?user <http://arvados.org/schema/user_is_admin> false .
+ ?user <http://arvados.org/schema/permission/can_read> ?s .
+ ?s ?p ?o .
+ FILTER strStarts(str(?s), "http://arvados.org/schema/modified") .
+}
+}
\ No newline at end of file
Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/874.ttl
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/874.ttl (rev 0)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/874.ttl 2014-04-07 20:33:31 UTC (rev 8076)
@@ -0,0 +1,4 @@
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+<http://qr1hi/user/12345> <http://arvados.org/schema/api_token> <token:ckedd> .
+<http://qr1hi/user/12345> <http://arvados.org/schema/user_is_admin> "true"^^xsd:boolean .
+<http://arvados.org/schema/modified_at> <http://rdf#type> <http://rdfs#Property> .
\ No newline at end of file
Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket831.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket831.java (rev 0)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket831.java 2014-04-07 20:33:31 UTC (rev 8076)
@@ -0,0 +1,177 @@
+/**
+Copyright (C) SYSTAP, LLC 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
+*/
+
+package com.bigdata.rdf.sail;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Properties;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.log4j.Logger;
+import org.openrdf.model.impl.URIImpl;
+import org.openrdf.query.BindingSet;
+import org.openrdf.query.QueryLanguage;
+import org.openrdf.query.TupleQueryResult;
+import org.openrdf.query.impl.BindingImpl;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.sail.SailTupleQuery;
+import org.openrdf.rio.RDFFormat;
+
+import com.bigdata.rdf.axioms.NoAxioms;
+import com.bigdata.rdf.vocab.NoVocabulary;
+
+/**
+ * Unit test template for use in submission of bugs.
+ * <p>
+ * This test case will delegate to an underlying backing store. You can
+ * specify this store via a JVM property as follows:
+ * <code>-DtestClass=com.bigdata.rdf.sail.TestBigdataSailWithQuads</code>
+ * <p>
+ * There are three possible configurations for the testClass:
+ * <ul>
+ * <li>com.bigdata.rdf.sail.TestBigdataSailWithQuads (quads mode)</li>
+ * <li>com.bigdata.rdf.sail.TestBigdataSailWithoutSids (triples mode)</li>
+ * <li>com.bigdata.rdf.sail.TestBigdataSailWithSids (SIDs mode)</li>
+ * </ul>
+ * <p>
+ * The default for triples and SIDs mode is for inference with truth maintenance
+ * to be on. If you would like to turn off inference, make sure to do so in
+ * {@link #getProperties()}.
+ *
+ * @author <a href="mailto:mrp...@us...">Mike Personick</a>
+ * @version $Id$
+ */
+public class TestTicket831 extends ProxyBigdataSailTestCase {
+
+ protected static final Logger log = Logger.getLogger(TestTicket831.class);
+
+ /**
+ * Please set your database properties here, except for your journal file,
+ * please DO NOT SPECIFY A JOURNAL FILE.
+ */
+ @Override
+ public Properties getProperties() {
+
+ Properties props = super.getProperties();
+
+ /*
+ * For example, here is a set of five properties that turns off
+ * inference, truth maintenance, and the free text index.
+ */
+ props.setProperty(BigdataSail.Options.AXIOMS_CLASS, NoAxioms.class.getName());
+ props.setProperty(BigdataSail.Options.VOCABULARY_CLASS, NoVocabulary.class.getName());
+ props.setProperty(BigdataSail.Options.TRUTH_MAINTENANCE, "false");
+ props.setProperty(BigdataSail.Options.JUSTIFY, "false");
+ props.setProperty(BigdataSail.Options.TEXT_INDEX, "false");
+
+ return props;
+
+ }
+
+ public TestTicket831() {
+ }
+
+ public TestTicket831(String arg0) {
+ super(arg0);
+ }
+
+ public void testBug1() throws Exception {
+
+ /*
+ * The bigdata store, backed by a temporary journal file.
+ */
+ final BigdataSail bigdataSail = getSail();
+
+ /*
+ * Data file containing the data demonstrating your bug.
+ */
+ final String data = "831.ttl";
+ final String baseURI = "";
+ final RDFFormat format = RDFFormat.TURTLE;
+
+ try {
+
+ bigdataSail.initialize();
+
+ final BigdataSailRepository bigdataRepo = new BigdataSailRepository(bigdataSail);
+
+ { // load the data into the bigdata store
+
+ final RepositoryConnection cxn = bigdataRepo.getConnection();
+ try {
+ cxn.setAutoCommit(false);
+ cxn.add(getClass().getResourceAsStream(data), baseURI, format);
+// cxn.add(data);
+ cxn.commit();
+ } finally {
+ cxn.close();
+ }
+
+ }
+
+ {
+// final Collection<BindingSet> answer = new LinkedList<BindingSet>();
+// answer.add(createBindingSet(
+// new BindingImpl("sub", new URIImpl("http://example.org/B"))
+// ));
+
+ final String query = IOUtils.toString(getClass().getResourceAsStream("831.rq"));
+
+ if (log.isInfoEnabled()) {
+ log.info("running query:\n" + query);
+ }
+
+ /*
+ * Run the problem query using the bigdata store and then compare
+ * the answer.
+ */
+ final RepositoryConnection cxn = bigdataRepo.getReadOnlyConnection();
+ try {
+
+ final SailTupleQuery tupleQuery = (SailTupleQuery)
+ cxn.prepareTupleQuery(QueryLanguage.SPARQL, query);
+ tupleQuery.setIncludeInferred(false /* includeInferred */);
+
+ final TupleQueryResult result = tupleQuery.evaluate();
+// compare(result, answer);
+
+ while (result.hasNext()) {
+ log.info(result.next());
+ }
+
+ } finally {
+ cxn.close();
+ }
+
+ }
+
+ } finally {
+
+ bigdataSail.__tearDownUnitTest();
+
+ }
+
+ }
+
+}
Property changes on: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket831.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket874.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket874.java (rev 0)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket874.java 2014-04-07 20:33:31 UTC (rev 8076)
@@ -0,0 +1,177 @@
+/**
+Copyright (C) SYSTAP, LLC 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
+*/
+
+package com.bigdata.rdf.sail;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Properties;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.log4j.Logger;
+import org.openrdf.model.impl.URIImpl;
+import org.openrdf.query.BindingSet;
+import org.openrdf.query.QueryLanguage;
+import org.openrdf.query.TupleQueryResult;
+import org.openrdf.query.impl.BindingImpl;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.sail.SailTupleQuery;
+import org.openrdf.rio.RDFFormat;
+
+import com.bigdata.rdf.axioms.NoAxioms;
+import com.bigdata.rdf.vocab.NoVocabulary;
+
+/**
+ * Unit test template for use in submission of bugs.
+ * <p>
+ * This test case will delegate to an underlying backing store. You can
+ * specify this store via a JVM property as follows:
+ * <code>-DtestClass=com.bigdata.rdf.sail.TestBigdataSailWithQuads</code>
+ * <p>
+ * There are three possible configurations for the testClass:
+ * <ul>
+ * <li>com.bigdata.rdf.sail.TestBigdataSailWithQuads (quads mode)</li>
+ * <li>com.bigdata.rdf.sail.TestBigdataSailWithoutSids (triples mode)</li>
+ * <li>com.bigdata.rdf.sail.TestBigdataSailWithSids (SIDs mode)</li>
+ * </ul>
+ * <p>
+ * The default for triples and SIDs mode is for inference with truth maintenance
+ * to be on. If you would like to turn off inference, make sure to do so in
+ * {@link #getProperties()}.
+ *
+ * @author <a href="mailto:mrp...@us...">Mike Personick</a>
+ * @version $Id$
+ */
+public class TestTicket874 extends ProxyBigdataSailTestCase {
+
+ protected static final Logger log = Logger.getLogger(TestTicket874.class);
+
+ /**
+ * Please set your database properties here, except for your journal file,
+ * please DO NOT SPECIFY A JOURNAL FILE.
+ */
+ @Override
+ public Properties getProperties() {
+
+ Properties props = super.getProperties();
+
+ /*
+ * For example, here is a set of five properties that turns off
+ * inference, truth maintenance, and the free text index.
+ */
+ props.setProperty(BigdataSail.Options.AXIOMS_CLASS, NoAxioms.class.getName());
+ props.setProperty(BigdataSail.Options.VOCABULARY_CLASS, NoVocabulary.class.getName());
+ props.setProperty(BigdataSail.Options.TRUTH_MAINTENANCE, "false");
+ props.setProperty(BigdataSail.Options.JUSTIFY, "false");
+ props.setProperty(BigdataSail.Options.TEXT_INDEX, "false");
+
+ return props;
+
+ }
+
+ public TestTicket874() {
+ }
+
+ public TestTicket874(String arg0) {
+ super(arg0);
+ }
+
+ public void testBug1() throws Exception {
+
+ /*
+ * The bigdata store, backed by a temporary journal file.
+ */
+ final BigdataSail bigdataSail = getSail();
+
+ /*
+ * Data file containing the data demonstrating your bug.
+ */
+ final String data = "874.ttl";
+ final String baseURI = "";
+ final RDFFormat format = RDFFormat.TURTLE;
+
+ try {
+
+ bigdataSail.initialize();
+
+ final BigdataSailRepository bigdataRepo = new BigdataSailRepository(bigdataSail);
+
+ { // load the data into the bigdata store
+
+ final RepositoryConnection cxn = bigdataRepo.getConnection();
+ try {
+ cxn.setAutoCommit(false);
+ cxn.add(getClass().getResourceAsStream(data), baseURI, format);
+// cxn.add(data);
+ cxn.commit();
+ } finally {
+ cxn.close();
+ }
+
+ }
+
+ {
+// final Collection<BindingSet> answer = new LinkedList<BindingSet>();
+// answer.add(createBindingSet(
+// new BindingImpl("sub", new URIImpl("http://example.org/B"))
+// ));
+
+ final String query = IOUtils.toString(getClass().getResourceAsStream("874.rq"));
+
+ if (log.isInfoEnabled()) {
+ log.info("running query:\n" + query);
+ }
+
+ /*
+ * Run the problem query using the bigdata store and then compare
+ * the answer.
+ */
+ final RepositoryConnection cxn = bigdataRepo.getReadOnlyConnection();
+ try {
+
+ final SailTupleQuery tupleQuery = (SailTupleQuery)
+ cxn.prepareTupleQuery(QueryLanguage.SPARQL, query);
+ tupleQuery.setIncludeInferred(false /* includeInferred */);
+
+ final TupleQueryResult result = tupleQuery.evaluate();
+// compare(result, answer);
+
+ while (result.hasNext()) {
+ log.info(result.next());
+ }
+
+ } finally {
+ cxn.close();
+ }
+
+ }
+
+ } finally {
+
+ bigdataSail.__tearDownUnitTest();
+
+ }
+
+ }
+
+}
Property changes on: branches/BIGDATA_RELEASE_1_3_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket874.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|