From: <tho...@us...> - 2010-09-02 18:52:46
|
Revision: 3495 http://bigdata.svn.sourceforge.net/bigdata/?rev=3495&view=rev Author: thompsonbry Date: 2010-09-02 18:52:36 +0000 (Thu, 02 Sep 2010) Log Message: ----------- Test suite for distinct binding sets operator and for an optional pipeline join using only the default sink. Reorganized the operator hierarchy somewhat. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/AbstractChunkedOrderedIteratorOp.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/AbstractPipelineOp.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/ArrayBindingSet.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/BindingSetPipelineOp.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/HashBindingSet.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/IPredicate.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/PipelineStartOp.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/aggregation/DistinctBindingSetOp.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/ap/DistinctElementFilter.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/EQ.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/EQConstant.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/NE.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/NEConstant.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/OR.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/eval/JoinGraph.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/join/PipelineJoin.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/join/ThreadLocalBufferFactory.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/IElementFilter.java branches/QUADS_QUERY_BRANCH/bigdata/src/resources/logging/log4j.properties branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/TestDeepCopy.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/aggregation/TestAll.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/aggregation/TestDistinctBindingSets.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/ap/R.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/ap/TestPredicateAccessPath.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestAll.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/MapBindingSetsOverShards.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/PipelineDelayOp.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/QueryEngine.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/ReceiveBindingSets.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/RunningQuery.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestPipelineUtility.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/join/TestPipelineJoin.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/inf/OwlSameAsPropertiesExpandingIterator.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/AbstractInlineConstraint.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/magic/IRISUtils.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/MatchRule.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RejectAnythingSameAsItself.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/aggregation/Union.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/BOpConstraint.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/INBinarySearch.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/INConstraint.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/INHashMap.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/aggregation/TestUnionBindingSets.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestEQConstant.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestInBinarySearch.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestInHashMap.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestNE.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestNEConstant.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestOR.java Removed Paths: ------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/ap/Union.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/IN.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/AbstractChunkedOrderedIteratorOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/AbstractChunkedOrderedIteratorOp.java 2010-09-02 13:49:55 UTC (rev 3494) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/AbstractChunkedOrderedIteratorOp.java 2010-09-02 18:52:36 UTC (rev 3495) @@ -30,8 +30,6 @@ import java.util.Map; import java.util.concurrent.TimeUnit; -import com.bigdata.bop.ap.Predicate; - /** * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/AbstractPipelineOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/AbstractPipelineOp.java 2010-09-02 13:49:55 UTC (rev 3494) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/AbstractPipelineOp.java 2010-09-02 18:52:36 UTC (rev 3495) @@ -35,6 +35,9 @@ import com.bigdata.relation.accesspath.IBlockingBuffer; /** + * Abstract base class for pipelined operators regardless of the type of data + * moving along the pipeline. + * * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ */ Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/ArrayBindingSet.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/ArrayBindingSet.java 2010-09-02 13:49:55 UTC (rev 3494) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/ArrayBindingSet.java 2010-09-02 18:52:36 UTC (rev 3495) @@ -50,19 +50,9 @@ private static final long serialVersionUID = -6468905602211956490L; - protected static final Logger log = Logger.getLogger(ArrayBindingSet.class); - - /** - * True iff the {@link #log} level is INFO or less. - */ - protected static final boolean INFO = log.isInfoEnabled(); + private static final Logger log = Logger.getLogger(ArrayBindingSet.class); /** - * True iff the {@link #log} level is DEBUG or less. - */ - protected static final boolean DEBUG = log.isDebugEnabled(); - - /** * A dense array of the bound variables. */ private final IVariable[] vars; @@ -77,7 +67,7 @@ /** * Copy constructor. */ - protected ArrayBindingSet(ArrayBindingSet bindingSet) { + protected ArrayBindingSet(final ArrayBindingSet bindingSet) { if (bindingSet == null) throw new IllegalArgumentException(); @@ -100,18 +90,17 @@ * @param vals * Their bound values. */ - public ArrayBindingSet(IVariable[] vars, IConstant[] vals) { + public ArrayBindingSet(final IVariable[] vars, final IConstant[] vals) { -// if (vars == null) -// throw new IllegalArgumentException(); -// -// if (vals == null) -// throw new IllegalArgumentException(); + if (vars == null) + throw new IllegalArgumentException(); - assert vars != null; - assert vals != null; - assert vars.length == vals.length; + if (vals == null) + throw new IllegalArgumentException(); + if(vars.length != vals.length) + throw new IllegalArgumentException(); + // for (int i = 0; i < vars.length; i++) { // // if (vars[i] == null) @@ -139,7 +128,7 @@ * @throws IllegalArgumentException * if the <i>capacity</i> is negative. */ - public ArrayBindingSet(int capacity) { + public ArrayBindingSet(final int capacity) { if (capacity < 0) throw new IllegalArgumentException(); @@ -244,7 +233,7 @@ * Since the array is dense (no gaps), {@link #clear(IVariable)} requires * that we copy down any remaining elements in the array by one position. */ - public void clear(IVariable var) { + public void clear(final IVariable var) { if (var == null) throw new IllegalArgumentException(); @@ -282,7 +271,7 @@ } - public IConstant get(IVariable var) { + public IConstant get(final IVariable var) { if (var == null) throw new IllegalArgumentException(); @@ -301,7 +290,7 @@ } - public boolean isBound(IVariable var) { + public boolean isBound(final IVariable var) { return get(var) != null; @@ -315,10 +304,11 @@ if (val == null) throw new IllegalArgumentException(); - if(DEBUG) { - - log.debug("var=" + var + ", val=" + val + ", nbound=" + nbound+", capacity="+vars.length); - + if (log.isTraceEnabled()) { + + log.trace("var=" + var + ", val=" + val + ", nbound=" + nbound + + ", capacity=" + vars.length); + } for (int i = 0; i < nbound; i++) { @@ -343,7 +333,7 @@ public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append("{"); Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/BindingSetPipelineOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/BindingSetPipelineOp.java 2010-09-02 13:49:55 UTC (rev 3494) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/BindingSetPipelineOp.java 2010-09-02 18:52:36 UTC (rev 3495) @@ -1,15 +1,51 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2010. 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 2, 2010 + */ + package com.bigdata.bop; +import java.util.Map; + /** - * Interface for evaluating pipeline operations producing and consuming chunks - * of binding sets. + * Abstract base class for pipeline operators where the data moving along the + * pipeline is chunks of {@link IBindingSet}s. * * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ */ -public interface BindingSetPipelineOp extends PipelineOp<IBindingSet> { +abstract public class BindingSetPipelineOp extends + AbstractPipelineOp<IBindingSet> { - public interface Annotations extends PipelineOp.Annotations { + /** + * + */ + private static final long serialVersionUID = 1L; + public interface Annotations extends AbstractPipelineOp.Annotations { + /** * The value of the annotation is the {@link BOp.Annotations#BOP_ID} of * the ancestor in the operator tree which serves as an alternative sink @@ -20,4 +56,26 @@ } + /** + * Required deep copy constructor. + * + * @param op + */ + protected BindingSetPipelineOp(AbstractPipelineOp<IBindingSet> op) { + super(op); + } + + /** + * Shallow copy constructor. + * + * @param args + * @param annotations + */ + protected BindingSetPipelineOp(final BOp[] args, + final Map<String, Object> annotations) { + + super(args, annotations); + + } + } Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/HashBindingSet.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/HashBindingSet.java 2010-09-02 13:49:55 UTC (rev 3494) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/HashBindingSet.java 2010-09-02 18:52:36 UTC (rev 3495) @@ -32,15 +32,20 @@ import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.LinkedList; import java.util.Map; import java.util.Map.Entry; - /** * {@link IBindingSet} backed by a {@link HashMap}. * * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ + * + * @todo Since {@link Var}s allow reference testing, a faster implementation + * could be written based on a {@link LinkedList}. Just scan the list + * until the entry is found with the desired {@link Var} reference and + * then return it. */ public class HashBindingSet implements IBindingSet { @@ -93,7 +98,28 @@ } - public boolean isBound(IVariable var) { + public HashBindingSet(final IVariable[] vars, final IConstant[] vals) { + + if (vars == null) + throw new IllegalArgumentException(); + + if (vals == null) + throw new IllegalArgumentException(); + + if (vars.length != vals.length) + throw new IllegalArgumentException(); + + map = new LinkedHashMap<IVariable, IConstant>(vars.length); + + for (int i = 0; i < vars.length; i++) { + + map.put(vars[i], vals[i]); + + } + + } + + public boolean isBound(final IVariable var) { if (var == null) throw new IllegalArgumentException(); @@ -102,7 +128,7 @@ } - public IConstant get(IVariable var) { + public IConstant get(final IVariable var) { if (var == null) throw new IllegalArgumentException(); @@ -111,7 +137,7 @@ } - public void set(IVariable var, IConstant val) { + public void set(final IVariable var, final IConstant val) { if (var == null) throw new IllegalArgumentException(); @@ -123,7 +149,7 @@ } - public void clear(IVariable var) { + public void clear(final IVariable var) { if (var == null) throw new IllegalArgumentException(); Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/IPredicate.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/IPredicate.java 2010-09-02 13:49:55 UTC (rev 3494) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/IPredicate.java 2010-09-02 18:52:36 UTC (rev 3495) @@ -30,7 +30,7 @@ import java.io.Serializable; -import com.bigdata.bop.ap.Union; +import com.bigdata.bop.join.PipelineJoin; import com.bigdata.mdi.PartitionLocator; import com.bigdata.relation.IMutableRelation; import com.bigdata.relation.IRelation; @@ -85,6 +85,8 @@ /** * <code>true</code> iff the predicate is optional (the right operand of * a left join). + * + * @deprecated This flag is being moved to the join operator. */ String OPTIONAL = "optional"; @@ -131,8 +133,8 @@ * @param index * The index into the array of relation names in the view. * - * @deprecated Unions of predicates must be handled explicitly. See - * {@link Union}. + * @deprecated Unions of predicates must be handled explicitly as a union of + * pipeline operators reading against the different predicate. */ public String getRelationName(int index); Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/PipelineStartOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/PipelineStartOp.java 2010-09-02 13:49:55 UTC (rev 3494) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/PipelineStartOp.java 2010-09-02 18:52:36 UTC (rev 3495) @@ -29,7 +29,6 @@ import java.util.Map; import java.util.concurrent.Callable; -import java.util.concurrent.Future; import java.util.concurrent.FutureTask; import com.bigdata.bop.engine.BOpStats; @@ -44,8 +43,7 @@ * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ */ -public class PipelineStartOp extends AbstractPipelineOp<IBindingSet> implements - BindingSetPipelineOp { +public class PipelineStartOp extends BindingSetPipelineOp { /** * @@ -82,8 +80,6 @@ */ static private class CopyTask implements Callable<Void> { -// private final BOpContext<IBindingSet> context; - private final BOpStats stats; private final IAsynchronousIterator<IBindingSet[]> source; @@ -91,8 +87,6 @@ private final IBlockingBuffer<IBindingSet[]> sink; CopyTask(final BOpContext<IBindingSet> context) { - -// this.context = context; stats = context.getStats(); Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/aggregation/DistinctBindingSetOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/aggregation/DistinctBindingSetOp.java 2010-09-02 13:49:55 UTC (rev 3494) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/aggregation/DistinctBindingSetOp.java 2010-09-02 18:52:36 UTC (rev 3495) @@ -7,10 +7,10 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.FutureTask; -import com.bigdata.bop.AbstractPipelineOp; -import com.bigdata.bop.ArrayBindingSet; import com.bigdata.bop.BOp; import com.bigdata.bop.BOpContext; +import com.bigdata.bop.BindingSetPipelineOp; +import com.bigdata.bop.HashBindingSet; import com.bigdata.bop.IBindingSet; import com.bigdata.bop.IConstant; import com.bigdata.bop.IVariable; @@ -25,14 +25,14 @@ * @version $Id: DistinctElementFilter.java 3466 2010-08-27 14:28:04Z * thompsonbry $ */ -public class DistinctBindingSetOp extends AbstractPipelineOp<IBindingSet>{ +public class DistinctBindingSetOp extends BindingSetPipelineOp { /** * */ private static final long serialVersionUID = 1L; - public interface Annotations extends BOp.Annotations { + public interface Annotations extends BindingSetPipelineOp.Annotations { /** * The initial capacity of the {@link ConcurrentHashMap} used to impose @@ -40,7 +40,7 @@ * * @see #DEFAULT_INITIAL_CAPACITY */ - String INITIAL_CAPACITY = "initialCapacity"; + String INITIAL_CAPACITY = DistinctBindingSetOp.class.getName()+".initialCapacity"; int DEFAULT_INITIAL_CAPACITY = 16; @@ -50,7 +50,7 @@ * * @see #DEFAULT_LOAD_FACTOR */ - String LOAD_FACTOR = "loadFactor"; + String LOAD_FACTOR = DistinctBindingSetOp.class.getName()+".loadFactor"; float DEFAULT_LOAD_FACTOR = .75f; @@ -60,7 +60,7 @@ * * @see #DEFAULT_CONCURRENCY_LEVEL */ - String CONCURRENCY_LEVEL = "concurrencyLevel"; + String CONCURRENCY_LEVEL = DistinctBindingSetOp.class.getName()+".concurrencyLevel"; int DEFAULT_CONCURRENCY_LEVEL = 16; @@ -170,7 +170,7 @@ if (vals.length != t.vals.length) return false; for (int i = 0; i < vals.length; i++) { - // @todo allow for nulls. + // @todo verify that this allows for nulls with a unit test. if (vals[i] == t.vals[i]) continue; if (vals[i] == null) @@ -185,7 +185,7 @@ /** * Task executing on the node. */ - private class DistinctTask implements Callable<Void> { + static private class DistinctTask implements Callable<Void> { private final BOpContext<IBindingSet> context; @@ -209,8 +209,8 @@ this.vars = op.getVariables(); this.map = new ConcurrentHashMap<Solution, Solution>( - getInitialCapacity(), getLoadFactor(), - getConcurrencyLevel()); + op.getInitialCapacity(), op.getLoadFactor(), + op.getConcurrencyLevel()); } @@ -230,16 +230,13 @@ for (int i = 0; i < vars.length; i++) { - if ((r[i] = bset.get(vars[i])) == null) { + /* + * Note: This allows null's. + * + * @todo write a unit test when some variables are not bound. + */ + r[i] = bset.get(vars[i]); - /* - * @todo probably allow nulls, but write a unit test for it. - */ - - throw new RuntimeException("Not bound: " + vars[i]); - - } - } final Solution s = new Solution(r); @@ -283,14 +280,7 @@ // System.err.println("accepted: " // + Arrays.toString(vals)); - /* - * @todo This may cause problems since the - * ArrayBindingSet does not allow mutation with - * variables not declared up front. In that case use - * new HashBindingSet( new ArrayBindingSet(...)). - */ - - accepted.add(new ArrayBindingSet(vars, vals)); + accepted.add(new HashBindingSet(vars, vals)); naccepted++; Copied: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/aggregation/Union.java (from rev 3466, branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/ap/Union.java) =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/aggregation/Union.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/aggregation/Union.java 2010-09-02 18:52:36 UTC (rev 3495) @@ -0,0 +1,135 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2010. 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 Aug 18, 2010 + */ + +package com.bigdata.bop.aggregation; + +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.FutureTask; + +import com.bigdata.bop.BOpContext; +import com.bigdata.bop.BindingSetPipelineOp; +import com.bigdata.bop.IBindingSet; +import com.bigdata.bop.engine.Haltable; +import com.bigdata.bop.join.PipelineJoin; +import com.bigdata.rdf.rules.TMUtility; +import com.bigdata.relation.RelationFusedView; + +/** + * The union of two or more {@link BindingSetPipelineOp} operators. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + * + * @todo I have some basic questions about the ability to use a UNION of two + * predicates in scale-out. I think that this might be more accurately + * modeled as the UNION of two joins. That is, rather than: + * + * <pre> + * JOIN( ..., + * UNION( foo.spo(A,loves,B), + * bar.spo(A,loves,B) ) + * ) + * </pre> + * + * using + * + * <pre> + * UNION( JOIN( ..., foo.spo(A,loves,B) ), + * JOIN( ..., bar.spo(A,loves,B) ) + * ) + * </pre> + * + * which would be a binding set union rather than an element union. + * + * @todo The union of access paths was historically handled by + * {@link RelationFusedView}. That class should be removed once queries + * are rewritten to use the union of joins. + * + * @todo The {@link TMUtility} will have to be updated to use this operator + * rather than specifying multiple source "names" for the relation of the + * predicate. + * + * @todo The FastClosureRuleTask will also need to be updated to use a + * {@link Union} over the joins rather than a {@link RelationFusedView}. + */ +public class Union extends BindingSetPipelineOp { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * @param args + * Two or more operators whose union is desired. + * @param annotations + */ + public Union(final BindingSetPipelineOp[] args, + final Map<String, Object> annotations) { + + super(args, annotations); + + if (args.length < 2) + throw new IllegalArgumentException(); + + } + + public FutureTask<Void> eval(final BOpContext<IBindingSet> context) { + + return new FutureTask<Void>(new UnionTask(this, context)); + + } + + /** + * Pipeline union impl. + * + * FIXME All this does is copy its inputs to its outputs. Since we only run + * one chunk of input at a time, it seems that the easiest way to implement + * a union is to have the operators in the union just target the same sink. + */ + private static class UnionTask extends Haltable<Void> implements Callable<Void> { + + public UnionTask(// + final Union op,// + final BOpContext<IBindingSet> context + ) { + + if (op == null) + throw new IllegalArgumentException(); + if (context == null) + throw new IllegalArgumentException(); + } + + public Void call() throws Exception { + // TODO Auto-generated method stub + throw new UnsupportedOperationException(); + } + + } + +} Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/ap/DistinctElementFilter.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/ap/DistinctElementFilter.java 2010-09-02 13:49:55 UTC (rev 3494) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/ap/DistinctElementFilter.java 2010-09-02 18:52:36 UTC (rev 3495) @@ -1,58 +1,46 @@ package com.bigdata.bop.ap; -import java.util.UUID; -import java.util.concurrent.Callable; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.FutureTask; +import com.bigdata.bop.BOp; import com.bigdata.bop.BOpBase; -import com.bigdata.bop.BOp; -import com.bigdata.bop.BOpList; +import com.bigdata.bop.BOpContext; import com.bigdata.bop.IBindingSet; -import com.bigdata.bop.IVariable; -import com.bigdata.bop.NV; -import com.bigdata.bop.aggregation.DistinctBindingSetOp; -import com.bigdata.btree.keys.KeyBuilder; -import com.bigdata.rdf.relation.rule.BindingSetSortKeyBuilder; import com.bigdata.rdf.spo.DistinctSPOIterator; -import com.bigdata.relation.accesspath.IBlockingBuffer; -import com.bigdata.relation.rule.eval.IJoinNexus; -import com.bigdata.relation.rule.eval.ISolution; +import com.bigdata.rdf.spo.SPO; +import com.bigdata.relation.accesspath.IElementFilter; import com.bigdata.striterator.DistinctFilter; import com.bigdata.striterator.IChunkConverter; import com.bigdata.striterator.MergeFilter; /** - * A DISTINCT operator based on a hash table. + * A DISTINCT operator based for elements in a relation. The operator is based + * on a hash table. New elements are constructed for each original element in + * which only the distinct fields are preserved. If the new element is distinct + * then it is passed by the filter. + * <p> + * The filter is capable of changing the type of the accepted elements. * * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id: DistinctElementFilter.java 3466 2010-08-27 14:28:04Z * thompsonbry $ + * * @param <E> + * The generic type of the source elements for the filter. + * @param <F> + * The generic type of the elements passed by the filter. * - * @todo could have an implementation backed by a persistent hash map using an - * extensible hash function to automatically grow the persistence store. - * This could be a general purpose persistent hash functionality, but it - * could also operate against a temporary file when used in the context of - * a query (the backing file can be destroyed afterwards or the data can - * be simply written onto the current temporary store). + * @todo support changing the generic type as part of the filter. this is + * similar to the {@link IChunkConverter}. * - * @todo Consider the use of lock amortization (batching) to reduce contention - * for the backing map. Alternatively, we could accept entire blocks of - * elements from a single source at a time, which would single thread us - * through the map. Or bound the #of threads hitting the map at once, - * increase the map concurrency level, etc. - * * @todo Reconcile with {@link IChunkConverter}, {@link DistinctFilter} (handles * solutions) and {@link MergeFilter} (handles comparables), - * {@link DistinctSPOIterator}, {@link DistinctBindingSetOp}, etc. + * {@link DistinctSPOIterator}, etc. */ -public class DistinctElementFilter<E> -extends BOpBase -//extends AbstractChunkedIteratorOp<E> -//implements IElementFilter<E>, -// implements IConstraint, -// implements ChunkedIteratorOp<E> -{ +public class DistinctElementFilter<E> extends BOpBase implements + IElementFilter<E> { /** * @@ -61,104 +49,272 @@ public interface Annotations extends BOp.Annotations { - String INITIAL_CAPACITY = "initialCapacity"; + /** + * The initial capacity of the {@link ConcurrentHashMap} used to impose + * the distinct constraint. + * + * @see #DEFAULT_INITIAL_CAPACITY + */ + String INITIAL_CAPACITY = DistinctElementFilter.class.getName() + + ".initialCapacity"; - String LOAD_FACTOR = "loadFactor"; + int DEFAULT_INITIAL_CAPACITY = 16; - String CONCURRENCY_LEVEL = "concurrencyLevel"; + /** + * The load factor of the {@link ConcurrentHashMap} used to impose the + * distinct constraint. + * + * @see #DEFAULT_LOAD_FACTOR + */ + String LOAD_FACTOR = DistinctElementFilter.class.getName() + + ".loadFactor"; - } + float DEFAULT_LOAD_FACTOR = .75f; - public DistinctElementFilter(final IVariable<?>[] distinctList, - final UUID masterUUID) { + /** + * The concurrency level of the {@link ConcurrentHashMap} used to impose + * the distinct constraint. + * + * @see #DEFAULT_CONCURRENCY_LEVEL + */ + String CONCURRENCY_LEVEL = DistinctElementFilter.class.getName() + + ".concurrencyLevel"; - super(distinctList, NV.asMap(new NV[] { - // new NV(Annotations.QUERY_ID, masterUUID), - // new NV(Annotations.BOP_ID, bopId) - })); + int DEFAULT_CONCURRENCY_LEVEL = 16; - if (masterUUID == null) - throw new IllegalArgumentException(); + /** + * The set of fields whose values must be distinct. + * + * @todo abstract base class to allow easy override for specific element + * types such as {@link SPO}. + */ + String FIELDS = DistinctElementFilter.class.getName() + ".fields"; + /** + * An optional constraint on the runtime type of the elements which are + * acceptable to this filter. + * + * @see IElementFilter#canAccept(Object) + * + * @todo I am not convinced that we need this. It parallels something + * which was introduced into the {@link IElementFilter} interface, + * but I suspect that we do not need that either. + */ + String CLASS_CONSTRAINT = DistinctElementFilter.class.getName() + + ".classConstraint"; + } -// public Future<Void> eval(final IBigdataFederation<?> fed, -// final IJoinNexus joinNexus, final IBlockingBuffer<E[]> buffer) { -// -// final FutureTask<Void> ft = new FutureTask<Void>(new DHTTask(joinNexus, -// buffer)); -// -// joinNexus.getIndexManager().getExecutorService().execute(ft); -// -// return ft; -// -// } + /** + * Required deep copy constructor. + */ + public DistinctElementFilter(final DistinctElementFilter<E> op) { + super(op); + } /** - * Task executing on the node. + * Required shallow copy constructor. */ - private class DHTTask implements Callable<Void> { + public DistinctElementFilter(final BOp[] args, + final Map<String, Object> annotations) { - private final IJoinNexus joinNexus; + super(args, annotations); - private final IBlockingBuffer<E[]> buffer; + final int[] fields = getFields(); - private final ConcurrentHashMap<byte[], Void> map; + if (fields == null) + throw new IllegalArgumentException(); - /* Note: This is NOT thread safe! */ - private final BindingSetSortKeyBuilder sortKeyBuilder; - - DHTTask(final IJoinNexus joinNexus, - final IBlockingBuffer<E[]> buffer) { + if (fields.length == 0) + throw new IllegalArgumentException(); - this.joinNexus = joinNexus; - - this.buffer = buffer; + } - final IVariable<?>[] vars = ((BOpList) get(0/* distinctList */)) - .toArray(new IVariable[0]); + /** + * @see Annotations#INITIAL_CAPACITY + */ + public int getInitialCapacity() { - this.sortKeyBuilder = new BindingSetSortKeyBuilder(KeyBuilder - .newInstance(), vars); + return getProperty(Annotations.INITIAL_CAPACITY, + Annotations.DEFAULT_INITIAL_CAPACITY); - this.map = new ConcurrentHashMap<byte[], Void>(/* - * @todo initialCapacity using annotations - * @todo loadFactor ... - * @todo concurrencyLevel ... - */); - } + } - private boolean accept(final IBindingSet bset) { + /** + * @see Annotations#LOAD_FACTOR + */ + public float getLoadFactor() { - return map.putIfAbsent(sortKeyBuilder.getSortKey(bset), null) == null; + return getProperty(Annotations.LOAD_FACTOR, + Annotations.DEFAULT_LOAD_FACTOR); - } + } - public Void call() throws Exception { + /** + * @see Annotations#CONCURRENCY_LEVEL + */ + public int getConcurrencyLevel() { - /* - * FIXME Setup to drain binding sets from the source. Note that the - * sort key builder is not thread safe, so a pool of key builders - * with a non-default initial capacity (LT 1024) might be used to - * allow higher concurrency for key building. - * - * Alternatively, the caller could generate the keys (SOUNDS GOOD) - * and just ship the byte[] keys to the DHTFilter. - * - * The DHTFilter needs to send back its boolean[] responses bit - * coded or run length coded. See AbstractArrayIndexProcedure which - * already does some of that. Those responses should move through - * NIO Buffers just like everything else, but the response will be - * much smaller than the incoming byte[][] (aka IRaba). - */ - throw new UnsupportedOperationException(); + return getProperty(Annotations.CONCURRENCY_LEVEL, + Annotations.DEFAULT_CONCURRENCY_LEVEL); - } + } + public int[] getFields() { + + return (int[]) getProperty(Annotations.FIELDS); + } + + public FutureTask<Void> eval(final BOpContext<IBindingSet> context) { - // public ResultBitBuffer bulkFilter(final K[] elements) { - // - // } +// return new FutureTask<Void>(new DistinctTask<E>(this, context)); + throw new UnsupportedOperationException(); + + } + public boolean accept(E e) { + // TODO Auto-generated method stub + return false; + } + + public boolean canAccept(Object o) { + // @todo by annotation giving an optional type constraint. + return true; + } + +// /** +// * Task executing on the node. +// */ +// static private class DistinctTask<E> implements Callable<Void> { +// +// private final BOpContext<IBindingSet> context; +// +// /** +// * A concurrent map whose keys are the bindings on the specified +// * variables (the keys and the values are the same since the map +// * implementation does not allow <code>null</code> values). +// */ +// private /*final*/ ConcurrentHashMap<E, E> map; +// +// /** +// * The variables used to impose a distinct constraint. +// */ +// private final int[] fields; +// +// DistinctTask(final DistinctElementFilter<E> op, +// final BOpContext<IBindingSet> context) { +// +// this.context = context; +// +// this.fields = op.getFields(); +// +// this.map = new ConcurrentHashMap<E, E>( +// op.getInitialCapacity(), op.getLoadFactor(), +// op.getConcurrencyLevel()); +// +// } +// +// /** +// * Construct an element are distinct for the configured variables then return +// * those bindings. +// * +// * @param bset +// * The binding set to be filtered. +// * +// * @return The distinct as bound values -or- <code>null</code> if the +// * binding set duplicates a solution which was already accepted. +// */ +// private E accept(final E e) { +// +// final E e2 = newElement(e); +// +// final boolean distinct = map.putIfAbsent(e2, e2) == null; +// +// return distinct ? e2 : null; +// +// } +// +// public Void call() throws Exception { +// +// final BOpStats stats = context.getStats(); +// +// final IAsynchronousIterator<IBindingSet[]> itr = context +// .getSource(); +// +// final IBlockingBuffer<IBindingSet[]> sink = context.getSink(); +// +// try { +// +// while (itr.hasNext()) { +// +// final IBindingSet[] a = itr.next(); +// +// stats.chunksIn.increment(); +// stats.unitsIn.add(a.length); +// +// final List<IBindingSet> accepted = new LinkedList<IBindingSet>(); +// +// int naccepted = 0; +// +// for (IBindingSet bset : a) { +// +//// System.err.println("considering: " + bset); +// +// final IConstant<?>[] vals = accept(bset); +// +// if (vals != null) { +// +//// System.err.println("accepted: " +//// + Arrays.toString(vals)); +// +// /* +// * @todo This may cause problems since the +// * ArrayBindingSet does not allow mutation with +// * variables not declared up front. In that case use +// * new HashBindingSet( new ArrayBindingSet(...)). +// */ +// +// accepted.add(new ArrayBindingSet(vars, vals)); +// +// naccepted++; +// +// } +// +// } +// +// if (naccepted > 0) { +// +// final IBindingSet[] b = accepted +// .toArray(new IBindingSet[naccepted]); +// +//// System.err.println("output: " +//// + Arrays.toString(b)); +// +// sink.add(b); +// +// stats.unitsOut.add(naccepted); +// stats.chunksOut.increment(); +// +// } +// +// } +// +// // done. +// return null; +// +// } finally { +// +// sink.flush(); +// sink.close(); +// +// // discard the map. +// map = null; +// +// } +// +// } +// +// } + } Deleted: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/ap/Union.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/ap/Union.java 2010-09-02 13:49:55 UTC (rev 3494) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/ap/Union.java 2010-09-02 18:52:36 UTC (rev 3495) @@ -1,139 +0,0 @@ -/** - -Copyright (C) SYSTAP, LLC 2006-2010. 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 Aug 18, 2010 - */ - -package com.bigdata.bop.ap; - -import java.util.Map; - -import com.bigdata.bop.AbstractChunkedOrderedIteratorOp; -import com.bigdata.bop.BOp; -import com.bigdata.bop.ChunkedOrderedIteratorOp; -import com.bigdata.bop.IPredicate; -import com.bigdata.bop.engine.MapBindingSetsOverShards; -import com.bigdata.rdf.rules.TMUtility; -import com.bigdata.relation.RelationFusedView; -import com.bigdata.relation.rule.eval.IJoinNexus; -import com.bigdata.service.IBigdataFederation; -import com.bigdata.service.proxy.IRemoteChunkedIterator; -import com.bigdata.striterator.ChunkedOrderedStriterator; -import com.bigdata.striterator.IChunkedOrderedIterator; -import com.ibm.icu.impl.ByteBuffer; - -/** - * An operator which returns the union of two {@link IPredicate}s. Elements are - * consumed first from the left predicate and then from the right predicate. - * This operator does not cross network boundaries. An intermediate send / - * receive operator pattern must be applied when this operator is used in a - * scale-out context. - * - * @author <a href="mailto:tho...@us...">Bryan Thompson</a> - * @version $Id$ - * - * @todo I have some basic questions about the ability to use a UNION of two - * predicates in scale-out. I think that this might be more accurately - * modeled as the UNION of two joins. That is, rather than: - * - * <pre> - * JOIN( ..., - * UNION( foo.spo(A,loves,B), - * bar.spo(A,loves,B) ) - * ) - * </pre> - * using - * <pre> - * UNION( JOIN( ..., foo.spo(A,loves,B) ), - * JOIN( ..., bar.spo(A,loves,B) ) - * ) - * </pre> - * which would be a binding set union rather than an element union. - * - * @todo This was historically handled by {@link RelationFusedView} which should - * be removed when this class is implemented. - * - * @todo The {@link TMUtility} will have to be updated to use this operator - * rather than specifying multiple source "names" for the relation of the - * predicate. - * - * @todo The FastClosureRuleTask will also need to be updated to use a - * {@link Union} rather than a {@link RelationFusedView}. - * - * @todo It would be a trivial generalization to make this an N-ary union. - * - * @todo A similar operator could be defined where child operands to execute - * concurrently and the result is no longer strongly ordered. - * - * @todo Implement the send/receive pattern. - * <p> - * This COULD be done using {@link IRemoteChunkedIterator} if the send and - * receive operators are appropriately decorated in order to pass the - * proxy object along. - * <p> - * This SHOULD be implemented using an NIO direct {@link ByteBuffer} - * pattern similar to {@link MapBindingSetsOverShards}. - */ -public class Union<E> extends AbstractChunkedOrderedIteratorOp<E> { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * @param left - * @param rigtht - * @param annotations - */ - public Union(final ChunkedOrderedIteratorOp<E> left, - final ChunkedOrderedIteratorOp<E> right, - final Map<String, Object> annotations) { - - super(new BOp[] { left, right }, annotations); - - } - - @SuppressWarnings("unchecked") - protected ChunkedOrderedIteratorOp<E> left() { - return (ChunkedOrderedIteratorOp<E>)get(0); - } - - @SuppressWarnings("unchecked") - protected ChunkedOrderedIteratorOp<E> right() { - return (ChunkedOrderedIteratorOp<E>)get(1); - } - - @SuppressWarnings("unchecked") - public IChunkedOrderedIterator<E> eval(final IBigdataFederation<?> fed, - final IJoinNexus joinNexus) { - - return (IChunkedOrderedIterator<E>) new ChunkedOrderedStriterator<IChunkedOrderedIterator<E>, E>(// - left().eval(fed, joinNexus)).append(// - right().eval(fed, joinNexus)// - ); - - } - -} Added: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/BOpConstraint.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/BOpConstraint.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/BOpConstraint.java 2010-09-02 18:52:36 UTC (rev 3495) @@ -0,0 +1,66 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2010. 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 2, 2010 + */ + +package com.bigdata.bop.constraint; + +import java.util.Map; + +import com.bigdata.bop.BOp; +import com.bigdata.bop.BOpBase; +import com.bigdata.bop.IConstraint; + +/** + * Abstract base class for constraint operators. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + */ +abstract public class BOpConstraint extends BOpBase implements IConstraint { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Required deep copy constructor. + * @param op + */ + public BOpConstraint(BOpBase op) { + super(op); + } + + /** + * Required shallow copy constructor. + * @param args + * @param annotations + */ + public BOpConstraint(BOp[] args, Map<String, Object> annotations) { + super(args, annotations); + } + +} Property changes on: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/BOpConstraint.java ___________________________________________________________________ Added: svn:keywords + Id Date Revision Author HeadURL Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/EQ.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/EQ.java 2010-09-02 13:49:55 UTC (rev 3494) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/EQ.java 2010-09-02 18:52:36 UTC (rev 3495) @@ -26,11 +26,9 @@ import java.util.Map; -import com.bigdata.bop.BOpBase; import com.bigdata.bop.BOp; import com.bigdata.bop.IBindingSet; import com.bigdata.bop.IConstant; -import com.bigdata.bop.IConstraint; import com.bigdata.bop.IVariable; /** @@ -39,7 +37,7 @@ * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ */ -public class EQ extends BOpBase implements IConstraint { +public class EQ extends BOpConstraint { private static final long serialVersionUID = 1L; Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/EQConstant.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/EQConstant.java 2010-09-02 13:49:55 UTC (rev 3494) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/EQConstant.java 2010-09-02 18:52:36 UTC (rev 3495) @@ -26,11 +26,9 @@ import java.util.Map; -import com.bigdata.bop.BOpBase; import com.bigdata.bop.BOp; import com.bigdata.bop.IBindingSet; import com.bigdata.bop.IConstant; -import com.bigdata.bop.IConstraint; import com.bigdata.bop.IVariable; /** @@ -39,7 +37,7 @@ * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ */ -public class EQConstant extends BOpBase implements IConstraint { +public class EQConstant extends BOpConstraint { /** * @@ -62,7 +60,7 @@ public EQConstant(final IVariable<?> var, final IConstant<?> val) { - super(new BOp[] { var, val }); + super(new BOp[] { var, val }, null/*annotations*/); if (var == null) throw new IllegalArgumentException(); Deleted: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/IN.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/IN.java 2010-09-02 13:49:55 UTC (rev 3494) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/IN.java 2010-09-02 18:52:36 UTC (rev 3495) @@ -1,197 +0,0 @@ -/** - -The Notice below must appear in each file of the Source Code of any -copy you distribute of the Licensed Product. Contributors to any -Modifications may add their own copyright notices to identify their -own contributions. - -License: - -The contents of this file are subject to the CognitiveWeb Open Source -License Version 1.1 (the License). You may not copy or use this file, -in either source code or executable form, except in compliance with -the License. You may obtain a copy of the License from - - http://www.CognitiveWeb.org/legal/license/ - -Software distributed under the License is distributed on an AS IS -basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -the License for the specific language governing rights and limitations -under the License. - -Copyrights: - -Portions created by or assigned to CognitiveWeb are Copyright -(c) 2003-2003 CognitiveWeb. All Rights Reserved. Contact -information for CognitiveWeb is available at - - http://www.CognitiveWeb.org - -Portions Copyright (c) 2002-2003 Bryan Thompson. - -Acknowledgements: - -Special thanks to the developers of the Jabber Open Source License 1.0 -(JOSL), from which this License was derived. This License contains -terms that differ from JOSL. - -Special thanks to the CognitiveWeb Open Source Contributors for their -suggestions and support of the Cognitive Web. - -Modifications: - -*/ -/* - * Created on Jun 17, 2008 - */ - -package com.bigdata.bop.constraint; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Map; - -import com.bigdata.bop.BOpBase; -import com.bigdata.bop.BOp; -import com.bigdata.bop.BOpList; -import com.bigdata.bop.IBindingSet; -import com.bigdata.bop.IConstant; -import com.bigdata.bop.IConstraint; -import com.bigdata.bop.IVariable; -import com.bigdata.rdf.spo.InGraphBinarySearchFilter; -import com.bigdata.rdf.spo.InGraphHashSetFilter; - -/** - * A constraint that a variable may only take on the bindings enumerated by some - * set. - * - * @author <a href="mailto:tho...@us...">Bryan Thompson</a> - * @version $Id$ - * - * @todo This uses binary search, which is thread-safe. It could also use a - * {@link HashSet}, but the {@link HashSet} needs to be thread-safe since - * the filter could be applied concurrently during evaluation. - * - * FIXME Reconcile this with {@link InGraphBinarySearchFilter} and - * {@link InGraphHashSetFilter} and also with the use of an in-memory join - * against the incoming binding sets to handle SPARQL data sets. - */ -public class IN<T> extends BOpBase implements IConstraint { - -// /** -// * -// */ -// private static final long serialVersionUID = 5805883429399100605L; -// -// private final IVariable<T> x; -// -// private final T[] set; - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * The sorted data (cached). - * <p> - * Note: This cache is redundant with the 2nd argument to the operator. It - * is not serialized and is compiled on demand when the operator is used. - */ - private transient volatile T[] set; - - /** - * Deep copy constructor. - */ - public IN(final IN<T> op) { - super(op); - } - - /** - * Shallow copy constructor. - */ - public IN(final BOp[] args, final Map<String, Object> annotations) { - - // @todo validate args? - super(args, annotations); - - } - - /** - * - * @param x - * Some variable. - * @param set - * A set of legal term identifiers providing a constraint on the - * allowable values for that variable. - */ - public IN(final IVariable<T> x, final IConstant<T>[] set) { - - super(new BOp[] { x, new BOpList(set) }); - - if (x == null || set == null) - throw new IllegalArgumentException(); - - if (set.length == 0) - throw new IllegalArgumentException(); - - } - - @SuppressWarnings("unchecked") - static private <T> T[] sort(final BOpList set) { - - final int n = set.arity(); - - if (n == 0) - throw new IllegalArgumentException(); - - final T firstValue = ((IConstant<T>) set.get(0)).get(); - - // allocate an array of the correct type. - final T[] tmp = (T[]) java.lang.reflect.Array.newInstance(firstValue - .getClass(), n); - - for (int i = 0; i < n; i++) { - - // dereference the constants to their bound values. - tmp[i] = ((IConstant<T>) set.get(i)).get(); - - } - - // sort the bound values. - Arrays.sort(tmp); - - return tmp; - - } - - public boolean accept(final IBindingSet bindingSet) { - - if(set == null) { - - set = sort((BOpList) get(1)); - - } - - // get binding for "x". - @SuppressWarnings("unchecked") - final IConstant<T> x = bindingSet.get((IVariable<?>) get(0)/* x */); - - if (x == null) { - - // not yet bound. - return true; - - } - - final T v = x.get(); - - // lookup the bound value in the set of values. - final int pos = Arrays.binarySearch(set, v); - - // true iff the bound value was found in the set. - return pos >= 0; - - } - -} Copied: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/INBinarySearch.java (from rev 3466, branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/IN.java) =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/INBinarySearch.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/INBinarySearch.java 2010-09-02 18:52:36 UTC (rev 3495) @@ -0,0 +1,201 @@ +/** + +The Notice below must appear in each file of the Source Code of any +copy you distribute of the Licensed Product. Contributors to any +Modifications may add their own copyright notices to identify their +own contributions. + +License: + +The contents of this file are subject to the CognitiveWeb Open Source +License Version 1.1 (the License). You may not copy or use this file, +in either source code or executable form, except in compliance with +the License. You may obtain a copy of the License from + + http://www.CognitiveWeb.org/legal/license/ + +Software distributed under the License is distributed on an AS IS +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +the License for the specific language governing rights and limitations +under the License. + +Copyrights: + +Portion... [truncated message content] |