From: <tho...@us...> - 2011-06-24 15:10:48
|
Revision: 4790 http://bigdata.svn.sourceforge.net/bigdata/?rev=4790&view=rev Author: thompsonbry Date: 2011-06-24 15:10:39 +0000 (Fri, 24 Jun 2011) Log Message: ----------- The 3rd party operation integration feature is done. See TestSetBindingSets for an example of how to make use of this feature. I've made the Property for the QueryHints null if there are no query hints and modified the various classes which look things up in that Properties object. I've backed out the changes which expose this facility in the BigdataSailQuery interface. For now, the mechanism is available to people who directly invoke BigdataSailConnection#evaluate(...). I prefer this approach with its minimum propagation of the API change until we get some feedback on the utility of this integration. See https://sourceforge.net/apps/trac/bigdata/ticket/267 Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/ThickAsynchronousIterator.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/striterator/AbstractChunkedResolverator.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataBindingSetResolverator.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataSolutionResolverator.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataStatementIteratorImpl.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java 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/BigdataSailBooleanQuery.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailGraphQuery.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailQuery.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepositoryConnection.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailTupleQuery.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/Rule2BOpUtility.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/sop/SOp2BOpUtility.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/sparql/BigdataSPARQLParser.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/TestSetBinding.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/WrappedAsynchronousIterator.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataOpenRDFBindingSetsResolverator.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/Sesame2BigdataIterator.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestSetBindingSets.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/ThickAsynchronousIterator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/ThickAsynchronousIterator.java 2011-06-24 14:41:14 UTC (rev 4789) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/ThickAsynchronousIterator.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -82,16 +82,16 @@ } - private final void assertOpen() { - - if (!open) - throw new IllegalStateException(); - - } +// private final void assertOpen() { +// +// if (!open) +// throw new IllegalStateException(); +// +// } public boolean hasNext() { - return lastIndex + 1 < a.length; + return open && lastIndex + 1 < a.length; } Added: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/WrappedAsynchronousIterator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/WrappedAsynchronousIterator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/WrappedAsynchronousIterator.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -0,0 +1,152 @@ +/* + +Copyright (C) SYSTAP, LLC 2006-2008. 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 Oct 28, 2008 + */ + +package com.bigdata.relation.accesspath; + +import java.util.NoSuchElementException; +import java.util.concurrent.TimeUnit; + +import com.bigdata.striterator.IChunkedIterator; +import com.bigdata.striterator.ICloseableIterator; + +/** + * An {@link IAsynchronousIterator} that wraps an {@link IChunkedIterator} or a + * {@link ICloseableIterator}. + * + * @param E + * The generic type of the visited chunks. + * @param F + * The generic type of the source elements. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id: ThickAsynchronousIterator.java 2265 2009-10-26 12:51:06Z + * thompsonbry $ + */ +public class WrappedAsynchronousIterator<E,F> implements IAsynchronousIterator<E> { + + private transient boolean open = true; + + private final IChunkedIterator<F> src; + + /** + * + * @param src + * The source. + * + * @throws IllegalArgumentException + * if <i>src</i> is <code>null</code>. + */ + public WrappedAsynchronousIterator(final IChunkedIterator<F> src) { + + if (src == null) + throw new IllegalArgumentException(); + + this.src = src; + + } + +// private final void assertOpen() { +// +// if (!open) +// throw new IllegalStateException(); +// +// } + + public boolean hasNext() { + + return open && src.hasNext(); + + } + + @SuppressWarnings("unchecked") + public E next() { + + if (!hasNext()) + throw new NoSuchElementException(); + + return (E) src.nextChunk(); + + } + + public void remove() { + + src.remove(); + + } + + /* + * ICloseableIterator. + */ + + public void close() { + + if (open) { + + open = false; + +// if (src instanceof ICloseableIterator<?>) { + + ((ICloseableIterator<?>) src).close(); + +// } + + } + + } + + /* + * IAsynchronousIterator. + */ + + public boolean isExhausted() { + + return !hasNext(); + + } + + /** + * Delegates to {@link #hasNext()} since all data are local and timeouts can + * not occur. + */ + public boolean hasNext(long timeout, TimeUnit unit) { + + return hasNext(); + + } + + /** + * Delegates to {@link #next()} since all data are local and timeouts can + * not occur. + */ + public E next(long timeout, TimeUnit unit) { + + return next(); + + } + +} Property changes on: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/WrappedAsynchronousIterator.java ___________________________________________________________________ Added: svn:keywords + Id Date Revision Author HeadURL Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/striterator/AbstractChunkedResolverator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/striterator/AbstractChunkedResolverator.java 2011-06-24 14:41:14 UTC (rev 4789) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/striterator/AbstractChunkedResolverator.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -50,12 +50,12 @@ */ abstract public class AbstractChunkedResolverator<E,F,S> implements ICloseableIterator<F> { - final protected static Logger log = Logger.getLogger(AbstractChunkedResolverator.class); + final private static Logger log = Logger.getLogger(AbstractChunkedResolverator.class); - /** - * True iff the {@link #log} level is DEBUG or less. - */ - final protected static boolean DEBUG = log.isDebugEnabled(); +// /** +// * True iff the {@link #log} level is DEBUG or less. +// */ +// final protected static boolean DEBUG = log.isDebugEnabled(); /** * The source iterator. @@ -202,7 +202,7 @@ try { - if (DEBUG) + if (log.isDebugEnabled()) log.debug("Start"); final long begin = System.currentTimeMillis(); @@ -224,7 +224,7 @@ nchunks++; nelements += chunk.length; - if (DEBUG) + if (log.isDebugEnabled()) log.debug("nchunks="+nchunks+", chunkSize="+chunk.length); } @@ -307,7 +307,7 @@ // elapsed += (now - begin); - if (DEBUG) + if (log.isDebugEnabled()) log.debug("nextChunk ready"); } @@ -315,7 +315,7 @@ // the next resolved element. final F f = chunk[++lastIndex]; - if (DEBUG) + if (log.isDebugEnabled()) log.debug("lastIndex=" + lastIndex + ", chunk.length=" + chunk.length + ", stmt=" + f); Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataBindingSetResolverator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataBindingSetResolverator.java 2011-06-24 14:41:14 UTC (rev 4789) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataBindingSetResolverator.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -1,6 +1,5 @@ package com.bigdata.rdf.store; -import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; @@ -8,6 +7,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; +import org.apache.log4j.Logger; import org.openrdf.model.Value; import com.bigdata.bop.Constant; @@ -31,7 +31,9 @@ public class BigdataBindingSetResolverator extends AbstractChunkedResolverator<IBindingSet, IBindingSet, AbstractTripleStore> { - + + final private static Logger log = Logger.getLogger(BigdataBindingSetResolverator.class); + private final IVariable[] required; /** Added: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataOpenRDFBindingSetsResolverator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataOpenRDFBindingSetsResolverator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataOpenRDFBindingSetsResolverator.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -0,0 +1,235 @@ +package com.bigdata.rdf.store; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; + +import org.apache.log4j.Logger; +import org.openrdf.model.Value; +import org.openrdf.query.Binding; +import org.openrdf.query.BindingSet; + +import com.bigdata.bop.Constant; +import com.bigdata.bop.IBindingSet; +import com.bigdata.bop.Var; +import com.bigdata.bop.bindingSet.ListBindingSet; +import com.bigdata.rdf.internal.DummyIV; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.lexicon.LexiconRelation; +import com.bigdata.rdf.model.BigdataValue; +import com.bigdata.rdf.model.BigdataValueFactory; +import com.bigdata.relation.accesspath.BlockingBuffer; +import com.bigdata.relation.rule.eval.ISolution; +import com.bigdata.striterator.AbstractChunkedResolverator; +import com.bigdata.striterator.IChunkedOrderedIterator; + +/** + * Efficiently resolve openrdf {@link BindingSet}s to bigdata {@link IBindingSets}s. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + */ +public class BigdataOpenRDFBindingSetsResolverator + extends + AbstractChunkedResolverator<BindingSet, IBindingSet, AbstractTripleStore> { + + final private static Logger log = Logger + .getLogger(BigdataOpenRDFBindingSetsResolverator.class); + + /** + * + * @param db + * Used to resolve RDF {@link Value}s to {@link IV}s. + * @param src + * The source iterator (will be closed when this iterator is + * closed). + * + * FIXME must accept reverse bnodes map (from term identifier to + * blank nodes) for resolution of blank nodes within a Sesame + * connection context. [Is this comment relevant for this class?] + */ + public BigdataOpenRDFBindingSetsResolverator(final AbstractTripleStore db, + final IChunkedOrderedIterator<BindingSet> src) { + + super(db, src, new BlockingBuffer<IBindingSet[]>( + db.getChunkOfChunksCapacity(), + db.getChunkCapacity(), + db.getChunkTimeout(), + TimeUnit.MILLISECONDS)); + + } + + /** + * Strengthens the return type. + */ + public BigdataOpenRDFBindingSetsResolverator start( + final ExecutorService service) { + + return (BigdataOpenRDFBindingSetsResolverator) super.start(service); + + } + + /** + * Resolve a chunk of {@link BindingSet}s into a chunk of + * {@link IBindingSet}s in which RDF {@link Value}s have been resolved to + * {@link IV}s. + */ + protected IBindingSet[] resolveChunk(final BindingSet[] chunk) { + + if (log.isInfoEnabled()) + log.info("Fetched chunk: size=" + chunk.length); + + /* + * Create a collection of the distinct term identifiers used in this + * chunk. + * + * Note: The [initialCapacity] is only an estimate. There are normally + * multiple values in each binding set. However, it is also common for + * the same Value to appear across different solutions in a chunk. + */ + + final int initialCapacity = chunk.length; + + final Collection<Value> valueSet = new LinkedHashSet<Value>(initialCapacity); + + for (BindingSet bindingSet : chunk) { + + for(Binding binding : bindingSet) { + + final Value value = binding.getValue(); + + if(value!=null) { + + valueSet.add(value); + + } + + } + + } + + if (log.isInfoEnabled()) + log.info("Resolving " + valueSet.size() + " term identifiers"); + + final LexiconRelation r = state.getLexiconRelation(); + + final BigdataValueFactory vf = r.getValueFactory(); + + final int nvalues = valueSet.size(); + + /* + * Convert to a BigdataValue[], building up a Map used to translate from + * Value to BigdataValue as we go. + */ + final BigdataValue[] values = new BigdataValue[nvalues]; + final Map<Value,BigdataValue> map = new LinkedHashMap<Value, BigdataValue>(nvalues); + { + + int i = 0; + + for (Value value : valueSet) { + + final BigdataValue val = vf.asValue(value); + + map.put(value, val); + + values[i++] = val; + + } + + } + + // Batch resolve against the database. + r.addTerms(values, nvalues, true/*readOnly*/); + + // Assemble a chunk of resolved elements + { + + final IBindingSet[] chunk2 = new IBindingSet[chunk.length]; + int i = 0; + for (BindingSet e : chunk) { + + final IBindingSet f = getBindingSet(e, map); + + chunk2[i++] = f; + + } + + // return the chunk of resolved elements. + return chunk2; + + } + + } + + /** + * Resolve the RDF {@link Value}s in the {@link BindingSet} using the map + * populated when we fetched the current chunk and return the + * {@link IBindingSet} for that solution in which term identifiers have been + * resolved to their corresponding {@link BigdataValue}s. + * + * @param solution + * A solution whose {@link Long}s will be interpreted as term + * identifiers and resolved to the corresponding + * {@link BigdataValue}s. + * + * @return The corresponding {@link IBindingSet} in which the term + * identifiers have been resolved to {@link BigdataValue}s. + * + * @throws IllegalStateException + * if the {@link IBindingSet} was not materialized with the + * {@link ISolution}. + */ + @SuppressWarnings("unchecked") + private IBindingSet getBindingSet(final BindingSet bindingSet, + final Map<Value,BigdataValue> map) { + + if (bindingSet == null) + throw new IllegalArgumentException(); + + if (map == null) + throw new IllegalArgumentException(); + + final IBindingSet out = new ListBindingSet(); + + for(Binding binding : bindingSet) { + + final String name = binding.getName(); + + final Value value = binding.getValue(); + + final BigdataValue outVal = map.get(value); + + /* + * TODO An alternative to using a DummyIV would be to drop the + * BindingSet if there are any Values in it which are not known to + * the database. + */ + if (outVal != null) { + + final Constant<?> c; + + if (outVal.getIV() == null) { + + c = new Constant(DummyIV.INSTANCE); + + } else { + + c = new Constant(outVal.getIV()); + + } + + out.set(Var.var(name), c); + + } + + } + + return out; + + } + +} Property changes on: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataOpenRDFBindingSetsResolverator.java ___________________________________________________________________ Added: svn:keywords + Id Date Revision Author HeadURL Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataSolutionResolverator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataSolutionResolverator.java 2011-06-24 14:41:14 UTC (rev 4789) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataSolutionResolverator.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -7,6 +7,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; +import org.apache.log4j.Logger; import org.openrdf.model.Value; import com.bigdata.bop.Constant; @@ -31,6 +32,8 @@ extends AbstractChunkedResolverator<ISolution, IBindingSet, AbstractTripleStore> { + final private static Logger log = Logger.getLogger(BigdataSolutionResolverator.class); + /** * * @param db Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataStatementIteratorImpl.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataStatementIteratorImpl.java 2011-06-24 14:41:14 UTC (rev 4789) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataStatementIteratorImpl.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -6,6 +6,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; +import org.apache.log4j.Logger; import org.openrdf.model.Value; import com.bigdata.rdf.internal.IV; @@ -34,6 +35,8 @@ AbstractChunkedResolverator<ISPO, BigdataStatement, AbstractTripleStore> implements BigdataStatementIterator { + final private static Logger log = Logger.getLogger(BigdataStatementIteratorImpl.class); + /** * An optional map of known blank node term identifiers and the * corresponding {@link BigdataBNodeImpl} objects. This map may be used to @@ -100,7 +103,7 @@ @Override protected BigdataStatement[] resolveChunk(final ISPO[] chunk) { - if (DEBUG) + if (log.isDebugEnabled()) log.debug("chunkSize=" + chunk.length); /* @@ -152,7 +155,7 @@ } - if (DEBUG) + if (log.isDebugEnabled()) log.debug("Resolving " + ivs.size() + " term identifiers"); /* Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java 2011-06-24 14:41:14 UTC (rev 4789) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -142,11 +142,14 @@ import com.bigdata.rdf.store.AbstractTripleStore; import com.bigdata.rdf.store.BD; import com.bigdata.rdf.store.BigdataBindingSetResolverator; +import com.bigdata.rdf.store.BigdataOpenRDFBindingSetsResolverator; +import com.bigdata.relation.accesspath.AccessPath; import com.bigdata.relation.accesspath.ElementFilter; import com.bigdata.relation.accesspath.IAsynchronousIterator; import com.bigdata.relation.accesspath.IBuffer; import com.bigdata.relation.accesspath.IElementFilter; import com.bigdata.relation.accesspath.ThickAsynchronousIterator; +import com.bigdata.relation.accesspath.WrappedAsynchronousIterator; import com.bigdata.relation.rule.IAccessPathExpander; import com.bigdata.relation.rule.IProgram; import com.bigdata.relation.rule.IQueryOptions; @@ -159,6 +162,7 @@ import com.bigdata.striterator.ChunkedWrappedIterator; import com.bigdata.striterator.Dechunkerator; import com.bigdata.striterator.DistinctFilter; +import com.bigdata.striterator.IChunkedIterator; import com.bigdata.striterator.IChunkedOrderedIterator; import com.bigdata.striterator.ICloseableIterator; @@ -292,19 +296,31 @@ /** * Logger. */ - protected static final Logger log = + private static final Logger log = Logger.getLogger(BigdataEvaluationStrategyImpl3.class); protected final BigdataTripleSource tripleSource; protected final Dataset dataset; + final private CloseableIteration<BindingSet, QueryEvaluationException> bindingSets; + private final AbstractTripleStore database; /** + * + * @param tripleSource + * @param dataset + * @param bindingSets + * An optional source for zero or more binding sets which will be + * fed into the start of the native query evaluation. + * @param nativeJoins + * @param allowSesameQueryEvaluation */ public BigdataEvaluationStrategyImpl3( - final BigdataTripleSource tripleSource, final Dataset dataset, + final BigdataTripleSource tripleSource, + final Dataset dataset, + final CloseableIteration<BindingSet, QueryEvaluationException> bindingSets, final boolean nativeJoins, final boolean allowSesameQueryEvaluation) { @@ -312,6 +328,7 @@ this.tripleSource = tripleSource; this.dataset = dataset; + this.bindingSets = bindingSets; this.database = tripleSource.getDatabase(); this.nativeJoins = nativeJoins; this.allowSesameQueryEvaluation = allowSesameQueryEvaluation; @@ -346,7 +363,7 @@ CloseableIteration<BindingSet, QueryEvaluationException> result; result = this.evaluate(projection.getArg(), bindings); - QueryBindingSet empty = new QueryBindingSet(); + final QueryBindingSet empty = new QueryBindingSet(); result = new ProjectionIterator(projection, result, empty); return result; } @@ -1028,10 +1045,45 @@ final UUID queryId = queryIdStr == null ? UUID.randomUUID() : UUID .fromString(queryIdStr); - // Wrap the input binding sets (or an empty binding set if there is no - // input). - final IAsynchronousIterator<IBindingSet[]> source = newBindingSetIterator(bs != null ? toBindingSet(bs) - : new ListBindingSet()); + /* + * Setup the input binding sets which will be fed into the query + * pipeline. + */ + final IAsynchronousIterator<IBindingSet[]> source; + if (bs != null && bindingSets != null && bs.size() > 0) + throw new QueryEvaluationException( + "BindingSet and BindingSets are mutually exclusive."); + if (bindingSets != null) { + /* + * A stream of input binding sets will be fed into the query + * pipeline (zero or more). + */ + // align openrdf CloseableIteration with Bigdata IClosableIterator. + final IChunkedOrderedIterator<BindingSet> src = new ChunkedWrappedIterator<BindingSet>( + new Sesame2BigdataIterator<BindingSet, QueryEvaluationException>( + bindingSets)); + // efficient resolution of Value[]s to IV[]s for binding set chunks. + final ICloseableIterator<IBindingSet> src2 = new BigdataOpenRDFBindingSetsResolverator( + database, src).start(database.getExecutorService()); + // chunk up the binding sets. + final IChunkedOrderedIterator<IBindingSet> src3 = new ChunkedWrappedIterator<IBindingSet>( + src2); + // wrap as an asynchronous iterator. + source = new WrappedAsynchronousIterator<IBindingSet[], IBindingSet>( + src3); + } else if (bs != null) { + /* + * A single input binding set will be fed into the query pipeline + * using the supplied bindings. + */ + source = newBindingSetIterator(toBindingSet(bs)); + } else { + /* + * A single empty input binding set will be fed into the query + * pipeline. + */ + source = newBindingSetIterator(new ListBindingSet()); + } IRunningQuery runningQuery = null; try { 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-06-24 14:41:14 UTC (rev 4789) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -3186,20 +3186,27 @@ * See {@link #evaluate(TupleExpr, Dataset, BindingSet, boolean, Properties)}. */ public CloseableIteration<? extends BindingSet, QueryEvaluationException> evaluate( - TupleExpr tupleExpr, Dataset dataset, - final BindingSet bindings, final boolean includeInferred) - throws SailException { - return evaluate(tupleExpr, dataset, bindings, includeInferred, new Properties()); + final TupleExpr tupleExpr, // + final Dataset dataset,// + final BindingSet bindings,// + final boolean includeInferred// + ) throws SailException { + + return evaluate(tupleExpr, dataset, bindings, + null/* bindingSets */, includeInferred, new Properties()); + } /** * Return the optimized operator tree. Useful for debugging. */ - public synchronized TupleExpr optimize( - TupleExpr tupleExpr, Dataset dataset, - BindingSet bindings, final boolean includeInferred, - final Properties queryHints) - throws SailException { + /*public*/ synchronized TupleExpr optimize( + TupleExpr tupleExpr,// + Dataset dataset,// + BindingSet bindings,// + final boolean includeInferred,// + final Properties queryHints// + ) throws SailException { if (log.isInfoEnabled()) log.info("Optimizing query: " + tupleExpr + ", dataSet=" @@ -3228,11 +3235,9 @@ final BigdataTripleSource tripleSource = new BigdataTripleSource(this, includeInferred); - final BigdataEvaluationStrategy strategy = - new BigdataEvaluationStrategyImpl3( - tripleSource, dataset, nativeJoins, - allowSesameQueryEvaluation - ); + final BigdataEvaluationStrategy strategy = new BigdataEvaluationStrategyImpl3( + tripleSource, dataset, null/* bindingSets */, nativeJoins, + allowSesameQueryEvaluation); final QueryOptimizerList optimizerList = new QueryOptimizerList(); optimizerList.add(new BindingAssigner()); @@ -3263,30 +3268,55 @@ } /** - * Note: The <i>includeInferred</i> argument is applied in two ways. - * First, inferences are stripped out of the {@link AccessPath}. - * Second, query time expansion of - * <code>foo rdf:type rdfs:Resource</code>, owl:sameAs, etc. - * <p> - * Note: Query time expansion can be disabled independently using - * {@link Options#QUERY_TIME_EXPANDER}, but not on a per-query basis. - * <p> - * QueryHints are a set of properties that are parsed from a SPARQL - * query. See {@link QueryHints#PREFIX} for more information. * - * @todo The [bindings] are supposed to be inputs to the query - * evaluation, but I am still not quite clear what the role of the - * "input" binding set is here. Based on their own code, e.g., - * MemoryStore, and the Sesame TCK, it is clear that evaluation - * needs to proceed against an empty binding set once it gets - * started. + * @param bindings + * The initial binding set which will be feed into the native + * query evaluation. + * + * @param bindingSets + * An optional source for zero or more binding sets which + * will be fed into the start of the native query evaluation. + * When non-<code>null</code> <i>bindings</i> MUST be empty. + * + * @param includeInferred + * The <i>includeInferred</i> argument is applied in two + * ways. First, inferences are stripped out of the + * {@link AccessPath}. Second, query time expansion of + * <code>foo rdf:type rdfs:Resource</code>, owl:sameAs, etc. + * <p> + * Note: Query time expansion can be disabled independently + * using {@link Options#QUERY_TIME_EXPANDER}, but not on a + * per-query basis. + * + * @param queryHints + * A set of properties that are parsed from a SPARQL query. + * See {@link QueryHints#PREFIX} for more information. + * + * @throws SailException + * if <i>bindingSets</i> is non-<code>null</code> and + * <i>bindingSet</i> is non-empty. + * + * @see https://sourceforge.net/apps/trac/bigdata/ticket/267 */ public synchronized CloseableIteration<? extends BindingSet, QueryEvaluationException> evaluate( - TupleExpr tupleExpr, Dataset dataset, - BindingSet bindings, final boolean includeInferred, - final Properties queryHints) - throws SailException { + TupleExpr tupleExpr,// + Dataset dataset,// + BindingSet bindings,// + final CloseableIteration<BindingSet, QueryEvaluationException> bindingSets, + final boolean includeInferred,// + final Properties queryHints// + ) throws SailException { + if (tupleExpr == null) + throw new SailException(); + + if (bindings == null) // required by optimize() and probably others. + throw new SailException(); + + if (bindings != null && bindingSets != null && bindings.size() > 0) + throw new SailException( + "The bindings and bindingSets options are mutually exclusive."); + if (log.isInfoEnabled()) log.info("Evaluating query: " + tupleExpr + ", dataSet=" + dataset + ", includeInferred=" + includeInferred); @@ -3318,8 +3348,11 @@ final BigdataEvaluationStrategy strategy = new BigdataEvaluationStrategyImpl3( - tripleSource, dataset, nativeJoins, - allowSesameQueryEvaluation + tripleSource, // + dataset, // + bindingSets,// + nativeJoins,// + allowSesameQueryEvaluation// ); final QueryOptimizerList optimizerList = new QueryOptimizerList(); @@ -3349,7 +3382,6 @@ // caller's bindingSet. final CloseableIteration<BindingSet, QueryEvaluationException> itr = strategy .evaluate(tupleExpr, - // org.openrdf.query.impl.EmptyBindingSet.getInstance(), bindings, queryHints); Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailBooleanQuery.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailBooleanQuery.java 2011-06-24 14:41:14 UTC (rev 4789) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailBooleanQuery.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -40,27 +40,39 @@ } /** - * Overriden to use query hints from SPARQL queries. Query hints are - * embedded in query strings as namespaces. - * See {@link QueryHints#PREFIX} for more information. + * {@inheritDoc} + * <p> + * Overridden to use query hints from SPARQL queries. Query hints are + * embedded in query strings as namespaces. + * + * @see QueryHints */ @Override public boolean evaluate() throws QueryEvaluationException { - ParsedBooleanQuery parsedBooleanQuery = getParsedQuery(); - TupleExpr tupleExpr = parsedBooleanQuery.getTupleExpr(); + + final ParsedBooleanQuery parsedBooleanQuery = getParsedQuery(); + + final TupleExpr tupleExpr = parsedBooleanQuery.getTupleExpr(); + Dataset dataset = getDataset(); + if (dataset == null) { + // No external dataset specified, use query's own dataset (if any) dataset = parsedBooleanQuery.getDataset(); + } try { - BigdataSailConnection sailCon = + + final BigdataSailConnection sailCon = (BigdataSailConnection) getConnection().getSailConnection(); CloseableIteration<? extends BindingSet, QueryEvaluationException> bindingsIter; - bindingsIter = sailCon.evaluate(tupleExpr, dataset, getBindings(), getIncludeInferred(), queryHints); + bindingsIter = sailCon.evaluate(tupleExpr, dataset, getBindings(), + null/* bindingSets */, getIncludeInferred(), queryHints); + bindingsIter = enforceMaxQueryTime(bindingsIter); try { @@ -76,17 +88,43 @@ } public TupleExpr getTupleExpr() throws QueryEvaluationException { + TupleExpr tupleExpr = getParsedQuery().getTupleExpr(); + try { - BigdataSailConnection sailCon = + + final BigdataSailConnection sailCon = (BigdataSailConnection) getConnection().getSailConnection(); + tupleExpr = sailCon.optimize(tupleExpr, getActiveDataset(), getBindings(), getIncludeInferred(), queryHints); + return tupleExpr; - } - catch (SailException e) { + + } catch (SailException e) { + throw new QueryEvaluationException(e.getMessage(), e); + } + } +// synchronized public void setBindingSets( +// final CloseableIteration<BindingSet, QueryEvaluationException> bindings) { +// +// if (this.bindings != null) +// throw new IllegalStateException(); +// +// this.bindings = bindings; +// +// } +// +// synchronized public CloseableIteration<BindingSet, QueryEvaluationException> getBindingSets() { +// +// return bindings; +// +// } +// +// private CloseableIteration<BindingSet, QueryEvaluationException> bindings; + } Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailGraphQuery.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailGraphQuery.java 2011-06-24 14:41:14 UTC (rev 4789) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailGraphQuery.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -230,11 +230,14 @@ public boolean isDescribe() { return describe; } - + /** - * Overriden to use query hints from SPARQL queries. Query hints are - * embedded in query strings as namespaces. - * See {@link QueryHints#PREFIX} for more information. + * {@inheritDoc} + * <p> + * Overridden to use query hints from SPARQL queries. Query hints are + * embedded in query strings as namespaces. + * + * @see QueryHints */ @Override public GraphQueryResult evaluate() throws QueryEvaluationException { @@ -242,13 +245,15 @@ try { final TupleExpr tupleExpr = getParsedQuery().getTupleExpr(); - final BigdataSailConnection sailCon = + + final BigdataSailConnection sailCon = (BigdataSailConnection) getConnection().getSailConnection(); - CloseableIteration<? extends BindingSet, QueryEvaluationException> bindingsIter = - sailCon.evaluate( - tupleExpr, getActiveDataset(), getBindings(), - getIncludeInferred(), queryHints); + CloseableIteration<? extends BindingSet, QueryEvaluationException> bindingsIter = sailCon + .evaluate(tupleExpr, getActiveDataset(), getBindings(), + null/* bindingSets */, getIncludeInferred(), + queryHints); + // Filters out all partial and invalid matches bindingsIter = new FilterIteration<BindingSet, QueryEvaluationException>( @@ -266,10 +271,14 @@ if (!useNativeConstruct) { // Convert the BindingSet objects to actual RDF statements + final ValueFactory vf = getConnection().getRepository().getValueFactory(); + final CloseableIteration<Statement, QueryEvaluationException> stIter; - stIter = new ConvertingIteration<BindingSet, Statement, QueryEvaluationException>(bindingsIter) { + stIter = new ConvertingIteration<BindingSet, Statement, QueryEvaluationException>( + bindingsIter) { + @Override protected Statement convert(BindingSet bindingSet) { final Resource subject = (Resource)bindingSet.getValue("subject"); @@ -279,26 +288,34 @@ if (context == null) { return vf.createStatement(subject, predicate, object); - } - else { + } else { return vf.createStatement(subject, predicate, object, context); } } - + }; - return new GraphQueryResultImpl(getParsedQuery().getQueryNamespaces(), stIter); + return new GraphQueryResultImpl(getParsedQuery() + .getQueryNamespaces(), stIter); } else { - // native construct. + /* + * Native construct. + */ + // Convert the BindingSet objects to actual RDF statements - final ValueFactory vf = getConnection().getRepository().getValueFactory(); + final ValueFactory vf = getConnection().getRepository() + .getValueFactory(); + final CloseableIteration<? extends Statement, QueryEvaluationException> stIter; - stIter = new BigdataConstructIterator(sailCon.getTripleStore(), bindingsIter, vf); + + stIter = new BigdataConstructIterator(sailCon.getTripleStore(), + bindingsIter, vf); + return new GraphQueryResultImpl(getParsedQuery() .getQueryNamespaces(), stIter); - + } } catch (SailException e) { @@ -311,16 +328,43 @@ * Return the same optimized operator tree as what would be executed. */ public TupleExpr getTupleExpr() throws QueryEvaluationException { + TupleExpr tupleExpr = getParsedQuery().getTupleExpr(); + try { - BigdataSailConnection sailCon = + + final BigdataSailConnection sailCon = (BigdataSailConnection) getConnection().getSailConnection(); + tupleExpr = sailCon.optimize(tupleExpr, getActiveDataset(), getBindings(), getIncludeInferred(), queryHints); + return tupleExpr; + } catch (SailException e) { + throw new QueryEvaluationException(e.getMessage(), e); + } + } +// synchronized public void setBindingSets( +// final CloseableIteration<BindingSet, QueryEvaluationException> bindings) { +// +// if (this.bindings != null) +// throw new IllegalStateException(); +// +// this.bindings = bindings; +// +// } +// +// synchronized public CloseableIteration<BindingSet, QueryEvaluationException> getBindingSets() { +// +// return bindings; +// +// } +// +// private CloseableIteration<BindingSet, QueryEvaluationException> bindings; + } Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailQuery.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailQuery.java 2011-06-24 14:41:14 UTC (rev 4789) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailQuery.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -23,10 +23,14 @@ package com.bigdata.rdf.sail; +import info.aduna.iteration.CloseableIteration; + import java.util.Properties; +import org.openrdf.query.BindingSet; import org.openrdf.query.QueryEvaluationException; import org.openrdf.query.algebra.TupleExpr; +import org.openrdf.query.impl.AbstractQuery; /** * Extension API for bigdata queries. @@ -39,7 +43,7 @@ /** * Returns a copy of the Sesame operator tree that will or would be - * evaluated by this query. + * evaluated by this query (debugging purposes only). */ TupleExpr getTupleExpr() throws QueryEvaluationException; @@ -48,6 +52,40 @@ * in query strings as namespaces. See {@link QueryHints#PREFIX} for more * information. */ - Properties getQueryHints(); - + Properties getQueryHints(); + +// /** +// * Integration point for 3rd party operators and/or data sources such as an +// * external GIS index. The supplied iteration will be used to feed initial +// * solutions into the native query evaluation performed by bigdata. +// * <p> +// * This provides a batch oriented version of the ability to set some initial +// * bindings on an {@link AbstractQuery} (you can provide many input +// * {@link BindingSet}s using this method, not just some variables on the +// * initial {@link BindingSet}). +// * <p> +// * This does not provide a "what-if" facility. Each input binding set +// * provided via this method must be consistent with the data and the query +// * for the bindings to flow through. Binding sets which are not consistent +// * with the data and the query will be pruned. +// * +// * @param bindings +// * The bindings to feed into the query evaluation. +// * +// * @throws IllegalStateException +// * if the bindings have already been set to a non- +// * <code>null</code> value. +// * +// * @see AbstractQuery#setBinding(String, org.openrdf.model.Value) +// * +// * @see https://sourceforge.net/apps/trac/bigdata/ticket/267 +// */ +// void setBindingSets( +// final CloseableIteration<BindingSet, QueryEvaluationException> bindings); +// +// /** +// * Return the iteration set by {@link #setBindingSets(CloseableIteration)}. +// */ +// CloseableIteration<BindingSet, QueryEvaluationException> getBindingSets(); + } Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepositoryConnection.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepositoryConnection.java 2011-06-24 14:41:14 UTC (rev 4789) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepositoryConnection.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -18,6 +18,7 @@ import com.bigdata.journal.TimestampUtility; import com.bigdata.rdf.changesets.IChangeLog; import com.bigdata.rdf.changesets.IChangeRecord; +import com.bigdata.rdf.model.BigdataValueFactory; import com.bigdata.rdf.sail.BigdataSail.BigdataSailConnection; import com.bigdata.rdf.sail.sparql.BigdataSPARQLParser; import com.bigdata.rdf.store.AbstractTripleStore; @@ -57,10 +58,17 @@ @Override public BigdataSailConnection getSailConnection() { - return (BigdataSailConnection)super.getSailConnection(); - + return (BigdataSailConnection)super.getSailConnection(); + } + @Override + public BigdataValueFactory getValueFactory() { + + return (BigdataValueFactory) super.getValueFactory(); + + } + /** * {@inheritDoc} * <p> Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailTupleQuery.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailTupleQuery.java 2011-06-24 14:41:14 UTC (rev 4789) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailTupleQuery.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -25,7 +25,12 @@ * See {@link QueryHints#PREFIX} for more information. */ private final Properties queryHints; - + + /** + * Set lazily by {@link #getTupleExpr()} + */ + private volatile TupleExpr tupleExpr; + public Properties getQueryHints() { return queryHints; @@ -60,8 +65,9 @@ final BigdataSailConnection sailCon = (BigdataSailConnection) getConnection() .getSailConnection(); - bindingsIter = sailCon.evaluate(tupleExpr, getActiveDataset(), - getBindings(), getIncludeInferred(), queryHints); + bindingsIter = sailCon.evaluate(tupleExpr, getActiveDataset(), + getBindings(), null/* bindingSets */, getIncludeInferred(), + queryHints); bindingsIter = enforceMaxQueryTime(bindingsIter); @@ -74,28 +80,51 @@ } - } + } - public TupleExpr getTupleExpr() throws QueryEvaluationException { + public TupleExpr getTupleExpr() throws QueryEvaluationException { - TupleExpr tupleExpr = getParsedQuery().getTupleExpr(); + if (tupleExpr == null) { + + TupleExpr tupleExpr = getParsedQuery().getTupleExpr(); - try { + try { - final BigdataSailConnection sailCon = (BigdataSailConnection) getConnection() - .getSailConnection(); + final BigdataSailConnection sailCon = (BigdataSailConnection) getConnection() + .getSailConnection(); - tupleExpr = sailCon.optimize(tupleExpr, getActiveDataset(), - getBindings(), getIncludeInferred(), queryHints); + tupleExpr = sailCon.optimize(tupleExpr, getActiveDataset(), + getBindings(), getIncludeInferred(), queryHints); - return tupleExpr; + this.tupleExpr = tupleExpr; - } catch (SailException e) { + } catch (SailException e) { - throw new QueryEvaluationException(e.getMessage(), e); - - } + throw new QueryEvaluationException(e.getMessage(), e); + } + } + + return tupleExpr; + } +// synchronized public void setBindingSets( +// final CloseableIteration<BindingSet, QueryEvaluationException> bindings) { +// +// if (this.bindings != null) +// throw new IllegalStateException(); +// +// this.bindings = bindings; +// +// } +// +// synchronized public CloseableIteration<BindingSet, QueryEvaluationException> getBindingSets() { +// +// return bindings; +// +// } +// +// private CloseableIteration<BindingSet, QueryEvaluationException> bindings; + } Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/Rule2BOpUtility.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/Rule2BOpUtility.java 2011-06-24 14:41:14 UTC (rev 4789) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/Rule2BOpUtility.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -306,6 +306,9 @@ public static PipelineOp applyQueryHints(PipelineOp op, final Properties queryHints) { + if (queryHints == null) + return op; + final Enumeration<?> pnames = queryHints.propertyNames(); while (pnames.hasMoreElements()) { @@ -409,9 +412,10 @@ */ final BOpContextBase context = new BOpContextBase(queryEngine); - final QueryOptimizerEnum optimizer = QueryOptimizerEnum - .valueOf(queryHints.getProperty(QueryHints.OPTIMIZER, - QueryOptimizerEnum.Static.toString())); + final QueryOptimizerEnum optimizer = queryHints == null ? QueryOptimizerEnum.Static + : QueryOptimizerEnum.valueOf(queryHints.getProperty( + QueryHints.OPTIMIZER, QueryOptimizerEnum.Static + .toString())); // The evaluation plan order. final int[] order; Added: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/Sesame2BigdataIterator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/Sesame2BigdataIterator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/Sesame2BigdataIterator.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -0,0 +1,101 @@ +/* + +Copyright (C) SYSTAP, LLC 2006-2008. 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 4, 2008 + */ + +package com.bigdata.rdf.sail; + +import info.aduna.iteration.CloseableIteration; + +import com.bigdata.striterator.ICloseableIterator; + +/** + * Class aligns a Sesame 2 {@link CloseableIteration} with a bigdata + * {@link ICloseableIterator}. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id: Bigdata2SesameIteration.java 2265 2009-10-26 12:51:06Z + * thompsonbry $ + * @param <T> + * The generic type of the visited elements. + * @param <E> + * The generic type of the exceptions thrown by the Sesame 2 + * {@link CloseableIteration}. + */ +public class Sesame2BigdataIterator<T, E extends Exception> implements + ICloseableIterator<T> { + + private final CloseableIteration<? extends T,E> src; + + public Sesame2BigdataIterator(final CloseableIteration<? extends T,E> src) { + + if (src == null) + throw new IllegalArgumentException(); + + this.src = src; + + } + + public void close() { + + try { + src.close(); + } catch(Exception e) { + throw new RuntimeException(e); + } + + } + + public boolean hasNext() { + + try { + return src.hasNext(); + } catch(Exception e) { + throw new RuntimeException(e); + } + + } + + public T next() { + + try { + return src.next(); + } catch(Exception e) { + throw new RuntimeException(e); + } + + } + + public void remove() { + + try { + src.remove(); + } catch(Exception e) { + throw new RuntimeException(e); + } + + } + +} Property changes on: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/Sesame2BigdataIterator.java ___________________________________________________________________ Added: svn:keywords + Id Date Revision Author HeadURL Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/sop/SOp2BOpUtility.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/sop/SOp2BOpUtility.java 2011-06-24 14:41:14 UTC (rev 4789) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/sop/SOp2BOpUtility.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -76,7 +76,7 @@ public class SOp2BOpUtility { - protected static final Logger log = Logger.getLogger(SOp2BOpUtility.class); + private static final Logger log = Logger.getLogger(SOp2BOpUtility.class); public static PipelineOp convert(final SOpTree sopTree, final AtomicInteger idFactory, final AbstractTripleStore db, @@ -962,8 +962,9 @@ } protected static boolean useHashJoin(final Properties queryHints) { - final boolean hashJoin = Boolean.valueOf(queryHints.getProperty( - QueryHints.HASH_JOIN, QueryHints.DEFAULT_HASH_JOIN)); + final boolean hashJoin = queryHints == null ? false : Boolean + .valueOf(queryHints.getProperty(QueryHints.HASH_JOIN, + QueryHints.DEFAULT_HASH_JOIN)); if (log.isInfoEnabled()) { log.info(queryHints); log.info(queryHints.getProperty(QueryHints.HASH_JOIN)); Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/sparql/BigdataSPARQLParser.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/sparql/BigdataSPARQLParser.java 2011-06-24 14:41:14 UTC (rev 4789) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/sparql/BigdataSPARQLParser.java 2011-06-24 15:10:39 UTC (rev 4790) @@ -1,4 +1,28 @@ +/** +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 +*/ /* + * Portions of this code are: + * * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007. * * Licensed under the Aduna BSD-style license. @@ -121,52 +145,46 @@ static private Properties getQueryHints(final ASTQueryContainer qc) throws MalformedQueryException { -// try { - final Properties queryHints = new Properties(); -// // currently only supporting SPARQL -// if (ql == QueryLanguage.SPARQL) { -// // the next four lines were taken directly from -// // org.openrdf.query.parser.sparql.SPARQLParser.parseQuery(String queryStr, String baseURI) -// final ASTQueryContainer qc = SyntaxTreeBuilder -// ... [truncated message content] |