This list is closed, nobody may subscribe to it.
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(139) |
Aug
(94) |
Sep
(232) |
Oct
(143) |
Nov
(138) |
Dec
(55) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2011 |
Jan
(127) |
Feb
(90) |
Mar
(101) |
Apr
(74) |
May
(148) |
Jun
(241) |
Jul
(169) |
Aug
(121) |
Sep
(157) |
Oct
(199) |
Nov
(281) |
Dec
(75) |
2012 |
Jan
(107) |
Feb
(122) |
Mar
(184) |
Apr
(73) |
May
(14) |
Jun
(49) |
Jul
(26) |
Aug
(103) |
Sep
(133) |
Oct
(61) |
Nov
(51) |
Dec
(55) |
2013 |
Jan
(59) |
Feb
(72) |
Mar
(99) |
Apr
(62) |
May
(92) |
Jun
(19) |
Jul
(31) |
Aug
(138) |
Sep
(47) |
Oct
(83) |
Nov
(95) |
Dec
(111) |
2014 |
Jan
(125) |
Feb
(60) |
Mar
(119) |
Apr
(136) |
May
(270) |
Jun
(83) |
Jul
(88) |
Aug
(30) |
Sep
(47) |
Oct
(27) |
Nov
(23) |
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(3) |
Oct
|
Nov
|
Dec
|
2016 |
Jan
|
Feb
|
Mar
(4) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <tho...@us...> - 2011-02-25 21:18:07
|
Revision: 4250 http://bigdata.svn.sourceforge.net/bigdata/?rev=4250&view=rev Author: thompsonbry Date: 2011-02-25 21:18:01 +0000 (Fri, 25 Feb 2011) Log Message: ----------- Modified Haltable#halted() to use the message "Halted" in the thrown RuntimeException as this is a normal halt. Modified PipelineJoin to log normal termination @ DEBUG. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/join/PipelineJoin.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/util/concurrent/Haltable.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/join/PipelineJoin.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/join/PipelineJoin.java 2011-02-24 23:15:17 UTC (rev 4249) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/join/PipelineJoin.java 2011-02-25 21:18:01 UTC (rev 4250) @@ -592,6 +592,9 @@ /** * An optional limit on the #of solutions to be produced. The limit is * ignored if it is {@link Long#MAX_VALUE}. + * <p> + * Note: Invoking {@link #halt(Object)} is necessary to enforce the + * limit. * * @see Annotations#LIMIT */ @@ -1094,8 +1097,10 @@ throw new RuntimeException("Halting join: " + t, t); } // normal termination - ignore exception. - log.warn("Caught and ignored exception: "+t); return null; - + if (log.isDebugEnabled()) + log.debug("Caught and ignored exception: " + t); + return null; + } } @@ -1632,7 +1637,7 @@ log.info("Breaking query @ limit: limit=" + limit + ", exactOutputCount=" + exactOutputCount.get()); -// halt((Void) null); + halt((Void) null); return null; } @@ -1677,10 +1682,14 @@ while (itr.hasNext()) { + halted(); + final Object[] chunk = itr.nextChunk(); - stats.accessPathChunksIn.increment(); + stats.accessPathChunksIn.increment(); +// System.err.println("#chunks="+stats.accessPathChunksIn+", chunkSize="+chunk.length); + // process the chunk in the caller's thread. new ChunkTask(bindingSets, naccepted, unsyncBuffer, chunk).call(); @@ -1727,7 +1736,7 @@ log.info("Breaking query @ limit: limit=" + limit + ", exactOutputCount=" + exactOutputCount.get()); -// halt((Void) null); + halt((Void) null); break; } @@ -1947,7 +1956,7 @@ log.info("Breaking query @ limit: limit=" + limit + ", exactOutputCount=" + exactOutputCount.get()); -// halt((Void) null); + halt((Void) null); break; } @@ -2145,7 +2154,7 @@ log.info("Breaking query @ limit: limit=" + limit + ", exactOutputCount=" + exactOutputCount.get()); -// halt((Void) null); + halt((Void) null); break; } Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/util/concurrent/Haltable.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/util/concurrent/Haltable.java 2011-02-24 23:15:17 UTC (rev 4249) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/util/concurrent/Haltable.java 2011-02-25 21:18:01 UTC (rev 4250) @@ -205,7 +205,7 @@ * running (since it invoked halted() it must be running). Since * it is running, */ - throw new RuntimeException(); + throw new RuntimeException("Halted"); } throw new RuntimeException(firstCause); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mrp...@us...> - 2011-02-24 23:15:23
|
Revision: 4249 http://bigdata.svn.sourceforge.net/bigdata/?rev=4249&view=rev Author: mrpersonick Date: 2011-02-24 23:15:17 +0000 (Thu, 24 Feb 2011) Log Message: ----------- fixed constraint attachment Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/PartitionedJoinGroup.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/PartitionedJoinGroup.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/PartitionedJoinGroup.java 2011-02-24 23:11:18 UTC (rev 4248) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/PartitionedJoinGroup.java 2011-02-24 23:15:17 UTC (rev 4249) @@ -341,31 +341,44 @@ continue; } - /* - * true iff all variables used by this constraint are bound - * at this point in the join path. - */ - boolean allVarsBound = true; - - // visit the variables used by this constraint. - final Iterator<IVariable<?>> vitr = BOpUtility - .getSpannedVariables(c); - - while (vitr.hasNext()) { - - final IVariable<?> var = vitr.next(); - - if (!boundVars.contains(var)) { - - allVarsBound = false; - - break; - - } - + boolean attach = false; + + if (i == path.length-1) { + + // attach all unused constraints to last predicate + attach = true; + + } else { + + /* + * true iff all variables used by this constraint are bound + * at this point in the join path. + */ + boolean allVarsBound = true; + + // visit the variables used by this constraint. + final Iterator<IVariable<?>> vitr = BOpUtility + .getSpannedVariables(c); + + while (vitr.hasNext()) { + + final IVariable<?> var = vitr.next(); + + if (!boundVars.contains(var)) { + + allVarsBound = false; + + break; + + } + + } + + attach = allVarsBound; + } - if (allVarsBound) { + if (attach) { /* * All variables have become bound for this constraint, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mrp...@us...> - 2011-02-24 23:11:24
|
Revision: 4248 http://bigdata.svn.sourceforge.net/bigdata/?rev=4248&view=rev Author: mrpersonick Date: 2011-02-24 23:11:18 +0000 (Thu, 24 Feb 2011) Log Message: ----------- fixed constraint attachment Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/PartitionedJoinGroup.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/sop/SOpTreeBuilder.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/PartitionedJoinGroup.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/PartitionedJoinGroup.java 2011-02-24 23:10:42 UTC (rev 4247) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/PartitionedJoinGroup.java 2011-02-24 23:11:18 UTC (rev 4248) @@ -217,6 +217,13 @@ } + static public IConstraint[][] getJoinGraphConstraints( + final IPredicate<?>[] path, final IConstraint[] joinGraphConstraints) { + + return getJoinGraphConstraints(path, joinGraphConstraints, null); + + } + /** * Given a join path, return the set of constraints to be associated with * each join in that join path. Only those constraints whose variables are @@ -226,6 +233,9 @@ * The join path. * @param joinGraphConstraints * The constraints to be applied to the join path (optional). + * @param knownBoundVars + * Variables that are known to be bound as inputs to this + * join graph (parent queries). * * @return The constraints to be paired with each element of the join path. * @@ -250,7 +260,9 @@ * FIXME Unit tests. */ static public IConstraint[][] getJoinGraphConstraints( - final IPredicate<?>[] path, final IConstraint[] joinGraphConstraints) { + final IPredicate<?>[] path, + final IConstraint[] joinGraphConstraints, + final IVariable<?>[] knownBoundVars) { if (path == null) throw new IllegalArgumentException(); @@ -260,7 +272,16 @@ // the set of constraints for each predicate in the join path. final IConstraint[][] ret = new IConstraint[path.length][]; + + // the set of variables which are bound. + final Set<IVariable<?>> boundVars = new LinkedHashSet<IVariable<?>>(); + // add the already known bound vars + if (knownBoundVars != null) { + for (IVariable<?> v : knownBoundVars) + boundVars.add(v); + } + /* * For each predicate in the path in the given order, figure out which * constraint(s) would attach to that predicate based on which variables @@ -268,9 +289,6 @@ * given join path, we return that set of constraints. */ - // the set of variables which are bound. - final Set<IVariable<?>> boundVars = new LinkedHashSet<IVariable<?>>(); - // the set of constraints which have been consumed. final Set<IConstraint> used = new LinkedHashSet<IConstraint>(); 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-02-24 23:10:42 UTC (rev 4247) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/Rule2BOpUtility.java 2011-02-24 23:11:18 UTC (rev 4248) @@ -70,6 +70,7 @@ import com.bigdata.bop.engine.QueryEngine; import com.bigdata.bop.join.PipelineJoin; import com.bigdata.bop.joinGraph.IRangeCountFactory; +import com.bigdata.bop.joinGraph.PartitionedJoinGroup; import com.bigdata.bop.joinGraph.fast.DefaultEvaluationPlan2; import com.bigdata.bop.rdf.filter.StripContextFilter; import com.bigdata.bop.rdf.join.DataSetJoin; @@ -327,13 +328,16 @@ final AtomicInteger idFactory, final AbstractTripleStore db, final QueryEngine queryEngine, final Properties queryHints) { - return convert(rule, null/* conditionals */, idFactory, db, queryEngine, - queryHints); + return convert(rule, + null/* conditionals */, + null/* known bound variables */, + idFactory, db, queryEngine, queryHints); } public static PipelineOp convert(final IRule<?> rule, final Collection<IConstraint> conditionals, + final Set<IVariable<?>> knownBound, final AtomicInteger idFactory, final AbstractTripleStore db, final QueryEngine queryEngine, final Properties queryHints) { @@ -514,43 +518,6 @@ // final IVariable<?>[][] selectVars = RuleState // .computeRequiredVarsForEachTail(rule, order); - /* - * Map the constraints from the variables they use. This way, we can - * properly attach constraints to only the first tail in which the - * variable appears. This way we only run the appropriate constraint - * once, instead of for every tail. - */ -// final Map<IVariable<?>, Collection<IConstraint>> constraintsByVar = -// new HashMap<IVariable<?>, Collection<IConstraint>>(); -// for (int i = 0; i < rule.getConstraintCount(); i++) { -// final IConstraint c = rule.getConstraint(i); -// -// if (log.isDebugEnabled()) { -// log.debug(c); -// } -// -// final Set<IVariable<?>> uniqueVars = new HashSet<IVariable<?>>(); -// final Iterator<IVariable<?>> vars = BOpUtility.getSpannedVariables(c); -// while (vars.hasNext()) { -// final IVariable<?> v = vars.next(); -// uniqueVars.add(v); -// } -// -// for (IVariable<?> v : uniqueVars) { -// -// if (log.isDebugEnabled()) { -// log.debug(v); -// } -// -// Collection<IConstraint> constraints = constraintsByVar.get(v); -// if (constraints == null) { -// constraints = new LinkedList<IConstraint>(); -// constraintsByVar.put(v, constraints); -// } -// constraints.add(c); -// } -// } - PipelineOp left = startOp; if (conditionals != null) { // @todo lift into CONDITION on SubqueryOp @@ -602,102 +569,40 @@ } -// /* -// * Analyze the predicates and constraints to decide which constraints -// * will run with which predicates. @todo does not accept known bound -// * variables yet and does not report on the constraint attachment for -// * optional joins using the same assignedConstraint[] (which makes the -// * integration a bit more complicated). -// */ -// final IConstraint[][] assignedConstraints; -//// final PartitionedJoinGroup g; -// { -// // Extract IConstraint[] from the rule. -// final IConstraint[] constraints = new IConstraint[rule.getConstraintCount()]; -// for(int i=0; i<constraints.length; i++) { -// constraints[i] = rule.getConstraint(i); -// } -// -//// // Analyze the join graph. -//// g = new PartitionedJoinGroup(preds, constraints); -// -// // figure out which constraints are attached to which predicates. -// assignedConstraints = PartitionedJoinGroup.getJoinGraphConstraints( -// preds, constraints); -// } + /* + * Analyze the predicates and constraints to decide which constraints + * will run with which predicates. @todo does not handle optionals + * correctly, but we do not pass optionals in to Rule2BOpUtility + * from SOp2BOpUtility anymore so ok for now + */ + final IConstraint[][] assignedConstraints; + { + // Extract IConstraint[] from the rule. + final IConstraint[] constraints = new IConstraint[rule.getConstraintCount()]; + for(int i=0; i<constraints.length; i++) { + constraints[i] = rule.getConstraint(i); + } + + // figure out which constraints are attached to which predicates. + assignedConstraints = PartitionedJoinGroup.getJoinGraphConstraints( + preds, constraints, + knownBound.toArray(new IVariable<?>[knownBound.size()])); + } /* * */ - for (int i = 0; i < order.length; i++) { + for (int i = 0; i < preds.length; i++) { // assign a bop id to the predicate final Predicate<?> pred = (Predicate<?>) preds[i]; - // @todo Life will be simple once assignedConstraints is ready. -// left = join(queryEngine, left, pred,// -// Arrays.asList(assignedConstraints[i]), // -// context, idFactory, queryHints); + left = join(queryEngine, left, pred,// + Arrays.asList(assignedConstraints[i]), // + context, idFactory, queryHints); - /* - * Collect all the constraints for this predicate based on which - * variables make their first appearance in this tail - */ - final Collection<IConstraint> constraints = - new LinkedList<IConstraint>(); - -// /* -// * Peek through the predicate's args to find its variables. Use -// * these to attach constraints to the join based on the variables -// * that make their first appearance in this tail. -// */ -// for (BOp arg : pred.args()) { -// if (arg instanceof IVariable<?>) { -// final IVariable<?> v = (IVariable<?>) arg; -// /* -// * We do a remove because we don't ever need to run these -// * constraints again during subsequent joins once they have -// * been run once at the initial appearance of the variable. -// * -// * @todo revisit this when we dynamically re-order running -// * joins -// */ -// if (constraintsByVar.containsKey(v)) -// constraints.addAll(constraintsByVar.remove(v)); -// } -// } - - // just add all the constraints to the very last tail for now - if (i == (order.length-1) && rule.getConstraintCount() > 0) { - final Iterator<IConstraint> it = rule.getConstraints(); - while (it.hasNext()) { - constraints.add(it.next()); - } - } - - left = join(queryEngine, left, pred, constraints, context, - idFactory, queryHints); - } -// if (rule.getConstraintCount() > 0) { -// final Iterator<IConstraint> it = rule.getConstraints(); -// while (it.hasNext()) { -// final IConstraint c = it.next(); -// final int condId = idFactory.incrementAndGet(); -// final PipelineOp condOp = applyQueryHints( -// new ConditionalRoutingOp(new BOp[]{left}, -// NV.asMap(new NV[]{// -// new NV(BOp.Annotations.BOP_ID,condId), -// new NV(ConditionalRoutingOp.Annotations.CONDITION, c), -// })), queryHints); -// left = condOp; -// if (log.isDebugEnabled()) { -// log.debug("adding conditional routing op: " + condOp); -// } -// } -// } - if (log.isInfoEnabled()) { // just for now while i'm debugging log.info("rule=" + rule + ":::query=" 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-02-24 23:10:42 UTC (rev 4247) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/sop/SOp2BOpUtility.java 2011-02-24 23:11:18 UTC (rev 4248) @@ -189,10 +189,11 @@ final Collection<IConstraint> postConditionals = new LinkedList<IConstraint>(); - final IRule rule = rule(join, preConditionals, postConditionals); + PipelineOp left = rule2BOp(join, preConditionals, postConditionals, + idFactory, db, queryEngine, queryHints); - PipelineOp left = Rule2BOpUtility.convert( - rule, preConditionals, idFactory, db, queryEngine, queryHints); +// PipelineOp left = Rule2BOpUtility.convert( +// rule, preConditionals, idFactory, db, queryEngine, queryHints); /* * Start with left=<this join group> and add a SubqueryOp for each @@ -229,14 +230,14 @@ if (!isUnion(child) || isEmptyUnion(child)) continue; + final boolean optional = isOptional(child); final PipelineOp subquery = union( child, idFactory, db, queryEngine, queryHints); - final boolean optional = isOptional(child); final int subqueryId = idFactory.incrementAndGet(); left = new SubqueryOp(new BOp[]{left}, new NV(Predicate.Annotations.BOP_ID, subqueryId),// new NV(SubqueryOp.Annotations.SUBQUERY, subquery),// - new NV(SubqueryOp.Annotations.OPTIONAL,optional)// + new NV(SubqueryOp.Annotations.OPTIONAL, optional)// ); if (log.isInfoEnabled()) { log.info("adding a subquery: " + subqueryId + "\n" + left); @@ -358,9 +359,11 @@ } - protected static IRule rule(final SOpGroup group, + protected static PipelineOp rule2BOp(final SOpGroup group, final Collection<IConstraint> preConditionals, - final Collection<IConstraint> postConditionals) { + final Collection<IConstraint> postConditionals, + final AtomicInteger idFactory, final AbstractTripleStore db, + final QueryEngine queryEngine, final Properties queryHints) { final Collection<IPredicate> preds = new LinkedList<IPredicate>(); final Collection<IConstraint> constraints = new LinkedList<IConstraint>(); @@ -504,7 +507,11 @@ null/* constants */, null/* taskFactory */, required); - return rule; + final PipelineOp left = Rule2BOpUtility.convert( + rule, preConditionals, nonOptParentVars, + idFactory, db, queryEngine, queryHints); + + return left; } Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/sop/SOpTreeBuilder.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/sop/SOpTreeBuilder.java 2011-02-24 23:10:42 UTC (rev 4247) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/sop/SOpTreeBuilder.java 2011-02-24 23:11:18 UTC (rev 4248) @@ -172,6 +172,8 @@ collectSOps(sops, (Join) left, rslj, g, pg); } else if (left instanceof LeftJoin) { collectSOps(sops, (LeftJoin) left, rslj, groupId.incrementAndGet(), g); + } else if (left instanceof Union) { + collectSOps(sops, (Union) left, rslj, groupId.incrementAndGet(), g); } else { throw new UnsupportedOperatorException(left); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mrp...@us...> - 2011-02-24 23:10:49
|
Revision: 4247 http://bigdata.svn.sourceforge.net/bigdata/?rev=4247&view=rev Author: mrpersonick Date: 2011-02-24 23:10:42 +0000 (Thu, 24 Feb 2011) Log Message: ----------- changed how describe is optimized Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailGraphQuery.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestDescribe.java 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-02-24 20:33:29 UTC (rev 4246) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailGraphQuery.java 2011-02-24 23:10:42 UTC (rev 4247) @@ -10,6 +10,8 @@ import java.util.LinkedList; import java.util.Properties; import java.util.Set; + +import org.apache.log4j.Logger; import org.openrdf.model.Resource; import org.openrdf.model.Statement; import org.openrdf.model.URI; @@ -46,6 +48,8 @@ public class BigdataSailGraphQuery extends SailGraphQuery implements BigdataSailQuery { + protected static Logger log = Logger.getLogger(BigdataSailGraphQuery.class); + /** * Query hints are embedded in query strings as namespaces. * See {@link QueryHints#NAMESPACE} for more information. @@ -74,8 +78,10 @@ protected void optimizeDescribe() { try { - ParsedQuery parsedQuery = getParsedQuery(); + ParsedQuery parsedQuery = getParsedQuery(); TupleExpr node = parsedQuery.getTupleExpr(); + if (log.isInfoEnabled()) + log.info(node); node = ((Reduced) node).getArg(); node = ((Projection) node).getArg(); ValueExpr ve = ((Filter) node).getCondition(); @@ -90,7 +96,7 @@ vars.add(var); } }); - Collection<Join> joins = new LinkedList<Join>(); + Collection<StatementPattern> sps = new LinkedList<StatementPattern>(); Collection<ProjectionElemList> projElemLists = new LinkedList<ProjectionElemList>(); for (Var v : vars) { @@ -98,7 +104,7 @@ Var p = createAnonVar("-p" + v.getName() + "-1"); Var o = createAnonVar("-o" + v.getName()); StatementPattern sp = new StatementPattern(v, p, o); - joins.add(new Join(node, sp)); + sps.add(sp); ProjectionElemList projElemList = new ProjectionElemList(); projElemList.addElement(new ProjectionElem(v.getName(), "subject")); projElemList.addElement(new ProjectionElem(p.getName(), "predicate")); @@ -109,7 +115,7 @@ Var s = createAnonVar("-s" + v.getName()); Var p = createAnonVar("-p" + v.getName() + "-2"); StatementPattern sp = new StatementPattern(s, p, v); - joins.add(new Join(node, sp)); + sps.add(sp); ProjectionElemList projElemList = new ProjectionElemList(); projElemList.addElement(new ProjectionElem(s.getName(), "subject")); projElemList.addElement(new ProjectionElem(p.getName(), "predicate")); @@ -117,12 +123,12 @@ projElemLists.add(projElemList); } } - Iterator<Join> it = joins.iterator(); - node = it.next(); + Iterator<StatementPattern> it = sps.iterator(); + Union union = new Union(it.next(), it.next()); while (it.hasNext()) { - Join j = it.next(); - node = new Union(j, node); + union = new Union(union, it.next()); } + node = new Join(node, union); node = new MultiProjection(node, projElemLists); node = new Reduced(node); parsedQuery.setTupleExpr(node); Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestDescribe.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestDescribe.java 2011-02-24 20:33:29 UTC (rev 4246) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestDescribe.java 2011-02-24 23:10:42 UTC (rev 4247) @@ -23,9 +23,9 @@ package com.bigdata.rdf.sail; -import java.util.Collection; -import java.util.LinkedList; import java.util.Properties; + +import org.apache.log4j.Logger; import org.openrdf.model.Literal; import org.openrdf.model.Statement; import org.openrdf.model.URI; @@ -33,16 +33,15 @@ import org.openrdf.model.impl.URIImpl; import org.openrdf.model.vocabulary.RDF; import org.openrdf.model.vocabulary.RDFS; -import org.openrdf.query.Binding; import org.openrdf.query.BindingSet; -import org.openrdf.query.GraphQuery; import org.openrdf.query.GraphQueryResult; import org.openrdf.query.QueryLanguage; import org.openrdf.query.TupleQuery; import org.openrdf.query.TupleQueryResult; import org.openrdf.query.algebra.TupleExpr; -import org.openrdf.query.impl.BindingImpl; + import com.bigdata.rdf.axioms.NoAxioms; +import com.bigdata.rdf.store.BD; import com.bigdata.rdf.vocab.NoVocabulary; /** @@ -51,6 +50,8 @@ */ public class TestDescribe extends ProxyBigdataSailTestCase { + protected static Logger log = Logger.getLogger(TestDescribe.class); + @Override public Properties getProperties() { @@ -90,15 +91,21 @@ try { - URI mike = new URIImpl("_:Mike"); - URI person = new URIImpl("_:Person"); - URI likes = new URIImpl("_:likes"); - URI rdf = new URIImpl("_:RDF"); - Literal label = new LiteralImpl("Mike"); + URI mike = new URIImpl(BD.NAMESPACE+"Mike"); + URI bryan = new URIImpl(BD.NAMESPACE+"Bryan"); + URI person = new URIImpl(BD.NAMESPACE+"Person"); + URI likes = new URIImpl(BD.NAMESPACE+"likes"); + URI rdf = new URIImpl(BD.NAMESPACE+"RDF"); + URI rdfs = new URIImpl(BD.NAMESPACE+"RDFS"); + Literal label1 = new LiteralImpl("Mike"); + Literal label2 = new LiteralImpl("Bryan"); /**/ cxn.add(mike, RDF.TYPE, person); cxn.add(mike, likes, rdf); - cxn.add(mike, RDFS.LABEL, label); + cxn.add(mike, RDFS.LABEL, label1); + cxn.add(bryan, RDF.TYPE, person); + cxn.add(bryan, likes, rdfs); + cxn.add(bryan, RDFS.LABEL, label2); /**/ /* @@ -116,11 +123,21 @@ { String query = -// "describe ?x " + -// "WHERE { " + -// " ?x <"+RDF.TYPE+"> <"+person+"> . " + -// "}"; - "describe <"+mike+">"; + "prefix bd: <"+BD.NAMESPACE+"> " + + "prefix rdf: <"+RDF.NAMESPACE+"> " + + "prefix rdfs: <"+RDFS.NAMESPACE+"> " + + + "describe ?x " + + "WHERE { " + +// " { " + + " ?x rdf:type bd:Person . " + + " ?x bd:likes bd:RDF " + +// " } union { " + +// " ?x rdf:type bd:Person . " + +// " ?x bd:likes bd:RDFS " + +// " } " + + "}"; +// "describe <"+mike+">"; // "construct { " + // " <"+mike+"> ?p1 ?o . " + // " ?s ?p2 <"+mike+"> . " + @@ -158,25 +175,28 @@ GraphQueryResult result = graphQuery.evaluate(); final TupleExpr tupleExpr = graphQuery.getTupleExpr(); - System.err.println(tupleExpr); + log.info(tupleExpr); while(result.hasNext()) { Statement s = result.next(); - System.err.println(s); + log.info(s); } } { String query = - "construct { " + - " ?x ?px1 ?ox . " + - " ?sx ?px2 ?x . " + + "construct { " + + " ?x ?p1 ?o . " + + " ?s ?p2 ?x . " + "} " + "WHERE { " + " ?x <"+RDF.TYPE+"> <"+person+"> . " + - " OPTIONAL { ?x ?px1 ?ox . } . " + - " OPTIONAL { ?sx ?px2 ?x . } . " + + " {" + + " ?x ?p1 ?ox . " + + " } UNION {" + + " ?sx ?p2 ?x . " + + " } " + "}"; /* @@ -204,11 +224,11 @@ GraphQueryResult result = graphQuery.evaluate(); final TupleExpr tupleExpr = graphQuery.getTupleExpr(); - System.err.println(tupleExpr); + log.info(tupleExpr); while(result.hasNext()) { Statement s = result.next(); - System.err.println(s); + log.info(s); } } @@ -295,148 +315,15 @@ GraphQueryResult result = graphQuery.evaluate(); final TupleExpr tupleExpr = graphQuery.getTupleExpr(); - System.err.println(tupleExpr); + log.info(tupleExpr); while(result.hasNext()) { Statement s = result.next(); - System.err.println(s); + log.info(s); } } - { - - String query = -// "construct {" + -// " ?x ?px1 ?ox . " + -// " ?sx ?px2 ?x . " + -// " ?y ?py1 ?oy . " + -// " ?sy ?py2 ?y . " + -// "} " + - "SELECT * " + - "WHERE { " + - " ?x <"+likes+"> ?y . " + - " OPTIONAL { ?x ?px1 ?ox . } . " + - " OPTIONAL { ?sx ?px2 ?x . } . " + - " OPTIONAL { ?y ?py1 ?oy . } . " + - " OPTIONAL { ?sy ?py2 ?y . } . " + - "}"; - -/* - construct { - ?s ?p ?o . - } - where { - ?x likes ?y . - ?s ?p ?o . - FILTER(?s == ?x || ?o == ?x || ?s == ?y || ?o == ?y) . - } - - construct { - ?x ?px1 ?ox . - ?sx ?px2 ?x . - ?y ?py1 ?oy . - ?sy ?py2 ?y . - } - where { - ?x likes ?y . - OPTIONAL { ?x ?px1 ?ox . } . - OPTIONAL { ?sx ?px2 ?x . } . - OPTIONAL { ?y ?py1 ?oy . } . - OPTIONAL { ?sy ?py2 ?y . } . - } -*/ -/* - final BigdataSailGraphQuery graphQuery = (BigdataSailGraphQuery) - cxn.prepareGraphQuery(QueryLanguage.SPARQL, query); - GraphQueryResult result = graphQuery.evaluate(); - - final TupleExpr tupleExpr = graphQuery.getTupleExpr(); - System.err.println(tupleExpr); - - while(result.hasNext()) { - Statement s = result.next(); - System.err.println(s); - } -*/ - final TupleQuery tupleQuery = - cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); - final TupleQueryResult result = tupleQuery.evaluate(); - - while(result.hasNext()) { - BindingSet bs = result.next(); - System.err.println(bs); - } - - } - { - - String query = -// "construct {" + -// " ?x ?px1 ?ox . " + -// " ?sx ?px2 ?x . " + -// " ?y ?py1 ?oy . " + -// " ?sy ?py2 ?y . " + -// "} " + - "SELECT * " + - "WHERE { " + - " { ?x <"+likes+"> ?y . ?x ?px1 ?ox . } " + - " UNION " + - " { ?x <"+likes+"> ?y . ?sx ?px2 ?x . } " + - " UNION " + - " { ?x <"+likes+"> ?y . ?y ?py1 ?oy . } " + - " UNION " + - " { ?x <"+likes+"> ?y . ?sy ?py2 ?y . } " + - "}"; - -/* - construct { - ?s ?p ?o . - } - where { - ?x likes ?y . - ?s ?p ?o . - FILTER(?s == ?x || ?o == ?x || ?s == ?y || ?o == ?y) . - } - - construct { - ?x ?px1 ?ox . - ?sx ?px2 ?x . - ?y ?py1 ?oy . - ?sy ?py2 ?y . - } - where { - ?x likes ?y . - OPTIONAL { ?x ?px1 ?ox . } . - OPTIONAL { ?sx ?px2 ?x . } . - OPTIONAL { ?y ?py1 ?oy . } . - OPTIONAL { ?sy ?py2 ?y . } . - } -*/ -/* - final BigdataSailGraphQuery graphQuery = (BigdataSailGraphQuery) - cxn.prepareGraphQuery(QueryLanguage.SPARQL, query); - GraphQueryResult result = graphQuery.evaluate(); - - final TupleExpr tupleExpr = graphQuery.getTupleExpr(); - System.err.println(tupleExpr); - - while(result.hasNext()) { - Statement s = result.next(); - System.err.println(s); - } -*/ - final TupleQuery tupleQuery = - cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); - final TupleQueryResult result = tupleQuery.evaluate(); - - while(result.hasNext()) { - BindingSet bs = result.next(); - System.err.println(bs); - } - - } - } finally { cxn.close(); sail.__tearDownUnitTest(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tho...@us...> - 2011-02-24 20:33:37
|
Revision: 4246 http://bigdata.svn.sourceforge.net/bigdata/?rev=4246&view=rev Author: thompsonbry Date: 2011-02-24 20:33:29 +0000 (Thu, 24 Feb 2011) Log Message: ----------- - Moved canJoin() and canJoinUsingConstraints() to PartitionedJoinGraph utility and their test suites to the com.bigdata.bop.joinGraph package. - Modified Rule2BOpUtility in preparation for deciding constraint attachments dynamically. However, I still need to modify PartitionedJoinGroup to (a) accept a set of variables known to be bound on entry. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/BOpUtility.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/PartitionedJoinGroup.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestAll.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestPartitionedJoinGroup.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/util/TestAll.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/Rule2BOpUtility.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestPartitionedJoinGroup_canJoin.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestPartitionedJoinGroup_canJoinUsingConstraints.java Removed Paths: ------------- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/util/TestBOpUtility_canJoin.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/util/TestBOpUtility_canJoinUsingConstraints.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/BOpUtility.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/BOpUtility.java 2011-02-24 17:49:44 UTC (rev 4245) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/BOpUtility.java 2011-02-24 20:33:29 UTC (rev 4246) @@ -27,7 +27,6 @@ package com.bigdata.bop; -import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashMap; @@ -41,7 +40,6 @@ import com.bigdata.bop.BOp.Annotations; import com.bigdata.bop.engine.BOpStats; -import com.bigdata.bop.joinGraph.PartitionedJoinGroup; import com.bigdata.btree.AbstractNode; import com.bigdata.relation.accesspath.IAsynchronousIterator; import com.bigdata.relation.accesspath.IBlockingBuffer; @@ -60,7 +58,8 @@ */ public class BOpUtility { - private static final Logger log = Logger.getLogger(BOpUtility.class); + private static transient final Logger log = Logger + .getLogger(BOpUtility.class); /** * Pre-order recursive visitation of the operator tree (arguments only, no @@ -1151,288 +1150,4 @@ } - /** - * Return <code>true</code> iff two predicates can join on the basis of at - * least one variable which is shared directly by those predicates. Only the - * operands of the predicates are considered. - * <p> - * Note: This method will only identify joins where the predicates directly - * share at least one variable. However, joins are also possible when the - * predicates share variables via one or more constraint(s). Use - * {@link #canJoinUsingConstraints(IPredicate[], IPredicate, IConstraint[])} - * to identify such joins. - * <p> - * Note: Any two predicates may join regardless of the presence of shared - * variables. However, such joins will produce the full cross product of the - * binding sets selected by each predicate. As such, they should be run last - * and this method will not return <code>true</code> for such predicates. - * <p> - * Note: This method is more efficient than {@link #getSharedVars(BOp, BOp)} - * because it does not materialize the sets of shared variables. However, it - * only considers the operands of the {@link IPredicate}s and is thus more - * restricted than {@link #getSharedVars(BOp, BOp)} as well. - * - * @param p1 - * A predicate. - * @param p2 - * Another predicate. - * - * @return <code>true</code> iff the predicates share at least one variable - * as an operand. - * - * @throws IllegalArgumentException - * if the two either reference is <code>null</code>. - */ -// * @throws IllegalArgumentException -// * if the reference are the same. - static public boolean canJoin(final IPredicate<?> p1, final IPredicate<?> p2) { - - if (p1 == null) - throw new IllegalArgumentException(); - - if (p2 == null) - throw new IllegalArgumentException(); - -// if (p1 == p2) -// throw new IllegalArgumentException(); - - // iterator scanning the operands of p1. - final Iterator<IVariable<?>> itr1 = BOpUtility.getArgumentVariables(p1); - - while (itr1.hasNext()) { - - final IVariable<?> v1 = itr1.next(); - - // iterator scanning the operands of p2. - final Iterator<IVariable<?>> itr2 = BOpUtility - .getArgumentVariables(p2); - - while (itr2.hasNext()) { - - final IVariable<?> v2 = itr2.next(); - - if (v1 == v2) { - - if (log.isDebugEnabled()) - log.debug("Can join: sharedVar=" + v1 + ", p1=" + p1 - + ", p2=" + p2); - - return true; - - } - - } - - } - - if (log.isDebugEnabled()) - log.debug("No directly shared variable: p1=" + p1 + ", p2=" + p2); - - return false; - - } - - /** - * Return <code>true</code> iff a predicate may be used to extend a join - * path on the basis of at least one variable which is shared either - * directly or via one or more constraints which may be attached to the - * predicate when it is added to the join path. The join path is used to - * decide which variables are known to be bound, which in turn decides which - * constraints may be run. Unlike the case when the variable is directly - * shared between the two predicates, a join involving a constraint requires - * us to know which variables are already bound so we can know when the - * constraint may be attached. - * <p> - * Note: Use {@link #canJoin(IPredicate, IPredicate)} instead to identify - * joins based on a variable which is directly shared. - * <p> - * Note: Any two predicates may join regardless of the presence of shared - * variables. However, such joins will produce the full cross product of the - * binding sets selected by each predicate. As such, they should be run last - * and this method will not return <code>true</code> for such predicates. - * - * @param path - * A join path containing at least one predicate. - * @param vertex - * A predicate which is being considered as an extension of that - * join path. - * @param constraints - * A set of zero or more constraints (optional). Constraints are - * attached dynamically once the variables which they use are - * bound. Hence, a constraint will always share a variable with - * any predicate to which it is attached. If any constraints are - * attached to the given vertex and they share a variable which - * has already been bound by the join path, then the vertex may - * join with the join path even if it does not directly bind that - * variable. - * - * @return <code>true</code> iff the vertex can join with the join path via - * a shared variable. - * - * @throws IllegalArgumentException - * if the join path is <code>null</code>. - * @throws IllegalArgumentException - * if the join path is empty. - * @throws IllegalArgumentException - * if any element in the join path is <code>null</code>. - * @throws IllegalArgumentException - * if the vertex is <code>null</code>. - * @throws IllegalArgumentException - * if the vertex is already part of the join path. - * @throws IllegalArgumentException - * if any element in the optional constraints array is - * <code>null</code>. - */ - static public boolean canJoinUsingConstraints(final IPredicate<?>[] path, - final IPredicate<?> vertex, final IConstraint[] constraints) { - - /* - * Check arguments. - */ - if (path == null) - throw new IllegalArgumentException(); - if (vertex == null) - throw new IllegalArgumentException(); - // constraints MAY be null. - if (path.length == 0) - throw new IllegalArgumentException(); - { - for (IPredicate<?> p : path) { - if (p == null) - throw new IllegalArgumentException(); - if (vertex == p) - throw new IllegalArgumentException(); - } - } - - /* - * Find the set of variables which are known to be bound because they - * are referenced as operands of the predicates in the join path. - */ - final Set<IVariable<?>> knownBound = new LinkedHashSet<IVariable<?>>(); - - for (IPredicate<?> p : path) { - - final Iterator<IVariable<?>> vitr = BOpUtility - .getArgumentVariables(p); - - while (vitr.hasNext()) { - - knownBound.add(vitr.next()); - - } - - } - - /* - * - * If the given predicate directly shares a variable with any of the - * predicates in the join path, then we can return immediately. - */ - { - - final Iterator<IVariable<?>> vitr = BOpUtility - .getArgumentVariables(vertex); - - while (vitr.hasNext()) { - - final IVariable<?> var = vitr.next(); - - if(knownBound.contains(var)) { - - if (log.isDebugEnabled()) - log.debug("Can join: sharedVar=" + var + ", path=" - + Arrays.toString(path) + ", vertex=" + vertex); - - return true; - - } - - } - - } - - if(constraints == null) { - - // No opportunity for a constraint based join. - - if (log.isDebugEnabled()) - log.debug("No directly shared variable: path=" - + Arrays.toString(path) + ", vertex=" + vertex); - - return false; - - } - - /* - * Find the set of constraints which can run with the vertex given the - * join path. - */ - { - - // Extend the new join path. - final IPredicate<?>[] newPath = new IPredicate[path.length + 1]; - - System.arraycopy(path/* src */, 0/* srcPos */, newPath/* dest */, - 0/* destPos */, path.length); - - newPath[path.length] = vertex; - - /* - * Find the constraints that will run with each vertex of the new - * join path. - * - * TODO This is a forward reference to a different package, so maybe - * move the canJoinWithConstraints() method to that package? - */ - final IConstraint[][] constraintRunArray = PartitionedJoinGroup - .getJoinGraphConstraints(newPath, constraints); - - /* - * Consider only the constraints attached to the last vertex in the - * new join path. All of their variables will be bound since (by - * definition) a constraint may not run until its variables are - * bound. If any of the constraints attached to that last share any - * variables which were already known to be bound in the caller's - * join path, then the vertex can join (without of necessity being - * a full cross product join). - */ - final IConstraint[] vertexConstraints = constraintRunArray[path.length]; - - for (IConstraint c : vertexConstraints) { - - // consider all variables spanned by the constraint. - final Iterator<IVariable<?>> vitr = BOpUtility - .getSpannedVariables(c); - - while (vitr.hasNext()) { - - final IVariable<?> var = vitr.next(); - - if (knownBound.contains(var)) { - - if (log.isDebugEnabled()) - log.debug("Can join: sharedVar=" + var + ", path=" - + Arrays.toString(path) + ", vertex=" - + vertex + ", constraint=" + c); - - return true; - - } - - } - - } - - } - - if (log.isDebugEnabled()) - log.debug("No shared variable: path=" + Arrays.toString(path) - + ", vertex=" + vertex + ", constraints=" - + Arrays.toString(constraints)); - - return false; - - } - } Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/PartitionedJoinGroup.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/PartitionedJoinGroup.java 2011-02-24 17:49:44 UTC (rev 4245) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/PartitionedJoinGroup.java 2011-02-24 20:33:29 UTC (rev 4246) @@ -1,5 +1,6 @@ package com.bigdata.bop.joinGraph; +import java.util.Arrays; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -100,6 +101,8 @@ * A map indicating which constraints are run for which predicate in the * tail plan. The keys are the bopIds of the predicates in the tail plan. * The values are the sets of constraints to run for that tail. + * + * @todo This assumes that the tail plan is not reordered. */ private final Map<Integer/* predId */, List<IConstraint>> tailPlanConstraintMap = new LinkedHashMap<Integer, List<IConstraint>>(); @@ -442,6 +445,285 @@ } /** + * Return <code>true</code> iff two predicates can join on the basis of at + * least one variable which is shared directly by those predicates. Only the + * operands of the predicates are considered. + * <p> + * Note: This method will only identify joins where the predicates directly + * share at least one variable. However, joins are also possible when the + * predicates share variables via one or more constraint(s). Use + * {@link canJoinUsingConstraints} to identify such joins. + * <p> + * Note: Any two predicates may join regardless of the presence of shared + * variables. However, such joins will produce the full cross product of the + * binding sets selected by each predicate. As such, they should be run last + * and this method will not return <code>true</code> for such predicates. + * <p> + * Note: This method is more efficient than + * {@link BOpUtility#getSharedVars(BOp, BOp)} because it does not + * materialize the sets of shared variables. However, it only considers the + * operands of the {@link IPredicate}s and is thus more restricted than + * {@link BOpUtility#getSharedVars(BOp, BOp)} as well. + * + * @param p1 + * A predicate. + * @param p2 + * Another predicate. + * + * @return <code>true</code> iff the predicates share at least one variable + * as an operand. + * + * @throws IllegalArgumentException + * if the two either reference is <code>null</code>. + */ + static public boolean canJoin(final IPredicate<?> p1, final IPredicate<?> p2) { + + if (p1 == null) + throw new IllegalArgumentException(); + + if (p2 == null) + throw new IllegalArgumentException(); + + // iterator scanning the operands of p1. + final Iterator<IVariable<?>> itr1 = BOpUtility.getArgumentVariables(p1); + + while (itr1.hasNext()) { + + final IVariable<?> v1 = itr1.next(); + + // iterator scanning the operands of p2. + final Iterator<IVariable<?>> itr2 = BOpUtility + .getArgumentVariables(p2); + + while (itr2.hasNext()) { + + final IVariable<?> v2 = itr2.next(); + + if (v1 == v2) { + + if (log.isDebugEnabled()) + log.debug("Can join: sharedVar=" + v1 + ", p1=" + p1 + + ", p2=" + p2); + + return true; + + } + + } + + } + + if (log.isDebugEnabled()) + log.debug("No directly shared variable: p1=" + p1 + ", p2=" + p2); + + return false; + + } + + /** + * Return <code>true</code> iff a predicate may be used to extend a join + * path on the basis of at least one variable which is shared either + * directly or via one or more constraints which may be attached to the + * predicate when it is added to the join path. The join path is used to + * decide which variables are known to be bound, which in turn decides which + * constraints may be run. Unlike the case when the variable is directly + * shared between the two predicates, a join involving a constraint requires + * us to know which variables are already bound so we can know when the + * constraint may be attached. + * <p> + * Note: Use {@link PartitionedJoinGroup#canJoin(IPredicate, IPredicate)} + * instead to identify joins based on a variable which is directly shared. + * <p> + * Note: Any two predicates may join regardless of the presence of shared + * variables. However, such joins will produce the full cross product of the + * binding sets selected by each predicate. As such, they should be run last + * and this method will not return <code>true</code> for such predicates. + * + * @param path + * A join path containing at least one predicate. + * @param vertex + * A predicate which is being considered as an extension of that + * join path. + * @param constraints + * A set of zero or more constraints (optional). Constraints are + * attached dynamically once the variables which they use are + * bound. Hence, a constraint will always share a variable with + * any predicate to which it is attached. If any constraints are + * attached to the given vertex and they share a variable which + * has already been bound by the join path, then the vertex may + * join with the join path even if it does not directly bind that + * variable. + * + * @return <code>true</code> iff the vertex can join with the join path via + * a shared variable. + * + * @throws IllegalArgumentException + * if the join path is <code>null</code>. + * @throws IllegalArgumentException + * if the join path is empty. + * @throws IllegalArgumentException + * if any element in the join path is <code>null</code>. + * @throws IllegalArgumentException + * if the vertex is <code>null</code>. + * @throws IllegalArgumentException + * if the vertex is already part of the join path. + * @throws IllegalArgumentException + * if any element in the optional constraints array is + * <code>null</code>. + */ + static public boolean canJoinUsingConstraints(final IPredicate<?>[] path, + final IPredicate<?> vertex, final IConstraint[] constraints) { + + /* + * Check arguments. + */ + if (path == null) + throw new IllegalArgumentException(); + if (vertex == null) + throw new IllegalArgumentException(); + // constraints MAY be null. + if (path.length == 0) + throw new IllegalArgumentException(); + { + for (IPredicate<?> p : path) { + if (p == null) + throw new IllegalArgumentException(); + if (vertex == p) + throw new IllegalArgumentException(); + } + } + + /* + * Find the set of variables which are known to be bound because they + * are referenced as operands of the predicates in the join path. + */ + final Set<IVariable<?>> knownBound = new LinkedHashSet<IVariable<?>>(); + + for (IPredicate<?> p : path) { + + final Iterator<IVariable<?>> vitr = BOpUtility + .getArgumentVariables(p); + + while (vitr.hasNext()) { + + knownBound.add(vitr.next()); + + } + + } + + /* + * + * If the given predicate directly shares a variable with any of the + * predicates in the join path, then we can return immediately. + */ + { + + final Iterator<IVariable<?>> vitr = BOpUtility + .getArgumentVariables(vertex); + + while (vitr.hasNext()) { + + final IVariable<?> var = vitr.next(); + + if (knownBound.contains(var)) { + + if (log.isDebugEnabled()) + log.debug("Can join: sharedVar=" + var + ", path=" + + Arrays.toString(path) + ", vertex=" + vertex); + + return true; + + } + + } + + } + + if (constraints == null) { + + // No opportunity for a constraint based join. + + if (log.isDebugEnabled()) + log.debug("No directly shared variable: path=" + + Arrays.toString(path) + ", vertex=" + vertex); + + return false; + + } + + /* + * Find the set of constraints which can run with the vertex given the + * join path. + */ + { + + // Extend the new join path. + final IPredicate<?>[] newPath = new IPredicate[path.length + 1]; + + System.arraycopy(path/* src */, 0/* srcPos */, newPath/* dest */, + 0/* destPos */, path.length); + + newPath[path.length] = vertex; + + /* + * Find the constraints that will run with each vertex of the new + * join path. + * + * TODO This is a forward reference to a different package, so maybe + * move the canJoinWithConstraints() method to that package? + */ + final IConstraint[][] constraintRunArray = getJoinGraphConstraints( + newPath, constraints); + + /* + * Consider only the constraints attached to the last vertex in the + * new join path. All of their variables will be bound since (by + * definition) a constraint may not run until its variables are + * bound. If any of the constraints attached to that last share any + * variables which were already known to be bound in the caller's + * join path, then the vertex can join (without of necessity being a + * full cross product join). + */ + final IConstraint[] vertexConstraints = constraintRunArray[path.length]; + + for (IConstraint c : vertexConstraints) { + + // consider all variables spanned by the constraint. + final Iterator<IVariable<?>> vitr = BOpUtility + .getSpannedVariables(c); + + while (vitr.hasNext()) { + + final IVariable<?> var = vitr.next(); + + if (knownBound.contains(var)) { + + if (log.isDebugEnabled()) + log.debug("Can join: sharedVar=" + var + ", path=" + + Arrays.toString(path) + ", vertex=" + + vertex + ", constraint=" + c); + + return true; + + } + + } + + } + + } + + if (log.isDebugEnabled()) + log.debug("No shared variable: path=" + Arrays.toString(path) + + ", vertex=" + vertex + ", constraints=" + + Arrays.toString(constraints)); + + return false; + + } + + /** * Analyze a set of {@link IPredicate}s representing "runFirst", optional * joins, and non-optional joins which may be freely reordered together with * a collection of {@link IConstraint}s and partition them into a join graph @@ -450,6 +732,8 @@ * be used to formulate a complete query when combined with a desired join * ordering. * + * @param knownBound + * A set of variables which are known to be bound on entry. * @param sourcePreds * The predicates. * @param constraints @@ -467,6 +751,7 @@ * <code>null</code>. */ public PartitionedJoinGroup(// +// final Set<IVariable<?>> knownBound, final IPredicate<?>[] sourcePreds,// IConstraint[] constraints) { Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java 2011-02-24 17:49:44 UTC (rev 4245) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java 2011-02-24 20:33:29 UTC (rev 4246) @@ -47,6 +47,7 @@ import com.bigdata.bop.ap.SampleIndex.SampleType; import com.bigdata.bop.engine.QueryEngine; import com.bigdata.bop.joinGraph.NoSolutionsException; +import com.bigdata.bop.joinGraph.PartitionedJoinGroup; import com.bigdata.bop.rdf.join.DataSetJoin; /** @@ -894,7 +895,7 @@ continue; } - if (!BOpUtility.canJoinUsingConstraints(// + if (!PartitionedJoinGroup.canJoinUsingConstraints(// x.getPredicates(),// path tVertex.pred,// vertex C// constraints @@ -1113,7 +1114,7 @@ vp = v1; } - if (!BOpUtility.canJoinUsingConstraints( + if (!PartitionedJoinGroup.canJoinUsingConstraints( new IPredicate[] { v.pred }, vp.pred, C)) { /* Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestAll.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestAll.java 2011-02-24 17:49:44 UTC (rev 4245) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestAll.java 2011-02-24 20:33:29 UTC (rev 4246) @@ -62,6 +62,12 @@ suite.addTestSuite(TestPartitionedJoinGroup.class); + // unit tests for allowing joins based on shared variables in preds. + suite.addTestSuite(TestPartitionedJoinGroup_canJoin.class); + + // more complex logic for join paths. + suite.addTestSuite(TestPartitionedJoinGroup_canJoinUsingConstraints.class); + // static query optimizer test suite. suite.addTest(com.bigdata.bop.joinGraph.fast.TestAll.suite()); Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestPartitionedJoinGroup.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestPartitionedJoinGroup.java 2011-02-24 17:49:44 UTC (rev 4245) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestPartitionedJoinGroup.java 2011-02-24 20:33:29 UTC (rev 4246) @@ -49,6 +49,11 @@ * * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ + * + * FIXME Add test to ensure that constraints are run regardless as of the last + * join even if their variables are not known to be bound. Also, modify the + * constructor to accept a set of variables which are known to be bound on + * entry into the join group. */ public class TestPartitionedJoinGroup extends TestCase2 { @@ -493,7 +498,7 @@ final int nrange = expected.length; - java.util.Map range = new java.util.HashMap(); + final java.util.Map range = new java.util.HashMap(); for (int j = 0; j < nrange; j++) { @@ -513,7 +518,7 @@ } - Object actualObject = actual.next(); + final Object actualObject = actual.next(); if (range.remove(actualObject) == null) { Copied: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestPartitionedJoinGroup_canJoin.java (from rev 4218, branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/util/TestBOpUtility_canJoin.java) =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestPartitionedJoinGroup_canJoin.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestPartitionedJoinGroup_canJoin.java 2011-02-24 20:33:29 UTC (rev 4246) @@ -0,0 +1,153 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + * Created on Feb 20, 2011 + */ + +package com.bigdata.bop.joinGraph; + +import com.bigdata.bop.BOp; +import com.bigdata.bop.IPredicate; +import com.bigdata.bop.IVariable; +import com.bigdata.bop.NV; +import com.bigdata.bop.Var; +import com.bigdata.bop.ap.Predicate; +import com.bigdata.bop.joinGraph.PartitionedJoinGroup; + +import junit.framework.TestCase2; + +/** + * Unit tests for {@link PartitionedJoinGroup#canJoin(IPredicate, IPredicate)} + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + */ +public class TestPartitionedJoinGroup_canJoin extends TestCase2 { + + /** + * + */ + public TestPartitionedJoinGroup_canJoin() { + } + + /** + * @param name + */ + public TestPartitionedJoinGroup_canJoin(String name) { + super(name); + } + + + /** + * Correct rejection tests. + * + * @see BOpUtility#canJoin(IPredicate, IPredicate). + */ + @SuppressWarnings("unchecked") + public void test_canJoin_correctRejection() { + + final IVariable<?> x = Var.var("x"); + final IVariable<?> y = Var.var("y"); + final IVariable<?> z = Var.var("z"); + + final IPredicate<?> p1 = new Predicate(new BOp[]{x,y}); + final IPredicate<?> p2 = new Predicate(new BOp[]{y,z}); + + // correct rejection w/ null arg. + try { + PartitionedJoinGroup.canJoin(null,p2); + fail("Expecting: " + IllegalArgumentException.class); + } catch (IllegalArgumentException ex) { + if (log.isInfoEnabled()) + log.info("Ignoring expected exception: " + ex); + } + + // correct rejection w/ null arg. + try { + PartitionedJoinGroup.canJoin(p1,null); + fail("Expecting: " + IllegalArgumentException.class); + } catch (IllegalArgumentException ex) { + if (log.isInfoEnabled()) + log.info("Ignoring expected exception: " + ex); + } + + } + + /** + * Semantics tests focused on shared variables in the operands. + * + * @see PartitionedJoinGroup#canJoin(IPredicate, IPredicate) + */ + @SuppressWarnings("unchecked") + public void test_canJoin() { + + final IVariable<?> u = Var.var("u"); + final IVariable<?> x = Var.var("x"); + final IVariable<?> y = Var.var("y"); + final IVariable<?> z = Var.var("z"); + + final IPredicate<?> p1 = new Predicate(new BOp[] { x, y }); + final IPredicate<?> p2 = new Predicate(new BOp[] { y, z }); + final IPredicate<?> p3 = new Predicate(new BOp[] { u, z }); + + // share y + assertTrue(PartitionedJoinGroup.canJoin(p1, p2)); + + // share z + assertTrue(PartitionedJoinGroup.canJoin(p2, p3)); + + // share z + assertFalse(PartitionedJoinGroup.canJoin(p1, p3)); + + // shares (x,y) with self. + assertTrue(PartitionedJoinGroup.canJoin(p1, p1)); + + } + + /** + * Verify that joins are not permitted when the variables are + * only shared via an annotation. + * + * @see PartitionedJoinGroup#canJoin(IPredicate, IPredicate) + */ + @SuppressWarnings("unchecked") + public void test_canJoin_annotationsAreIngored() { + + final IVariable<?> x = Var.var("x"); + final IVariable<?> y = Var.var("y"); + final IVariable<?> z = Var.var("z"); + + final IPredicate<?> p1 = new Predicate(new BOp[] { x, },// + new NV("foo", y)// + ); + final IPredicate<?> p2 = new Predicate(new BOp[] { z },// + new NV("foo", y) + ); + + // verify that the variables in the annotations are ignored. + assertFalse(PartitionedJoinGroup.canJoin(p1, p2)); + + } + +} Copied: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestPartitionedJoinGroup_canJoinUsingConstraints.java (from rev 4233, branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/util/TestBOpUtility_canJoinUsingConstraints.java) =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestPartitionedJoinGroup_canJoinUsingConstraints.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestPartitionedJoinGroup_canJoinUsingConstraints.java 2011-02-24 20:33:29 UTC (rev 4246) @@ -0,0 +1,719 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + * Created on Feb 20, 2011 + */ + +package com.bigdata.bop.joinGraph; + +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Random; +import java.util.Set; + +import junit.framework.TestCase2; + +import com.bigdata.bop.BOp; +import com.bigdata.bop.Constant; +import com.bigdata.bop.IBindingSet; +import com.bigdata.bop.IConstant; +import com.bigdata.bop.IConstraint; +import com.bigdata.bop.IPredicate; +import com.bigdata.bop.IValueExpression; +import com.bigdata.bop.IVariable; +import com.bigdata.bop.ImmutableBOp; +import com.bigdata.bop.NV; +import com.bigdata.bop.Var; +import com.bigdata.bop.ap.Predicate; +import com.bigdata.bop.constraint.AND; +import com.bigdata.bop.constraint.BooleanValueExpression; +import com.bigdata.bop.constraint.Constraint; +import com.bigdata.bop.joinGraph.PartitionedJoinGroup; +import com.bigdata.bop.joinGraph.rto.JGraph; + +/** + * + * This test suite is built around around BSBM Q5. Each test has an existing + * join path and a new vertex to be added to the join path. The question is + * whether or not the vertex <em>can join</em> with the join path using one or + * more shared variable(s). This tests a method used to incrementally grow a + * join path when it is dynamically decided that an {@link IPredicate} may be + * added to the join path based on shared variables. Static analysis easily + * reports those joins which are allowed based on the variables directly given + * with two {@link IPredicate}s. The purpose of this test suite is to explore + * when joins (based on shared variables) become permissible through + * {@link IConstraint}s as the variable(s) used within those constraints become + * bound. + * <p> + * Note: To avoid a dependency on the RDF model layer, this just uses String + * constants for URIs and Literals. + * <h2>Analysis of BSBM Q5</h2> + * The following predicates all join on {@link #product}: + * <ul> + * <li>{@link #p0}</li> + * <li>{@link #p2}</li> + * <li>{@link #p4}</li> + * <li>{@link #p5}</li> + * </ul> + * The predicates ({@link #p3} and {@link #p5}) do not directly join with any of + * the other predicates (they do not directly share any variables). In general, + * a join without shared variables means the cross product of the sources will + * be materialized and such joins should be run last. + * <p> + * However, in this case there are two SPARQL FILTERs ({@link #c1} and + * {@link #c2}) which (a) use those variables ({@link #origProperty1} and + * {@link #origProperty2}); and (b) can constrain the query. This means that + * running the predicates without shared variables and applying the constraints + * before the tail of the plan can in fact lead to a more efficient join path. + * <p> + * This set of unit tests explores various join paths and verifies that the + * canJoin() and canJoinUsingConstraints() methods correctly recognize edges by + * which a join path can be extended corresponding to both static and dynamic + * analysis of the query. + * + * @see PartitionedJoinGroup#canJoin(IPredicate, IPredicate) + * @see PartitionedJoinGroup#canJoinUsingConstraints(IPredicate[], IPredicate, + * IConstraint[]) + * @see JGraph + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id: TestBOpUtility_canJoinUsingConstraints.java 4211 2011-02-20 + * 21:20:44Z thompsonbry $ + * + * @todo These are the full plans generated by the runtime and static + * optimizers. One way to test canJoinXXX() is to run out these join plans + * and verify that they report "true" in each case. However, the critical + * bit to test are join plans where the predicates w/o the shared + * variables can be run earlier due to the FILTERs. + * + * <pre> + * test_bsbm_q5 : static [0] : : ids=[1, 2, 4, 6, 0, 3, 5] + * test_bsbm_q5 : runtime[0] : : ids=[1, 2, 0, 4, 6, 3, 5] + * </pre> + */ +//@SuppressWarnings("unchecked") +public class TestPartitionedJoinGroup_canJoinUsingConstraints extends TestCase2 { + + /** + * + */ + public TestPartitionedJoinGroup_canJoinUsingConstraints() { + } + + /** + * @param name + */ + public TestPartitionedJoinGroup_canJoinUsingConstraints(String name) { + super(name); + } + + /** + * Unit tests to verify that arguments are validated. + * + * @see PartitionedJoinGroup#canJoinUsingConstraints(IPredicate[], IPredicate, + * IConstraint[]) + */ + public void test_canJoinUsingConstraints_illegalArgument() { + + final IVariable<?> x = Var.var("x"); + final IVariable<?> y = Var.var("y"); + + final IPredicate<?> p1 = new Predicate(new BOp[]{x}); + + final IPredicate<?> p2 = new Predicate(new BOp[]{y}); + + // path must not be null. + try { + PartitionedJoinGroup.canJoinUsingConstraints(// + null, // path + p1,// vertex + new IConstraint[0]// constraints + ); + fail("Expecting: " + IllegalArgumentException.class); + } catch (IllegalArgumentException ex) { + if (log.isInfoEnabled()) + log.info("Expecting: " + IllegalArgumentException.class); + } + + // vertex must not be null. + try { + PartitionedJoinGroup.canJoinUsingConstraints(// + new IPredicate[]{p1}, // path + null,// vertex + new IConstraint[0]// constraints + ); + fail("Expecting: " + IllegalArgumentException.class); + } catch (IllegalArgumentException ex) { + if (log.isInfoEnabled()) + log.info("Expecting: " + IllegalArgumentException.class); + } + + // path may not be empty. + try { + PartitionedJoinGroup.canJoinUsingConstraints(// + new IPredicate[] {}, // path + p1,// vertex + new IConstraint[0]// constraints + ); + fail("Expecting: " + IllegalArgumentException.class); + } catch (IllegalArgumentException ex) { + if (log.isInfoEnabled()) + log.info("Expecting: " + IllegalArgumentException.class); + } + + // path elements may not be null. + try { + PartitionedJoinGroup.canJoinUsingConstraints(// + new IPredicate[] { p2, null }, // path + p1,// vertex + new IConstraint[0]// constraints + ); + fail("Expecting: " + IllegalArgumentException.class); + } catch (IllegalArgumentException ex) { + if (log.isInfoEnabled()) + log.info("Expecting: " + IllegalArgumentException.class); + } + + // vertex must not appear in the path. + try { + PartitionedJoinGroup.canJoinUsingConstraints(// + new IPredicate[] { p2, p1 }, // path + p1,// vertex + new IConstraint[0]// constraints + ); + fail("Expecting: " + IllegalArgumentException.class); + } catch (IllegalArgumentException ex) { + if (log.isInfoEnabled()) + log.info("Expecting: " + IllegalArgumentException.class); + } + + // constraint array may not contain null elements. + try { + PartitionedJoinGroup.canJoinUsingConstraints(// + new IPredicate[] { p2 }, // path + p1,// vertex + new IConstraint[] { // + Constraint.wrap(new NEConstant(x, new Constant<Integer>(12))), // + null // + }// constraints + ); + fail("Expecting: " + IllegalArgumentException.class); + } catch (IllegalArgumentException ex) { + if (log.isInfoEnabled()) + log.info("Expecting: " + IllegalArgumentException.class); + } + + } + + // The comparison operators. + static private final int GT = 0, LT = 1;// , EQ = 2, GTE = 3, LTE = 4; + + // The math operators. + static private final int PLUS = 0, MINUS = 1; + + // Annotation for the comparison or math operator. + static private final String OP = "op"; + + /** + * A do-nothing constraint. The constraint is never evaluated. It is only + * used to test the logic which decides when two predicates can join based + * on variable(s) shared via a constraint. + */ + static private final class MyCompareOp extends BooleanValueExpression { + + private static final long serialVersionUID = 1L; + + /** + * Required deep copy constructor. + * + * @param op + */ + public MyCompareOp(MyCompareOp op) { + super(op); + } + + /** + * @param args + * @param annotations + */ + public MyCompareOp(BOp[] args, Map<String, Object> annotations) { + super(args, annotations); + } + + public Boolean get(IBindingSet bindingSet) { + throw new UnsupportedOperationException(); + } + + } + + /** + * A do-nothing constraint. The constraint is never evaluated. It is only + * used to test the logic which decides when two predicates can join based + * on variable(s) shared via a constraint. + */ + static private final class NEConstant extends BooleanValueExpression { + + private static final long serialVersionUID = 1L; + + /** + * Required deep copy constructor. + * + * @param op + */ + public NEConstant(NEConstant op) { + super(op); + } + + /** + * @param args + * @param annotations + */ + public NEConstant(BOp[] args, Map<String, Object> annotations) { + super(args, annotations); + } + + public NEConstant(IVariable<?> var, IConstant<?> value) { + this(new BOp[] { var, value }, null/* annotations */); + } + + public Boolean get(IBindingSet bindingSet) { + throw new UnsupportedOperationException(); + } + + } + + /** + * A do-nothing value expression. The expression is never evaluated. It is + * only used to test the logic which decides when two predicates can join + * based on variable(s) shared via a constraint. + */ + static private final class MathBOp extends ImmutableBOp implements + IValueExpression { + + private static final long serialVersionUID = 1L; + + /** + * Required deep copy constructor. + * + * @param op + */ + public MathBOp(final MathBOp op) { + + super(op); + + } + + /** + * Required shallow copy constructor. + * + * @param args + * The operands. + * @param op + * The operation. + */ + public MathBOp(final BOp[] args, Map<String, Object> anns) { + + super(args, anns); + + if (args.length != 2 || args[0] == null || args[1] == null + || getProperty(OP) == null) { + + throw new IllegalArgumentException(); + + } + + } + + /** + * + * @param left + * The left operand. + * @param right + * The right operand. + * @param op + * The annotation specifying the operation to be performed on + * those operands. + */ + public MathBOp(final IValueExpression left, + final IValueExpression right, final int op) { + + this(new BOp[] { left, right }, NV.asMap(new NV(OP, op))); + + } + + public Object get(IBindingSet bindingSet) { + throw new UnsupportedOperationException(); + } + } + + static private final String rdfs = "http://www.w3.org/2000/01/rdf-schema#"; + + static private final String bsbm = "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/"; + + static private final String rdfsLabel = rdfs + "label"; + + static private final String productFeature = bsbm + "productFeature"; + + static private final String productPropertyNumeric1 = "productPropertyNumeric1"; + + static private final String productPropertyNumeric2 = bsbm + + "productPropertyNumeric2"; + + static private final String productInstance = "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromProducer1/Product22"; + + private int nextId = 0; + + final IVariable<?> product = Var.var("product"); + + final IVariable<?> productLabel = Var.var("productLabel"); + + final IVariable<?> prodFeature = Var.var("prodFeature"); + + final IVariable<?> simProperty1 = Var.var("simProperty1"); + + final IVariable<?> simProperty2 = Var.var("simProperty2"); + + final IVariable<?> origProperty1 = Var.var("origProperty1"); + + final IVariable<?> origProperty2 = Var.var("origProperty2"); + + /** ?product rdfs:label ?productLabel . */ + final private IPredicate<?> p0 = new Predicate(new BOp[] {// + product, new Constant(rdfsLabel), productLabel },// + new NV(BOp.Annotations.BOP_ID, nextId++)// + ); + + /** productInstance bsbm:productFeature ?prodFeature . */ + final private IPredicate<?> p1 = new Predicate(new BOp[] { // + new Constant(productInstance), new Constant(productFeature), + prodFeature },// + new NV(BOp.Annotations.BOP_ID, nextId++)// + ); + + /** ?product bsbm:productFeature ?prodFeature . */ + final private IPredicate<?> p2 = new Predicate(new BOp[] { // + product, new Constant(productFeature), prodFeature },// + new NV(BOp.Annotations.BOP_ID, nextId++)// + ); + + /** productInstance bsbm:productPropertyNumeric1 ?origProperty1 . */ + final private IPredicate<?> p3 = new Predicate(new BOp[] { // + new Constant<String>(productInstance), + new Constant(productPropertyNumeric1), origProperty1 },// + new NV(BOp.Annotations.BOP_ID, nextId++)// + ); + + /** ?product bsbm:productPropertyNumeric1 ?simProperty1 . */ + final private IPredicate<?> p4 = new Predicate(new BOp[] { // + product, new Constant(productPropertyNumeric1), simProperty1 },// + new NV(BOp.Annotations.BOP_ID, nextId++)// + ); + + /** productInstance bsbm:productPropertyNumeric2 ?origProperty2 . */ + final private IPredicate<?> p5 = new Predicate(new BOp[] { // + new Constant(productInstance), + new Constant(productPropertyNumeric2), origProperty2 },// + new NV(BOp.Annotations.BOP_ID, nextId++)// + ); + + /** ?product bsbm:productPropertyNumeric2 ?simProperty2 . */ + final private IPredicate<?> p6 = new Predicate(new BOp[] { // + product, new Constant(productPropertyNumeric2), simProperty2 },// + new NV(BOp.Annotations.BOP_ID, nextId++)// + ); + + /** The vertices of the join graph (the predicates). */ + final IPredicate<?>[] preds = new IPredicate[] { p0, p1, p2, p3, p4, p5, p6 }; + + /** + * FILTER (productInstance != ?product) + */ + final IConstraint c0 = Constraint.wrap(new NEConstant(product, new Constant<String>( + productInstance))); + + /** + * FILTER (?simProperty1 < (?origProperty1 + 120) && ?simProperty1 > + * (?origProperty1 - 120)) + * <p> + * Note: The AND in the compound filters is typically optimized out such + * that each of these is represented as its own IConstraint, but I have + * combined them for the purposes of these unit tests. + */ + final IConstraint c1 = Constraint.wrap(new AND(// + new MyCompareOp( + new BOp[] { + simProperty1, + new MathBOp(origProperty1, new Constant<Integer>( + 120), PLUS) }, NV.asMap(new NV[] { new NV( + OP, LT) })), // + new MyCompareOp(new BOp[] { + simProperty1, + new MathBOp(origProperty1, new Constant<Integer>(120), + MINUS) }, NV.asMap(new NV[] { new NV(OP, GT) }))// + )); + + /** + * FILTER (?simProperty2 < (?origProperty2 + 170) && ?simProperty2 > + * (?origProperty2 - 170)) + * <p> + * Note: The AND in the compound filters is typically optimized out such + * that each of these is represented as its own IConstraint, but I have + * combined them for the purposes of these unit tests. + */ + final IConstraint c2 = Constraint.wrap(new AND(// + new MyCompareOp( + new BOp[] { + simProperty2, + new MathBOp(origProperty2, new Constant<Integer>( + 170), PLUS) }, NV.asMap(new NV[] { new NV( + OP, LT) })),// + new MyCompareOp(new BOp[] { + simProperty2, + new MathBOp(origProperty2, new Constant<Integer>(170), + MINUS) }, NV.asMap(new NV[] { new NV(OP, GT) }))// + )); + + /** The constraints on the join graph. */ + final IConstraint[] constraints = new IConstraint[] { c0, c1, c2 }; + + /** + * Unit test for one-step joins based on the {@link #product} variable. + */ + public void test_canJoinUsingConstraints_1step_productVar() { + + // share ?product + final IPredicate<?>[] a = new IPredicate[] { p0, p2, p4, p6 }; + for (int i = 0; i < a.length; i++) { + for (int j = i; j < a.length; j++) { + final IPredicate<?> t0 = a[i]; + final IPredicate<?> t1 = a[j]; + assertTrue(PartitionedJoinGroup.canJoin(t0, t1)); + assertTrue(PartitionedJoinGroup.canJoin(t1, t0)); + if (t0 != t1) { + /* + * Test join path extension, but not when the vertex used to + * extend the path is already present in the join path. + */ + assertTrue(PartitionedJoinGroup.canJoinUsingConstraints(// + new IPredicate[] { t0 }, // path + t1,// vertex + new IConstraint[0]// constraints + )); + assertTrue(PartitionedJoinGroup.canJoinUsingConstraints(// + new IPredicate[] { t1 }, // path + t0,// vertex + new IConstraint[0]// constraints + )); + } + } + } + + } + + /** + * Unit test for multi-step join paths based on the {@link #product} + * variable. + */ + public void test_canJoinUsingConstraints_multiStep_productVar() { + + final Random r = new Random(); + + // share ?product + final IPredicate<?>[] a = new IPredicate[] { p0, p2, p4, p6 }; + + // existing path length [1:3]. + final int existingPathLength = r.nextInt(3)+1; + + // generated pre-existing path. + final IPredicate<?>[] path = new IPredicate[existingPathLength]; + // vertex which will extend that path + final IPredicate<?> vertex; + { + // collection of predicates used so far by the path. + final Set<Integer> used = new LinkedHashSet<Integer>(); + for (int i = 0; i < path.length; i++) { + // Locate an unused predicate. + int index; + while (true) { + index = r.nextInt(a.length); + if (!used.contains(index)) { + used.add(index); + break; + } + } + // add to the path. + path[i] = a[index]; + } + // Locate an unused predicate to serve as the extension vertex. + { + // Locate an unused predicate. + int index; + while (true) { + index = r.nextInt(a.length); + if (!used.contains(index)) { + used.add(index); + break; + } + } + vertex = a[index]; + } + } + + // Verify all joins in the path are legal. + for (int i = 0; i < path.length - 1; i++) { + assertTrue(PartitionedJoinGroup.canJoin(path[i], path[i + 1])); + } + + // Verify the extension of the path is legal. + assertTrue(PartitionedJoinGroup.canJoinUsingConstraints(// + path,// + vertex,// + new IConstraint[0]// constraints + )); + + } + + /** + * Unit test examines the predicates without shared variables and verifies + * (a) that joins are not permitted when the constraints are not considered; + * and (b) that joins are permitted when the constraints are considered. + * <p> + * This test is identical to {@link #test_canJoinUsingConstraints_p5_p6()()} + * except that it considers the ({@link #p3} x {@link #p4}) join via the + * {@link #c1} constraint instead. + */ + public void test_canJoinUsingConstraints_p3_p4() { + + /* + * Verify (p3,p4) join is not permitted when we do not consider the + * constraints (i.e., the join would be an unconstrained cross product + * if it were executed). + */ + assertFalse(PartitionedJoinGroup.canJoin(p3, p4)); + assertFalse(PartitionedJoinGroup.canJoin(p4, p3)); + assertFalse(PartitionedJoinGroup.canJoinUsingConstraints(// + new IPredicate[] { p3 }, // path + p4,// vertex + new IConstraint[0]// constraints + )); + assertFalse(PartitionedJoinGroup.canJoinUsingConstraints(// + new IPredicate[] { p4 }, // path + p3,// vertex + new IConstraint[0]// constraints + )); + + /* + * Verify (p3,p4) join is not permitted if we do not consider the + * constraint which provides the shared variables. + */ + assertFalse(PartitionedJoinGroup.canJoinUsingConstraints(// + new IPredicate[] { p3 }, // path + p4,// vertex + new IConstraint[] { c2 }// constraints + )); + assertFalse(PartitionedJoinGroup.canJoinUsingConstraints(// + new IPredicate[] { p4 }, // path + p3,// vertex + new IConstraint[] { c2 }// constraints + )); + + /* + * Verify (p3,p4) join is permitted if we consider the constraint which + * provides the shared variables. + */ + assertTrue(PartitionedJoinGroup.canJoinUsingConstraints(// + new IPredicate[] { p3 }, // path + p4,// vertex + new IConstraint[] { c1 }// constraints + )); + assertTrue(PartitionedJoinGroup.canJoinUsingConstraints(// + new IPredicate[] { p4 }, // path + p3,// vertex + new IConstraint[] { c1 }// constraints + )); + + } + + /** + * Unit test examines the predicates without shared variables and verifies + * (a) that joins are not permitted when the constraints are not considered; + * and (b) that joins are permitted wh... [truncated message content] |
From: <mar...@us...> - 2011-02-24 17:49:50
|
Revision: 4245 http://bigdata.svn.sourceforge.net/bigdata/?rev=4245&view=rev Author: martyncutcher Date: 2011-02-24 17:49:44 +0000 (Thu, 24 Feb 2011) Log Message: ----------- Remove unneeded reference to RWSectorStore Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/SectorAllocator.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/rwstore/sector/TestMemoryManager.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/SectorAllocator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/SectorAllocator.java 2011-02-24 17:34:41 UTC (rev 4244) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/SectorAllocator.java 2011-02-24 17:49:44 UTC (rev 4245) @@ -35,7 +35,6 @@ import com.bigdata.rwstore.FixedOutputStream; import com.bigdata.rwstore.IAllocationContext; import com.bigdata.rwstore.IWriteCacheManager; -import com.bigdata.rwstore.RWSectorStore; import com.bigdata.rwstore.RWWriteCacheService; /** @@ -666,7 +665,7 @@ } - public int alloc(RWSectorStore sectorStore, int size, IAllocationContext context) { + public int alloc(int size, IAllocationContext context) { return alloc(size); } Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/rwstore/sector/TestMemoryManager.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/rwstore/sector/TestMemoryManager.java 2011-02-24 17:34:41 UTC (rev 4244) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/rwstore/sector/TestMemoryManager.java 2011-02-24 17:49:44 UTC (rev 4245) @@ -10,6 +10,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import com.bigdata.io.DirectBufferPool; +import com.bigdata.rwstore.sector.MemoryManagerResourceError; import com.bigdata.util.concurrent.DaemonThreadFactory; import junit.framework.TestCase; @@ -47,12 +49,10 @@ String retstr = getString(saddr); assertTrue(helloWorld.equals(retstr)); - - System.out.println(helloWorld + " allocated address: " + saddr + " returned: " + retstr); } private void installMemoryManager() { - manager = new MemoryManager(5 * sectorSize, sectorSize); + manager = new MemoryManager(DirectBufferPool.INSTANCE, 10); } /** @@ -64,7 +64,7 @@ while (--i > 0) { // final int sector = r.nextInt(12); final int sector = r.nextInt(32 * 1024); - final int bit = r.nextInt(64 * 1024); + final int bit = r.nextInt(32 * 1024); final int rwaddr = SectorAllocator.makeAddr(sector, bit); final int rsector = SectorAllocator.getSectorIndex(rwaddr); final int rbit = SectorAllocator.getSectorOffset(rwaddr); @@ -76,14 +76,26 @@ installMemoryManager(); for (int i = 0; i < 20; i++) { - doStressAllocations(manager, true, 80000, 5 + r.nextInt(200)); + doStressAllocations(manager, true, 50000, 5 + r.nextInt(5000)); } } + public void testSimpleBlob() { + installMemoryManager(); + + String blob = new String(c_testData, 0, 11000); + + final long saddr = allocate(manager, blob); + + String retstr = getString(saddr); + + assertTrue(blob.equals(retstr)); + } + public void testAllocationContexts() { installMemoryManager(); - final IMemoryManager context = manager.createAllocationContext(); + IMemoryManager context = manager.createAllocationContext(); for (int i = 0; i < 500; i++) { doStressAllocations(context, false, 5000, 5 + r.nextInt(3000)); context.clear(); @@ -133,30 +145,34 @@ int f = r.nextInt(addrs.size()); long faddr = ((Long) addrs.remove(f)).longValue(); mm.free(faddr); - // System.out.println("freeing: " + faddr); frees++; } } } catch (MemoryManagerResourceError err) { // all okay } - - System.out.println("Committed " + allocs + " allocations, and " + frees + " frees"); } private String getString(long saddr) { - final ByteBuffer ret = manager.get(saddr)[0]; - final byte[] data; - if (ret.isDirect()) { - ByteBuffer indbuf = ByteBuffer.allocate(ret.remaining()); - data = indbuf.array(); - indbuf.put(ret); - indbuf.flip(); - } else { - data = ret.array(); + StringBuffer sb = new StringBuffer(); + + final ByteBuffer[] bufs = manager.get(saddr); + + for (int i = 0; i < bufs.length; i++) { + final byte[] data; + if (bufs[i].isDirect()) { + ByteBuffer indbuf = ByteBuffer.allocate(bufs[i].remaining()); + data = indbuf.array(); + indbuf.put(bufs[i]); + indbuf.flip(); + } else { + data = bufs[i].array(); + } + + sb.append(new String(data)); } - return new String(data); + return sb.toString(); } private long allocate(final IMemoryManager mm, String val) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mrp...@us...> - 2011-02-24 17:34:48
|
Revision: 4244 http://bigdata.svn.sourceforge.net/bigdata/?rev=4244&view=rev Author: mrpersonick Date: 2011-02-24 17:34:41 +0000 (Thu, 24 Feb 2011) Log Message: ----------- added a few more VE bops Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsLiteralBOp.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsBNodeBOp.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsURIBOp.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/StrBOp.java Added: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsBNodeBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsBNodeBOp.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsBNodeBOp.java 2011-02-24 17:34:41 UTC (rev 4244) @@ -0,0 +1,91 @@ +/* + +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 + +*/ +package com.bigdata.rdf.internal.constraints; + +import java.util.Map; + +import com.bigdata.bop.BOp; +import com.bigdata.bop.IBindingSet; +import com.bigdata.bop.IValueExpression; +import com.bigdata.bop.IVariable; +import com.bigdata.rdf.error.SparqlTypeErrorException; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.XSDBooleanIV; + +/** + * Imposes the constraint <code>isBNode(x)</code>. + */ +public class IsBNodeBOp extends ValueExpressionBOp + implements IValueExpression<IV> { + + /** + * + */ + private static final long serialVersionUID = 3125106876006900339L; + + public IsBNodeBOp(final IVariable<IV> x) { + + this(new BOp[] { x }, null/*annocations*/); + + } + + /** + * Required shallow copy constructor. + */ + public IsBNodeBOp(final BOp[] args, final Map<String, Object> anns) { + + super(args, anns); + + if (args.length != 1 || args[0] == null) + throw new IllegalArgumentException(); + + } + + /** + * Required deep copy constructor. + */ + public IsBNodeBOp(final IsBNodeBOp op) { + super(op); + } + + public boolean accept(final IBindingSet bs) { + + final IV iv = get(0).get(bs); + + // not yet bound + if (iv == null) + throw new SparqlTypeErrorException(); + + return iv.isBNode(); + + } + + public IV get(final IBindingSet bs) { + + return accept(bs) ? XSDBooleanIV.TRUE : XSDBooleanIV.FALSE; + + } + +} Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsLiteralBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsLiteralBOp.java 2011-02-24 17:34:11 UTC (rev 4243) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsLiteralBOp.java 2011-02-24 17:34:41 UTC (rev 4244) @@ -70,7 +70,7 @@ super(op); } - public boolean accept(IBindingSet bs) { + public boolean accept(final IBindingSet bs) { final IV iv = get(0).get(bs); Added: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsURIBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsURIBOp.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsURIBOp.java 2011-02-24 17:34:41 UTC (rev 4244) @@ -0,0 +1,91 @@ +/* + +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 + +*/ +package com.bigdata.rdf.internal.constraints; + +import java.util.Map; + +import com.bigdata.bop.BOp; +import com.bigdata.bop.IBindingSet; +import com.bigdata.bop.IValueExpression; +import com.bigdata.bop.IVariable; +import com.bigdata.rdf.error.SparqlTypeErrorException; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.XSDBooleanIV; + +/** + * Imposes the constraint <code>isURI(x)</code>. + */ +public class IsURIBOp extends ValueExpressionBOp + implements IValueExpression<IV> { + + /** + * + */ + private static final long serialVersionUID = 3125106876006900339L; + + public IsURIBOp(final IVariable<IV> x) { + + this(new BOp[] { x }, null/*annocations*/); + + } + + /** + * Required shallow copy constructor. + */ + public IsURIBOp(final BOp[] args, final Map<String, Object> anns) { + + super(args, anns); + + if (args.length != 1 || args[0] == null) + throw new IllegalArgumentException(); + + } + + /** + * Required deep copy constructor. + */ + public IsURIBOp(final IsURIBOp op) { + super(op); + } + + public boolean accept(final IBindingSet bs) { + + final IV iv = get(0).get(bs); + + // not yet bound + if (iv == null) + throw new SparqlTypeErrorException(); + + return iv.isURI(); + + } + + public IV get(final IBindingSet bs) { + + return accept(bs) ? XSDBooleanIV.TRUE : XSDBooleanIV.FALSE; + + } + +} Added: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/StrBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/StrBOp.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/StrBOp.java 2011-02-24 17:34:41 UTC (rev 4244) @@ -0,0 +1,118 @@ +/* + +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 + +*/ +package com.bigdata.rdf.internal.constraints; + +import java.util.Map; + +import org.openrdf.model.URI; + +import com.bigdata.bop.BOp; +import com.bigdata.bop.IBindingSet; +import com.bigdata.bop.IValueExpression; +import com.bigdata.bop.IVariable; +import com.bigdata.rdf.error.SparqlTypeErrorException; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.StrIV; +import com.bigdata.rdf.lexicon.LexiconRelation; +import com.bigdata.rdf.model.BigdataLiteral; +import com.bigdata.rdf.model.BigdataValueFactory; +import com.bigdata.rdf.store.AbstractTripleStore; + +/** + * Imposes the constraint <code>isURI(x)</code>. + */ +public class StrBOp extends ValueExpressionBOp + implements IValueExpression<IV> { + + /** + * + */ + private static final long serialVersionUID = 3125106876006900339L; + + public StrBOp(final IVariable<IV> x) { + + this(new BOp[] { x }, null/*annocations*/); + + } + + /** + * Required shallow copy constructor. + */ + public StrBOp(final BOp[] args, final Map<String, Object> anns) { + + super(args, anns); + + if (args.length != 1 || args[0] == null) + throw new IllegalArgumentException(); + + } + + /** + * Required deep copy constructor. + */ + public StrBOp(final StrBOp op) { + super(op); + } + + public IV get(final IBindingSet bs) { + + final IV iv = get(0).get(bs); + + // not yet bound + if (iv == null) + throw new SparqlTypeErrorException(); + + // uh oh how the heck do I get my hands on this? big change + final AbstractTripleStore db = null; + + // use to materialize my terms + final LexiconRelation lex = db.getLexiconRelation(); + + // use to create my simple literals + final BigdataValueFactory vf = db.getValueFactory(); + + if (iv.isURI()) { + // return new simple literal using URI label + final URI uri = (URI) iv.asValue(lex); + final BigdataLiteral str = vf.createLiteral(uri.toString()); + return new StrIV(iv, str); + } else if (iv.isLiteral()) { + final BigdataLiteral lit = (BigdataLiteral) iv.asValue(lex); + if (lit.getDatatype() == null && lit.getLanguage() == null) { + // if simple literal return it + return iv; + } + else { + // else return new simple literal using Literal.getLabel + final BigdataLiteral str = vf.createLiteral(lit.getLabel()); + return new StrIV(iv, str); + } + } else { + throw new SparqlTypeErrorException(); + } + + } + +} 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-02-24 17:34:11 UTC (rev 4243) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java 2011-02-24 17:34:41 UTC (rev 4244) @@ -30,7 +30,10 @@ import org.openrdf.query.algebra.Compare; import org.openrdf.query.algebra.Filter; import org.openrdf.query.algebra.Group; +import org.openrdf.query.algebra.IsBNode; import org.openrdf.query.algebra.IsLiteral; +import org.openrdf.query.algebra.IsResource; +import org.openrdf.query.algebra.IsURI; import org.openrdf.query.algebra.Join; import org.openrdf.query.algebra.LeftJoin; import org.openrdf.query.algebra.MathExpr; @@ -48,6 +51,7 @@ import org.openrdf.query.algebra.SameTerm; import org.openrdf.query.algebra.StatementPattern; import org.openrdf.query.algebra.StatementPattern.Scope; +import org.openrdf.query.algebra.Str; import org.openrdf.query.algebra.TupleExpr; import org.openrdf.query.algebra.UnaryTupleOperator; import org.openrdf.query.algebra.Union; @@ -72,6 +76,7 @@ import com.bigdata.bop.NV; import com.bigdata.bop.PipelineOp; import com.bigdata.bop.ap.Predicate; +import com.bigdata.bop.constraint.INBinarySearch; import com.bigdata.bop.engine.IRunningQuery; import com.bigdata.bop.engine.QueryEngine; import com.bigdata.bop.solutions.ISortOrder; @@ -82,14 +87,16 @@ import com.bigdata.rdf.internal.XSDBooleanIV; import com.bigdata.rdf.internal.constraints.AndBOp; import com.bigdata.rdf.internal.constraints.CompareBOp; +import com.bigdata.rdf.internal.constraints.Constraint; import com.bigdata.rdf.internal.constraints.EBVBOp; +import com.bigdata.rdf.internal.constraints.IsBNodeBOp; import com.bigdata.rdf.internal.constraints.IsBoundBOp; import com.bigdata.rdf.internal.constraints.IsLiteralBOp; +import com.bigdata.rdf.internal.constraints.IsURIBOp; import com.bigdata.rdf.internal.constraints.MathBOp; import com.bigdata.rdf.internal.constraints.NotBOp; import com.bigdata.rdf.internal.constraints.OrBOp; import com.bigdata.rdf.internal.constraints.SameTermBOp; -import com.bigdata.rdf.internal.constraints.Constraint; import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataValue; import com.bigdata.rdf.sail.BigdataSail.Options; @@ -2066,6 +2073,12 @@ return toVE((Bound) ve); } else if (ve instanceof IsLiteral) { return toVE((IsLiteral) ve); + } else if (ve instanceof IsBNode) { + return toVE((IsBNode) ve); + } else if (ve instanceof IsResource) { + return toVE((IsResource) ve); + } else if (ve instanceof IsURI) { + return toVE((IsURI) ve); } throw new UnsupportedOperatorException(ve); @@ -2152,6 +2165,22 @@ return new IsLiteralBOp(var); } + private IValueExpression<IV> toVE(final IsBNode isBNode) { + final IVariable<IV> var = (IVariable<IV>) toVE(isBNode.getArg()); + return new IsBNodeBOp(var); + } + + private IValueExpression<IV> toVE(final IsResource isResource) { + final IVariable<IV> var = (IVariable<IV>) toVE(isResource.getArg()); + // isResource == isURI || isBNode == !isLiteral + return new NotBOp(new IsLiteralBOp(var)); + } + + private IValueExpression<IV> toVE(final IsURI isURI) { + final IVariable<IV> var = (IVariable<IV>) toVE(isURI.getArg()); + return new IsURIBOp(var); + } + /** * Generate a bigdata term from a Sesame term. * <p> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mrp...@us...> - 2011-02-24 17:34:19
|
Revision: 4243 http://bigdata.svn.sourceforge.net/bigdata/?rev=4243&view=rev Author: mrpersonick Date: 2011-02-24 17:34:11 +0000 (Thu, 24 Feb 2011) Log Message: ----------- changed the method signature for asValue() Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/AbstractBNodeIV.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/DummyIV.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/ExtensionIV.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/IV.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/TermId.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/UUIDLiteralIV.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDBooleanIV.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDByteIV.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDDecimalIV.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDDoubleIV.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDFloatIV.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDIntIV.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDIntegerIV.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDLongIV.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDShortIV.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/TestEncodeDecodeKeys.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/StrIV.java Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/AbstractBNodeIV.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/AbstractBNodeIV.java 2011-02-24 17:28:05 UTC (rev 4242) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/AbstractBNodeIV.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -23,8 +23,10 @@ */ package com.bigdata.rdf.internal; +import org.openrdf.model.ValueFactory; + +import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataBNode; -import com.bigdata.rdf.model.BigdataValueFactory; import com.bigdata.rdf.store.AbstractTripleStore; /** @@ -54,9 +56,8 @@ } - public V asValue(final BigdataValueFactory f, - final ILexiconConfiguration config) - throws UnsupportedOperationException { + public V asValue(final LexiconRelation lex) { + final ValueFactory f = lex.getValueFactory(); final V bnode = (V) f.createBNode(stringValue()); bnode.setIV(this); return bnode; Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/DummyIV.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/DummyIV.java 2011-02-24 17:28:05 UTC (rev 4242) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/DummyIV.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -31,8 +31,8 @@ import com.bigdata.bop.Constant; import com.bigdata.bop.Var; +import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataValue; -import com.bigdata.rdf.model.BigdataValueFactory; /** * A dummy {@link IV} class used in cases where we want a dummy {@link Constant} @@ -55,8 +55,7 @@ return "DummyIV"; } - public BigdataValue asValue(final BigdataValueFactory f, - final ILexiconConfiguration config) + public BigdataValue asValue(final LexiconRelation lex) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/ExtensionIV.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/ExtensionIV.java 2011-02-24 17:28:05 UTC (rev 4242) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/ExtensionIV.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -1,6 +1,7 @@ package com.bigdata.rdf.internal; import com.bigdata.rawstore.Bytes; +import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataLiteral; import com.bigdata.rdf.model.BigdataValueFactory; @@ -81,10 +82,10 @@ * Defer to the {@link ILexiconConfiguration} which has specific knowledge * of how to generate an RDF value from this general purpose extension IV. */ - @SuppressWarnings("unchecked") - public V asValue(final BigdataValueFactory f, - final ILexiconConfiguration config) - throws UnsupportedOperationException { + @SuppressWarnings({"unchecked","rawtypes"}) + public V asValue(final LexiconRelation lex) { + final BigdataValueFactory f = lex.getValueFactory(); + final ILexiconConfiguration config = lex.getLexiconConfiguration(); return (V) config.asValue(this, f); } Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/IV.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/IV.java 2011-02-24 17:28:05 UTC (rev 4242) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/IV.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -33,8 +33,8 @@ import org.openrdf.model.Value; import com.bigdata.btree.keys.IKeyBuilder; +import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataValue; -import com.bigdata.rdf.model.BigdataValueFactory; import com.bigdata.rdf.store.AbstractTripleStore.Options; /** @@ -202,17 +202,12 @@ * factory. However, implementations are encouraged to cache the inflated * {@link BigdataValue} on a transient field. * - * @param vf - * The value factory. - * @param config - * The lexicon configuration. + * @param lex + * the lexicon relation * * @return The corresponding {@link BigdataValue}. - * - * @throws UnsupportedOperationException - * unless the RDF value is inline. */ - V asValue(final BigdataValueFactory vf, final ILexiconConfiguration config) + V asValue(final LexiconRelation lex) throws UnsupportedOperationException; } Added: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/StrIV.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/StrIV.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/StrIV.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -0,0 +1,144 @@ +/** + +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 Jul 9, 2010 + */ + +package com.bigdata.rdf.internal; + +import com.bigdata.btree.keys.IKeyBuilder; +import com.bigdata.rdf.lexicon.LexiconRelation; +import com.bigdata.rdf.model.BigdataValue; + +/** + * A StrIV is used by the StrBOp to create an alternate "view" of a Literal or + * URI IV, one where the {@link BigdataValue} is transormed into a simple + * literal (no datatype, no language tag) using the URI's toString() or the + * Literal's label. + */ +public class StrIV implements IV { + + /** + * + */ + private static final long serialVersionUID = 5020144206004241997L; + + private final IV iv; + + private final BigdataValue strVal; + + public StrIV(final IV iv, final BigdataValue strVal) { + this.iv = iv; + this.strVal = strVal; + } + + public String toString() { + return iv.toString(); + } + + public BigdataValue asValue(final LexiconRelation lex) { + return strVal; + } + + public int compareTo(Object o) { + return iv.compareTo(o); + } + + public byte flags() { + return iv.flags(); + } + + public int byteLength() { + return iv.byteLength(); + } + + public IKeyBuilder encode(IKeyBuilder keyBuilder) { + return iv.encode(keyBuilder); + } + + public VTE getVTE() { + return iv.getVTE(); + } + + public boolean isLiteral() { + return iv.isLiteral(); + } + + public boolean isBNode() { + return iv.isBNode(); + } + + public boolean isURI() { + return iv.isURI(); + } + + public boolean isStatement() { + return iv.isStatement(); + } + + public DTE getDTE() { + return iv.getDTE(); + } + + public boolean isTermId() { + return iv.isTermId(); + } + + public long getTermId() throws UnsupportedOperationException { + return iv.getTermId(); + } + + public boolean isInline() { + return iv.isInline(); + } + + public Object getInlineValue() throws UnsupportedOperationException { + return iv.getInlineValue(); + } + + public boolean isNumeric() { + return iv.isNumeric(); + } + + public boolean isSignedNumeric() { + return iv.isSignedNumeric(); + } + + public boolean isUnsignedNumeric() { + return iv.isUnsignedNumeric(); + } + + public boolean isFixedNumeric() { + return iv.isFixedNumeric(); + } + + public boolean isBigNumeric() { + return iv.isBigNumeric(); + } + + public boolean isFloatingPointNumeric() { + return iv.isFloatingPointNumeric(); + } + +} Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/TermId.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/TermId.java 2011-02-24 17:28:05 UTC (rev 4242) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/TermId.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -23,10 +23,12 @@ */ package com.bigdata.rdf.internal; +import org.apache.log4j.Logger; + import com.bigdata.btree.keys.IKeyBuilder; import com.bigdata.rawstore.Bytes; +import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataValue; -import com.bigdata.rdf.model.BigdataValueFactory; /** * Implementation for any kind of RDF Value when the values is not being @@ -42,6 +44,8 @@ */ private static final long serialVersionUID = 4309045651680610931L; + protected static final Logger log = Logger.getLogger(TermId.class); + /** * Value used for a "NULL" term identifier. */ @@ -49,7 +53,7 @@ /** The term identifier. */ private final long termId; - + /** * Constructor for a term identifier when you are decoding and already have * the flags. @@ -101,19 +105,24 @@ /** * {@inheritDoc} - * <p> - * {@link TermId}s are never inline so this method always throws an - * exception. - * - * @throws UnsupportedOperationException - * always since {@link TermId}s are never inline. */ - final public V asValue(final BigdataValueFactory f, - final ILexiconConfiguration config) - throws UnsupportedOperationException { - throw new UnsupportedOperationException(); + final public V asValue(final LexiconRelation lex) + throws UnsupportedOperationException { + throw new UnsupportedOperationException(); +// /* +// * Delegates to {@link LexiconRelation#getTerm(IV)}, which is an +// * extremely inefficient method for materializing terms. Caches the +// * BigdataValue once it has been materialized. +// */ +// if (value == null) { +// if (log.isInfoEnabled()) +// log.info("performing inefficient materialization"); +// value = (V) lex.getTerm(this); +// } +// return value; } - +// volatile private V value; + final public Void getInlineValue() { throw new UnsupportedOperationException(); } Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/UUIDLiteralIV.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/UUIDLiteralIV.java 2011-02-24 17:28:05 UTC (rev 4242) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/UUIDLiteralIV.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -27,9 +27,11 @@ import java.math.BigInteger; import java.util.UUID; +import org.openrdf.model.ValueFactory; + import com.bigdata.rawstore.Bytes; +import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataLiteral; -import com.bigdata.rdf.model.BigdataValueFactory; /** * Implementation for inline {@link UUID}s (there is no corresponding XML @@ -61,8 +63,8 @@ } @SuppressWarnings("unchecked") - public V asValue(final BigdataValueFactory f, - final ILexiconConfiguration config) { + public V asValue(final LexiconRelation lex) { + final ValueFactory f = lex.getValueFactory(); final V v = (V) f.createLiteral(value.toString(), // f.createURI(DTE.UUID.getDatatype())); v.setIV(this); Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDBooleanIV.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDBooleanIV.java 2011-02-24 17:28:05 UTC (rev 4242) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDBooleanIV.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -27,8 +27,8 @@ import java.math.BigDecimal; import java.math.BigInteger; +import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataLiteral; -import com.bigdata.rdf.model.BigdataValueFactory; /** Implementation for inline <code>xsd:boolean</code>. */ public class XSDBooleanIV<V extends BigdataLiteral> extends @@ -66,9 +66,8 @@ } @SuppressWarnings("unchecked") - public V asValue(final BigdataValueFactory f, - final ILexiconConfiguration config) { - final V v = (V) f.createLiteral(value); + public V asValue(final LexiconRelation lex) { + final V v = (V) lex.getValueFactory().createLiteral(value); v.setIV(this); return v; } Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDByteIV.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDByteIV.java 2011-02-24 17:28:05 UTC (rev 4242) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDByteIV.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -27,6 +27,7 @@ import java.math.BigDecimal; import java.math.BigInteger; +import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataLiteral; import com.bigdata.rdf.model.BigdataValueFactory; @@ -56,8 +57,8 @@ } @SuppressWarnings("unchecked") - public V asValue(final BigdataValueFactory f, - final ILexiconConfiguration config) { + public V asValue(final LexiconRelation lex) { + final BigdataValueFactory f = lex.getValueFactory(); final V v = (V) f.createLiteral(value); v.setIV(this); return v; Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDDecimalIV.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDDecimalIV.java 2011-02-24 17:28:05 UTC (rev 4242) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDDecimalIV.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -28,6 +28,7 @@ import java.math.BigInteger; import com.bigdata.btree.keys.KeyBuilder; +import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataLiteral; import com.bigdata.rdf.model.BigdataValueFactory; @@ -61,8 +62,8 @@ } @SuppressWarnings("unchecked") - public V asValue(final BigdataValueFactory f, - final ILexiconConfiguration config) { + public V asValue(final LexiconRelation lex) { + final BigdataValueFactory f = lex.getValueFactory(); // @todo factory should cache the XSD URIs. final V v = (V) f.createLiteral(value.toPlainString(),// f.createURI(DTE.XSDDecimal.getDatatype())); Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDDoubleIV.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDDoubleIV.java 2011-02-24 17:28:05 UTC (rev 4242) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDDoubleIV.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -28,6 +28,7 @@ import java.math.BigInteger; import com.bigdata.rawstore.Bytes; +import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataLiteral; import com.bigdata.rdf.model.BigdataValueFactory; @@ -55,8 +56,8 @@ } @SuppressWarnings("unchecked") - public V asValue(final BigdataValueFactory f, - final ILexiconConfiguration config) { + public V asValue(final LexiconRelation lex) { + final BigdataValueFactory f = lex.getValueFactory(); final V v = (V) f.createLiteral(value); v.setIV(this); return v; Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDFloatIV.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDFloatIV.java 2011-02-24 17:28:05 UTC (rev 4242) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDFloatIV.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -28,6 +28,7 @@ import java.math.BigInteger; import com.bigdata.rawstore.Bytes; +import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataLiteral; import com.bigdata.rdf.model.BigdataValueFactory; @@ -55,8 +56,8 @@ } @SuppressWarnings("unchecked") - public V asValue(final BigdataValueFactory f, - final ILexiconConfiguration config) { + public V asValue(final LexiconRelation lex) { + final BigdataValueFactory f = lex.getValueFactory(); final V v = (V) f.createLiteral(value); v.setIV(this); return v; Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDIntIV.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDIntIV.java 2011-02-24 17:28:05 UTC (rev 4242) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDIntIV.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -28,6 +28,7 @@ import java.math.BigInteger; import com.bigdata.rawstore.Bytes; +import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataLiteral; import com.bigdata.rdf.model.BigdataValueFactory; @@ -57,8 +58,8 @@ } @SuppressWarnings("unchecked") - public V asValue(final BigdataValueFactory f, - final ILexiconConfiguration config) { + public V asValue(final LexiconRelation lex) { + final BigdataValueFactory f = lex.getValueFactory(); final V v = (V) f.createLiteral(value); v.setIV(this); return v; Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDIntegerIV.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDIntegerIV.java 2011-02-24 17:28:05 UTC (rev 4242) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDIntegerIV.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -28,6 +28,7 @@ import java.math.BigInteger; import com.bigdata.btree.keys.KeyBuilder; +import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataLiteral; import com.bigdata.rdf.model.BigdataValueFactory; @@ -61,8 +62,8 @@ } @SuppressWarnings("unchecked") - public V asValue(final BigdataValueFactory f, - final ILexiconConfiguration config) { + public V asValue(final LexiconRelation lex) { + final BigdataValueFactory f = lex.getValueFactory(); // @todo factory should cache the XSD URIs. final V v = (V) f.createLiteral(value.toString(),// f.createURI(DTE.XSDInteger.getDatatype())); Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDLongIV.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDLongIV.java 2011-02-24 17:28:05 UTC (rev 4242) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDLongIV.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -28,6 +28,7 @@ import java.math.BigInteger; import com.bigdata.rawstore.Bytes; +import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataLiteral; import com.bigdata.rdf.model.BigdataValueFactory; @@ -55,8 +56,8 @@ } @SuppressWarnings("unchecked") - public V asValue(final BigdataValueFactory f, - final ILexiconConfiguration config) { + public V asValue(final LexiconRelation lex) { + final BigdataValueFactory f = lex.getValueFactory(); final V v = (V) f.createLiteral(value); v.setIV(this); return v; Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDShortIV.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDShortIV.java 2011-02-24 17:28:05 UTC (rev 4242) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDShortIV.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -28,6 +28,7 @@ import java.math.BigInteger; import com.bigdata.rawstore.Bytes; +import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataLiteral; import com.bigdata.rdf.model.BigdataValueFactory; @@ -57,8 +58,8 @@ } @SuppressWarnings("unchecked") - public V asValue(final BigdataValueFactory f, - final ILexiconConfiguration config) { + public V asValue(final LexiconRelation lex) { + final BigdataValueFactory f = lex.getValueFactory(); final V v = (V) f.createLiteral(value); v.setIV(this); return v; Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java 2011-02-24 17:28:05 UTC (rev 4242) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -1661,7 +1661,7 @@ if (iv.isInline()) { // translate it into a value directly - ret.put(iv, iv.asValue(valueFactory, getLexiconConfiguration())); + ret.put(iv, iv.asValue(this)); } else { @@ -2291,7 +2291,7 @@ final public BigdataValue getTerm(final IV iv) { if (iv.isInline()) - return iv.asValue(valueFactory, getLexiconConfiguration()); + return iv.asValue(this); TermId tid = (TermId) iv; Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/TestEncodeDecodeKeys.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/TestEncodeDecodeKeys.java 2011-02-24 17:28:05 UTC (rev 4242) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/TestEncodeDecodeKeys.java 2011-02-24 17:34:11 UTC (rev 4243) @@ -42,6 +42,7 @@ import com.bigdata.btree.keys.IKeyBuilder; import com.bigdata.btree.keys.KeyBuilder; +import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataBNode; import com.bigdata.rdf.model.BigdataLiteral; import com.bigdata.rdf.model.BigdataURI; @@ -232,8 +233,7 @@ throw new UnsupportedOperationException(); } - public BigdataValue asValue(final BigdataValueFactory f, - final ILexiconConfiguration config) + public BigdataValue asValue(final LexiconRelation lex) throws UnsupportedOperationException { return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2011-02-24 17:28:12
|
Revision: 4242 http://bigdata.svn.sourceforge.net/bigdata/?rev=4242&view=rev Author: martyncutcher Date: 2011-02-24 17:28:05 +0000 (Thu, 24 Feb 2011) Log Message: ----------- Update interface to support more flexible direct buffer transfers Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/AllocationContext.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/IMemoryManager.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/MemoryManager.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/SectorAllocator.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/AllocationContext.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/AllocationContext.java 2011-02-24 16:49:42 UTC (rev 4241) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/AllocationContext.java 2011-02-24 17:28:05 UTC (rev 4242) @@ -80,6 +80,17 @@ } synchronized + public long allocate(final int nbytes) { + + final long addr = m_parent.allocate(nbytes); + + // getSectorAllocation(addr).allocate(addr); + m_addresses.add(Long.valueOf(addr)); + + return addr; + } + + synchronized public void clear() { for (Long addr : m_addresses) { m_parent.free(addr); @@ -105,6 +116,10 @@ return new AllocationContext(this); } + public int allocationSize(final long addr) { + return m_parent.allocationSize(addr); + } + // private SectorAllocation m_head = null; // // /** Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/IMemoryManager.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/IMemoryManager.java 2011-02-24 16:49:42 UTC (rev 4241) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/IMemoryManager.java 2011-02-24 17:28:05 UTC (rev 4242) @@ -51,6 +51,15 @@ public long allocate(ByteBuffer data); /** + * To give more control to the caller by reserving the allocations without + * the requirement to supply a source ByteBuffer. + * + * @param nbytes + * @return an address that will return a ByteBuffer[] using get + */ + public long allocate(int nbytes); + + /** * The ByteBuffer[] return enables the handling of blobs that span more than * a single slot, without the need to create an intermediate ByteBuffer. * @@ -68,9 +77,13 @@ * } * </pre> * + * Furthermore, since the ByteBuffers are not read-only, they can be updated + * directly. In this way the {@link #allocate(int)} can be used + * in conjunction with get to provide more flexibility when storing data. + * * @param addr * An address previously returned by - * {@link #allocate(ByteBuffer)}. + * {@link #allocate(ByteBuffer)} or {@link #allocate(int)}. * * @return array of ByteBuffers */ @@ -94,4 +107,10 @@ */ public IMemoryManager createAllocationContext(); + /** + * @param addr + * @return the number of bytes allocated at the address + */ + public int allocationSize(long addr); + } Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/MemoryManager.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/MemoryManager.java 2011-02-24 16:49:42 UTC (rev 4241) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/MemoryManager.java 2011-02-24 17:28:05 UTC (rev 4242) @@ -49,43 +49,80 @@ private static final Logger log = Logger .getLogger(MemoryManager.class); - private final ByteBuffer m_resource; + final DirectBufferPool m_pool; + private final ByteBuffer[] m_resources; final private ReentrantLock m_allocationLock = new ReentrantLock(); int m_allocation = 0; private final int m_sectorSize; - private final int m_maxResource; private final ArrayList<SectorAllocator> m_sectors = new ArrayList<SectorAllocator>(); private final ArrayList<SectorAllocator> m_free = new ArrayList<SectorAllocator>(); - public MemoryManager(final int maxResource, final int sectorSize) { -// m_resource = DirectBufferPool.INSTANCE.acquire(); - m_resource = ByteBuffer.allocateDirect(maxResource); - m_sectorSize = sectorSize; - m_maxResource = maxResource; + public MemoryManager(final DirectBufferPool pool, final int sectors) { + m_pool = pool; + m_resources = new ByteBuffer[sectors]; + m_sectorSize = pool.getBufferCapacity(); } protected void finalize() throws Throwable { // release to pool. - DirectBufferPool.INSTANCE.release(m_resource); + releaseDirectBuffers(); } + protected void releaseDirectBuffers() throws Throwable { + // release to pool. + for (ByteBuffer buf : m_resources) { + if (buf != null) + DirectBufferPool.INSTANCE.release(buf); + } + } + + /** + * The memory manager can handle the ByteBuffer allocation and copying + * directly. + */ public long allocate(final ByteBuffer data) { if (data == null) throw new IllegalArgumentException(); + + final long retaddr = allocate(data.remaining()); + + ByteBuffer[] bufs = get(retaddr); + final ByteBuffer src = data.duplicate(); + int pos = 0; + for (int i = 0; i < bufs.length; i++) { + final int tsize = bufs[i].remaining(); + src.position(pos); + src.limit(pos + tsize); + bufs[i].put(src); + pos += tsize; + } + + return retaddr; + } + + public long allocate(final int nbytes) { m_allocationLock.lock(); try { - final int size = data.remaining(); - if (size <= SectorAllocator.BLOB_SIZE) { + if (nbytes <= SectorAllocator.BLOB_SIZE) { if (m_free.size() == 0) { - if ((m_allocation + m_sectorSize) > m_maxResource) { + if (!(m_sectors.size() < m_resources.length)) { throw new MemoryManagerResourceError(); } + // Allocate new buffer + ByteBuffer nbuf = m_pool.acquire(); + if (nbuf == null) { + throw new MemoryManagerResourceError(); + } + + m_resources[m_sectors.size()] = nbuf; + SectorAllocator sector = new SectorAllocator(this, null); sector.setSectorAddress(m_allocation, m_sectorSize); sector.setIndex(m_sectors.size()); + m_sectors.add(sector); m_allocation += m_sectorSize; @@ -93,7 +130,7 @@ final SectorAllocator sector = m_free.get(0); - final int rwaddr = sector.alloc(size); + final int rwaddr = sector.alloc(nbytes); if (SectorAllocator.getSectorIndex(rwaddr) >= m_sectors.size()) { throw new IllegalStateException("Address: " + rwaddr + " yields index: " + SectorAllocator.getSectorIndex(rwaddr)); @@ -103,31 +140,29 @@ log.trace("allocating bit: " + SectorAllocator.getSectorOffset(rwaddr)); // Now copy the data to the backing resource - final long paddr = sector.getPhysicalAddress(SectorAllocator.getSectorOffset(rwaddr)); - final ByteBuffer dest = m_resource.duplicate(); - dest.position((int) paddr); - dest.limit((int) (paddr + size)); - dest.put(data); +// final long paddr = sector.getPhysicalAddress(SectorAllocator.getSectorOffset(rwaddr)); +// final ByteBuffer dest = m_resources[sector.m_index].duplicate(); +// final int bufferAddr = (int) (paddr - (sector.m_index * m_sectorSize)); +// dest.position(bufferAddr); +// dest.limit(bufferAddr + nbytes); +// dest.put(data); - return makeAddr(rwaddr, size); + return makeAddr(rwaddr, nbytes); } else { /** * For Blob allocation call the normal allocate and retrieve * the allocation address to store in the blob header. */ - final int nblocks = SectorAllocator.getBlobBlockCount(size); + final int nblocks = SectorAllocator.getBlobBlockCount(nbytes); final ByteBuffer hdrbuf = ByteBuffer.allocate(nblocks * 4); for (int i = 0; i < nblocks; i++) { - final ByteBuffer src = data.duplicate(); final int pos = SectorAllocator.BLOB_SIZE * i; - src.position(pos); - final int bsize = i < (nblocks-1) ? SectorAllocator.BLOB_SIZE : size - pos; - src.limit(pos + bsize); + final int bsize = i < (nblocks-1) ? SectorAllocator.BLOB_SIZE : nbytes - pos; /* * BLOB RECURSION */ - final long bpaddr = allocate(src); + final long bpaddr = allocate(bsize); hdrbuf.putInt(getAllocationAddress(bpaddr)); } @@ -135,9 +170,11 @@ hdrbuf.flip(); final int retaddr = getAllocationAddress(allocate(hdrbuf)); - return makeAddr(retaddr, size); + return makeAddr(retaddr, nbytes); } + } catch (InterruptedException e) { + throw new RuntimeException(e); } finally { m_allocationLock.unlock(); } @@ -161,6 +198,8 @@ for (int i = 0; i < nblocks; i++) { int blockSize = remaining <= SectorAllocator.BLOB_SIZE ? remaining : SectorAllocator.BLOB_SIZE; blobbufs[i] = getBuffer(hdrbuf.getInt(), blockSize); + + remaining -= blockSize; } return blobbufs; @@ -192,12 +231,12 @@ final SectorAllocator sector = getSector(rwaddr); final int offset = SectorAllocator.getSectorOffset(rwaddr); - int resAddr = (int) sector.getPhysicalAddress(offset); + final long paddr = sector.getPhysicalAddress(offset); + final ByteBuffer ret = m_resources[sector.m_index].duplicate(); + final int bufferAddr = (int) (paddr - (sector.m_index * m_sectorSize)); + ret.position(bufferAddr); + ret.limit(bufferAddr + size); - final ByteBuffer ret = m_resource.duplicate(); - ret.position(resAddr); - ret.limit(resAddr + size); - return ret; } @@ -268,6 +307,14 @@ m_sectors.clear(); m_free.clear(); m_allocation = 0; + try { + releaseDirectBuffers(); + } catch (Throwable e) { + log.warn("Unable to release direct buffers", e); + } + for (int i = 0; i < m_resources.length; i++) { + m_resources[i] = null; + } } finally { m_allocationLock.unlock(); } @@ -290,11 +337,16 @@ public void trimSector(final long trim, final SectorAllocator sector) { assert m_free.get(0) == sector; - m_allocation -= trim; + // Do not trim when using buffer pool + // m_allocation -= trim; } public IMemoryManager createAllocationContext() { return new AllocationContext(this); } + public int allocationSize(final long addr) { + return getAllocationSize(addr); + } + } Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/SectorAllocator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/SectorAllocator.java 2011-02-24 16:49:42 UTC (rev 4241) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/rwstore/sector/SectorAllocator.java 2011-02-24 17:28:05 UTC (rev 4242) @@ -31,22 +31,26 @@ import org.apache.log4j.Logger; +import com.bigdata.io.DirectBufferPool; import com.bigdata.rwstore.FixedOutputStream; +import com.bigdata.rwstore.IAllocationContext; import com.bigdata.rwstore.IWriteCacheManager; +import com.bigdata.rwstore.RWSectorStore; +import com.bigdata.rwstore.RWWriteCacheService; /** * The SectorAllocator is designed as an alternative the the standard RWStore * FixedAllocators. - * <p> + * * The idea of the SectorAllocator is to efficiently contain within a single * region as dense a usage as possible. Since a SectorAllocator is able to * allocate a full range of slot sizes, it should be able to service several - * thousand allocations and maximize disk locality on write. - * <p> + * thousand allocations and maximise disk locality on write. + * * Furthermore, it presents an option to be synced with the backing store - * similarly to a MappedFile, in which case a single write for the entire * sector could be made for update. - * <p> + * * What we do not want is to run out of bits and to leave significant unused * space in the sector. This could happen if we primarily allocated small * slots - say on average 512 bytes. In this case, the maximum 1636 entries @@ -62,19 +66,25 @@ * sectors. Implying a maximum addressable store file of 64M * 64K, * = 4TB of full sectors. If the average sector only requires 32M, then the * total store would be reduced appropriately. - * <p> + * * The maximum theoretical storage is yielded by MAX_INT * AVG_SLOT_SIZE, so * 2GB * 2K (avg) would equate to the optimal maximum addressable allocations * and file size. An AVG of > 2K yields fewer allocations and an AVG of < 2K * a reduced file size. * * TODO: add parameterisation of META_SIZE for exploitation by MemoryManager. + * TODO: cache block starts in m_addresses to simplify/optimise bit2Offset * + * When a new SectorAllocator is at the head of the free list, a store + * such as the RWSectorStore can use an in-memory buffer to write the data + * to - sized to the full size of the sector. This can be written in a single + * write to the WriteCacheService. + * * @author Martyn Cutcher + * */ -public class SectorAllocator { - - private static final Logger log = Logger +public class SectorAllocator implements Comparable { + protected static final Logger log = Logger .getLogger(SectorAllocator.class); static final int getBitMask(int bits) { @@ -84,29 +94,28 @@ return ret; } - - private static final int SECTOR_INDEX_BITS = 16; - private static final int SECTOR_OFFSET_BITS = 32-SECTOR_INDEX_BITS; - private static final int SECTOR_OFFSET_MASK = getBitMask(SECTOR_OFFSET_BITS); + static final int SECTOR_INDEX_BITS = 16; + static final int SECTOR_OFFSET_BITS = 32-SECTOR_INDEX_BITS; + static final int SECTOR_OFFSET_MASK = getBitMask(SECTOR_OFFSET_BITS); - private static final int META_SIZE = 8192; // 8K + static final int META_SIZE = 8192; // 8K -// private final static int SECTOR_SIZE = 64 * 1024 * 1024; // 10M - private final static int NUM_ENTRIES = (META_SIZE - 12) / (4 + 1); // 8K - index - address / (4 + 1) bits plus tag -// private final int[] BIT_MASKS = {0x1, 0x3, 0x7, 0xF, 0xFF, 0xFFFF, 0xFFFFFFFF}; - final static int BLOB_SIZE = 4096; -// private final static int BLOB_CHAIN_OFFSET = BLOB_SIZE - 4; - private final static int[] ALLOC_SIZES = {64, 128, 256, 512, 1024, 2048, BLOB_SIZE}; - private final static int[] ALLOC_BITS = {32, 32, 32, 32, 32, 32, 32}; - private int m_index; - private long m_sectorAddress; - private int m_maxSectorSize; - private final byte[] m_tags = new byte[NUM_ENTRIES]; - private final int[] m_bits = new int[NUM_ENTRIES]; // 128 - sectorAddress(1) - m_tags(4) + final static int SECTOR_SIZE = 64 * 1024 * 1024; // 64M + final static int NUM_ENTRIES = (META_SIZE - 12) / (4 + 1); // 8K - index - address (- chksum) / (4 + 1) bits plus tag + final int[] BIT_MASKS = {0x1, 0x3, 0x7, 0xF, 0xFF, 0xFFFF, 0xFFFFFFFF}; + final public static int BLOB_SIZE = 4096; + final static int BLOB_CHAIN_OFFSET = BLOB_SIZE - 4; + final public static int[] ALLOC_SIZES = {64, 128, 256, 512, 1024, 2048, BLOB_SIZE}; + final static int[] ALLOC_BITS = {32, 32, 32, 32, 32, 32, 32}; + int m_index; + long m_sectorAddress; + int m_maxSectorSize; + byte[] m_tags = new byte[NUM_ENTRIES]; + int[] m_bits = new int[NUM_ENTRIES]; // 128 - sectorAddress(1) - m_tags(4) - private int[] m_transientbits = new int[NUM_ENTRIES]; - private int[] m_commitbits = new int[NUM_ENTRIES]; - private final int[] m_addresses = new int[NUM_ENTRIES]; + int[] m_transientbits = new int[NUM_ENTRIES]; + int[] m_commitbits = new int[NUM_ENTRIES]; + int[] m_addresses = new int[NUM_ENTRIES]; // maintain count against each alloc size, this provides ready access to be // able to check the minimum number of bits for all tag sizes. No @@ -117,18 +126,17 @@ // only the total number of bits, but the average number of bits for the // tag, dividing the numebr of free bits by the total (number of blocks) // for each tag. - final private int[] m_free = new int[ALLOC_SIZES.length]; - final private int[] m_total = new int[ALLOC_SIZES.length]; - final private int[] m_allocations = new int[ALLOC_SIZES.length]; - final private int[] m_recycles = new int[ALLOC_SIZES.length]; + int[] m_free = new int[ALLOC_SIZES.length]; + int[] m_total = new int[ALLOC_SIZES.length]; + int[] m_allocations = new int[ALLOC_SIZES.length]; + int[] m_recycles = new int[ALLOC_SIZES.length]; - private final ISectorManager m_store; + final ISectorManager m_store; + boolean m_onFreeList = false; + private int m_diskAddr; private final IWriteCacheManager m_writes; - private boolean m_onFreeList = false; - private long m_diskAddr; - - public SectorAllocator(final ISectorManager store, final IWriteCacheManager writes) { + public SectorAllocator(ISectorManager store, IWriteCacheManager writes) { m_store = store; m_writes = writes; } @@ -186,6 +194,14 @@ if (m_free[tag] == 0) { if (!addNewTag(tag)) { + if (log.isInfoEnabled()) { + StringBuffer str = new StringBuffer("Removing Sector #" + m_index + ": "); + for (int t = 0; t < m_free.length; t++) { + str.append("[" + m_allocations[t] + "," + m_free[t] + "," + m_recycles[t] + "]"); + } + + log.info(str.toString()); + } m_store.removeFromFreeList(this); m_onFreeList = false; } @@ -210,14 +226,14 @@ } public static int makeAddr(final int index, final int bit) { - return -((index << SECTOR_OFFSET_BITS) + bit); + return -(((index+1) << SECTOR_OFFSET_BITS) + bit); } private boolean addNewTag(byte tag) { int allocated = 0; for (int i = 0; i < m_tags.length; i++) { if (m_tags[i] == -1) { - int block = SectorAllocator.ALLOC_SIZES[tag] * 32; + int block = this.ALLOC_SIZES[tag] * 32; if ((allocated + block) <= m_maxSectorSize) { m_tags[i] = tag; m_free[tag] += 32; @@ -277,8 +293,16 @@ // The hasFree test is too coarse, ideally we should test for // percentage of free bits - say 10% PLUS a minimum of say 10 // for each tag type. - if ((!m_onFreeList) && hasFree(5)) { // minimum of 10 bits for all tags + if ((!m_onFreeList) && hasFree(2)) { // minimum of 5 bits for each 32 bit block m_onFreeList = true; + if (log.isInfoEnabled()) { + StringBuffer str = new StringBuffer("Returning Sector #" + m_index + ": "); + for (int t = 0; t < m_free.length; t++) { + str.append("("+ (m_free[t]/m_total[t]) + ")[T" + (m_total[t] * 32) + ",A" + m_allocations[t] + ",F" + m_free[t] + ",R" + m_recycles[t] + "]"); + } + + log.info(str.toString()); + } m_store.addToFreeList(this); } @@ -367,7 +391,11 @@ * */ public long getPhysicalAddress(int offset) { - return m_sectorAddress + bit2Offset(offset); + if (!tstBit(m_transientbits, offset)) { + return 0L; + } else { + return m_sectorAddress + bit2Offset(offset); + } } public int getPhysicalSize(int offset) { @@ -383,9 +411,14 @@ return null; } + /** + * + * @param threshold the minimum number of bits free per 32 bit block + * @return whether there are sufficient free for all block sizes + */ public boolean hasFree(int threshold) { for (int i = 0; i < m_free.length; i++) { - if ((m_free[i]/m_total[i]) < threshold) + if (m_free[i] < (threshold * m_total[i])) return false; } return true; @@ -408,12 +441,15 @@ try { m_index = str.readInt(); m_sectorAddress = str.readLong(); + + System.out.println("Sector: " + m_index + " managing sector at " + m_sectorAddress); + int taglen = str.read(m_tags); assert taglen == m_tags.length; m_addresses[0] = 0; for (int i = 0; i < NUM_ENTRIES; i++) { - m_bits[i] = str.readInt(); + m_commitbits[i] = m_transientbits[i] = m_bits[i] = str.readInt(); // maintain cached block offset if (i < (NUM_ENTRIES-1)) { @@ -428,11 +464,11 @@ } } - public long getDiskAddr() { + public int getDiskAddr() { return m_diskAddr; } - public void setDiskAddr(long addr) { + public void setDiskAddr(int addr) { m_diskAddr = addr; } @@ -532,7 +568,7 @@ */ public void setSectorAddress(final long sectorAddress, final int maxsize) { if (log.isInfoEnabled()) - log.info("setting sector address: " + sectorAddress); + log.info("setting sector #" + m_index + " address: " + sectorAddress); m_sectorAddress = sectorAddress; m_maxSectorSize = maxsize; @@ -553,18 +589,86 @@ m_store.addToFreeList(this); } - public static int getSectorIndex(final int rwaddr) { - return (-rwaddr) >> SECTOR_OFFSET_BITS; + public static int getSectorIndex(int rwaddr) { + return ((-rwaddr) >>> SECTOR_OFFSET_BITS) - 1; } - public static int getSectorOffset(final int rwaddr) { + public static int getSectorOffset(int rwaddr) { return (-rwaddr) & SECTOR_OFFSET_MASK; } - public static int getBlobBlockCount(final int size) { + public static int getBlobBlockCount(int size) { final int nblocks = (size + BLOB_SIZE - 1) / BLOB_SIZE; return nblocks; } + public static int getBlockForSize(int size) { + for (int i = 0; i < ALLOC_SIZES.length; i++) { + if (size <= ALLOC_SIZES[i]) { + return ALLOC_SIZES[i]; + } + } + + throw new IllegalArgumentException("Size does not fit in a slot"); + } + + public int compareTo(Object other) { + final int oindex = ((SectorAllocator) other).m_index; + + return m_index < oindex ? -1 : (m_index > oindex ? 1 : 0); + } + + public int getIndex() { + return m_index; + } + + public void releaseSession(IWriteCacheManager cache) { + // TODO Auto-generated method stub + + } + + public boolean addressInRange(int addr) { + // TODO Auto-generated method stub + return false; + } + + public int getAllocatedBlocks() { + // TODO Auto-generated method stub + return 0; + } + + public long getFileStorage() { + // TODO Auto-generated method stub + return 0; + } + + public long getAllocatedSlots() { + // TODO Auto-generated method stub + return 0; + } + + public boolean canImmediatelyFree(int addr, int sze, IAllocationContext context) { + // TODO Auto-generated method stub + return false; + } + + public boolean isAllocated(int addrOffset) { + return tstBit(m_bits, addrOffset); + } + + public void free(int addr, int sze, boolean overrideSession) { + free(addr); + } + + public void setAllocationContext(IAllocationContext m_context) { + // TODO Auto-generated method stub + + } + + public int alloc(RWSectorStore sectorStore, int size, IAllocationContext context) { + + return alloc(size); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tho...@us...> - 2011-02-24 16:49:52
|
Revision: 4241 http://bigdata.svn.sourceforge.net/bigdata/?rev=4241&view=rev Author: thompsonbry Date: 2011-02-24 16:49:42 +0000 (Thu, 24 Feb 2011) Log Message: ----------- More work on the Runtime optimizer. JGraph: After each round, including the first, the logic now remove any entries from the edgeSamples map which do not correspond to a prefix for a surviving join path. This reduces the heap pressure of the RTO. SampleBase: Encapsulated the [sample] field as a private atomic reference and exposed a method to release the sampled solution set. This reduces heap pressure on the JVM and is forward looking to storing materialized samples on the native C heap using the memory manager. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Path.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/SampleBase.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java 2011-02-24 16:42:05 UTC (rev 4240) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java 2011-02-24 16:49:42 UTC (rev 4241) @@ -30,6 +30,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.Formatter; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; @@ -968,9 +969,15 @@ } // next path + /* + * Now examine the set of generated and sampled join paths. If any paths + * span the same vertices then they are alternatives and we can pick the + * best alternative now and prune the other alternatives for those + * vertices. + */ final Path[] paths_tp1 = tmp.toArray(new Path[tmp.size()]); - final Path[] paths_tp1_pruned = pruneJoinPaths(paths_tp1); + final Path[] paths_tp1_pruned = pruneJoinPaths(paths_tp1, edgeSamples); if (log.isDebugEnabled()) log.debug("\n*** round=" + round + ", limit=" + limit @@ -1153,22 +1160,26 @@ /** * Prune paths which are dominated by other paths. Paths are extended in * each round. Paths from previous rounds are always pruned. Of the new - * paths in each round, the following rule is applied to prune the - * search to just those paths which are known to dominate the other - * paths covering the same set of vertices: + * paths in each round, the following rule is applied to prune the search to + * just those paths which are known to dominate the other paths covering the + * same set of vertices: * <p> * If there is a path, [p] != [p1], where [p] is an unordered variant of - * [p1] (that is the vertices of p are the same as the vertices of p1), - * and the cumulative cost of [p] is LTE the cumulative cost of [p1], - * then [p] dominates (or is equivalent to) [p1] and p1 should be - * pruned. + * [p1] (that is the vertices of p are the same as the vertices of p1), and + * the cumulative cost of [p] is LTE the cumulative cost of [p1], then [p] + * dominates (or is equivalent to) [p1] and p1 should be pruned. * * @param a * A set of paths. + * @param edgeSamples + * The set of samples for path segments. Samples which are no + * longer in use after pruning will be cleared from the map and + * their materialized solution sets will be discarded. * * @return The set of paths with all dominated paths removed. */ - public Path[] pruneJoinPaths(final Path[] a) { + public Path[] pruneJoinPaths(final Path[] a, + final Map<PathIds, EdgeSample> edgeSamples) { /* * Find the length of the longest path(s). All shorter paths are * dropped in each round. @@ -1237,13 +1248,84 @@ } } // Pj } // Pi - final Set<Path> keep = new LinkedHashSet<Path>(); - for (Path p : a) { - if (pruned.contains(p)) - continue; - keep.add(p); + /* + * Generate a set of paths which will be retained. + */ + final Path[] b; + { + final Set<Path> keep = new LinkedHashSet<Path>(); + for (Path p : a) { + if (pruned.contains(p)) + continue; + keep.add(p); + } + // convert the retained paths to an array. + b = keep.toArray(new Path[keep.size()]); } - final Path[] b = keep.toArray(new Path[keep.size()]); + /* + * Clear any entries from the edgeSamples map which are not prefixes of + * the retained join paths. + */ + { + + final Iterator<Map.Entry<PathIds, EdgeSample>> itr = edgeSamples + .entrySet().iterator(); + + int ncleared = 0; + while (itr.hasNext()) { + + final Map.Entry<PathIds, EdgeSample> e = itr.next(); + + final PathIds ids = e.getKey(); + + // Consider the retained paths. + boolean found = false; + + for (Path p : b) { + + if (p.beginsWith(ids.ids)) { + + // This sample is still in use. + found = true; + + break; + + } + + } + + if (!found) { + + /* + * Clear sample no longer in use. + * + * Note: In fact, holding onto the sample metadata is + * relatively cheap if there was a reason to do so (it only + * effects the size of the [edgeSamples] map). It is holding + * onto the materialized solution set which puts pressure on + * the heap. + */ + if (log.isTraceEnabled()) + log.trace("Clearing sample: " + ids); + + // release the sampled solution set. + e.getValue().releaseSample(); + + // clear the entry from the array. + itr.remove(); + + ncleared++; + + } + + } + + if (ncleared > 0 && log.isDebugEnabled()) + log.debug("Cleared " + ncleared + " samples"); + + } + + // Return the set of retained paths. return b; } Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Path.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Path.java 2011-02-24 16:42:05 UTC (rev 4240) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Path.java 2011-02-24 16:49:42 UTC (rev 4241) @@ -202,7 +202,7 @@ if (edgeSample == null) throw new IllegalArgumentException(); - if (edgeSample.sample == null) + if (edgeSample.getSample() == null) throw new IllegalArgumentException(); // this.edges = Collections.singletonList(e); @@ -264,7 +264,7 @@ if (edgeSample == null) throw new IllegalArgumentException(); - if (edgeSample.sample == null) + if (edgeSample.getSample() == null) throw new IllegalArgumentException(); // this.edges = Collections.unmodifiableList(edges); @@ -457,9 +457,11 @@ if (p == null) throw new IllegalArgumentException(); - if (vertices.length > p.vertices.length) { + if (vertices.length < p.vertices.length) { + // Proven false since the caller's path is longer. return false; + } for (int i = 0; i < p.vertices.length; i++) { @@ -480,6 +482,43 @@ } /** + * Return <code>true</code> if this path begins with the given path. + * + * @param p + * The given path. + * + * @return <code>true</code> if this path begins with the given path. + * + * @todo unit tests. + */ + public boolean beginsWith(final int[] ids) { + + if (ids == null) + throw new IllegalArgumentException(); + + if (vertices.length < ids.length) { + // Proven false since the caller's path is longer. + return false; + } + + for (int i = 0; i < ids.length; i++) { + + final int idSelf = vertices[i].pred.getId(); + + final int idOther = ids[i]; + + if (idSelf != idOther) { + + return false; + + } + + } + + return true; + } + + /** * Return the first N {@link IPredicate}s in this {@link Path}. * * @param length @@ -658,7 +697,7 @@ if (sourceSample == null) throw new IllegalArgumentException(); - if (sourceSample.sample == null) + if (sourceSample.getSample() == null) throw new IllegalArgumentException(); // Figure out which constraints attach to each predicate. @@ -749,7 +788,7 @@ new LocalChunkMessage<IBindingSet>(queryEngine, queryId, joinOp .getId()/* startId */, -1 /* partitionId */, new ThickAsynchronousIterator<IBindingSet[]>( - new IBindingSet[][] { sourceSample.sample }))); + new IBindingSet[][] { sourceSample.getSample() }))); final List<IBindingSet> result = new LinkedList<IBindingSet>(); try { Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/SampleBase.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/SampleBase.java 2011-02-24 16:42:05 UTC (rev 4240) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/SampleBase.java 2011-02-24 16:49:42 UTC (rev 4241) @@ -27,6 +27,10 @@ package com.bigdata.bop.joinGraph.rto; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.log4j.Logger; + import com.bigdata.bop.IBindingSet; import com.bigdata.rwstore.sector.IMemoryManager; @@ -36,9 +40,22 @@ * * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ + * + * TODO Large samples should be buffered on the {@link IMemoryManager} + * so they do not pose a burden on the heap. This will require us to + * manage the allocation contexts so we can release samples in a timely + * manner once they are no longer used and always release samples by + * the time the RTO is finished. [There is an additional twist if we + * have fully materialized some part of the join since we no longer + * need to evaluate that path segment. If the RTO can interleave query + * evaluation with exploration then we can take advantage of these + * materialized solutions.] */ public abstract class SampleBase { + private static final transient Logger log = Logger + .getLogger(SampleBase.class); + /** * The estimated cardinality of the underlying access path (for a vertex) or * the join (for a cutoff join). @@ -46,7 +63,7 @@ public final long estimatedCardinality; /** - * The limit used to produce the {@link #sample}. + * The limit used to produce the {@link #getSample() sample}. */ public final int limit; @@ -77,20 +94,39 @@ /** * Sample. + */ + private final AtomicReference<IBindingSet[]> sampleRef = new AtomicReference<IBindingSet[]>(); + + /** + * The sampled solution set. * - * TODO Large samples should be buffered on the {@link IMemoryManager} so - * they do not pose a burden on the heap. This will require us to manage the - * allocation contexts so we can release samples in a timely manner once - * they are no longer used and always release samples by the time the RTO is - * finished. [There is an additional twist if we have fully materialized - * some part of the join since we no longer need to evaluate that path - * segment. If the RTO can interleave query evaluation with exploration - * then we can take advantage of these materialized solutions.] + * @return The sampled solution set -or- <code>null</code> if it has been + * released. */ - final IBindingSet[] sample; + IBindingSet[] getSample() { + + return sampleRef.get(); + + } /** + * Release the sampled solution set. * + * TODO MEMORY MANAGER : release. + */ + void releaseSample() { + + if (sampleRef.getAndSet(null) != null) { + + if (log.isTraceEnabled()) + log.trace("Released sample: " + this); + + } + + } + + /** + * * @param estimatedCardinality * The estimated cardinality. * @param limit @@ -126,7 +162,7 @@ this.estimateEnum = estimateEnum; - this.sample = sample; + this.sampleRef.set(sample); } @@ -147,7 +183,10 @@ sb.append("{estimatedCardinality=" + estimatedCardinality); sb.append(",limit=" + limit); sb.append(",estimateEnum=" + estimateEnum); - sb.append(",sampleSize=" + sample.length); + { + final IBindingSet[] tmp = sampleRef.get(); + sb.append(",sampleSize=" + (tmp != null ? tmp.length : "N/A")); + } toString(sb); // allow extension sb.append("}"); return sb.toString(); Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java 2011-02-24 16:42:05 UTC (rev 4240) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java 2011-02-24 16:49:42 UTC (rev 4241) @@ -24,10 +24,12 @@ import com.bigdata.journal.Journal; import com.bigdata.rdf.internal.XSDIntIV; import com.bigdata.rdf.internal.constraints.CompareBOp; +import com.bigdata.rdf.internal.constraints.Constraint; +import com.bigdata.rdf.internal.constraints.IsBoundBOp; import com.bigdata.rdf.internal.constraints.MathBOp; import com.bigdata.rdf.internal.constraints.NotBOp; import com.bigdata.rdf.internal.constraints.SameTermBOp; -import com.bigdata.rdf.internal.constraints.Constraint; +import com.bigdata.rdf.model.BigdataLiteral; import com.bigdata.rdf.model.BigdataURI; import com.bigdata.rdf.model.BigdataValue; import com.bigdata.rdf.model.BigdataValueFactory; @@ -432,19 +434,19 @@ } - /* - * Run w/o constraints. + /* + * Run w/o constraints. + * + * Note: There are no solutions for this query against BSBM 100. The + * optimizer is only providing the fastest path to prove that. We have + * to use a larger data set if we want to verify the optimizers join + * path for a query which produces solutions in the data. * - * Note: There are no solutions for this query against BSBM 100. The - * optimizer is only providing the fastest path to prove that. We have - * to use a larger data set if we want to verify the optimizers join - * path for a query which produces solutions in the data. - * * Note: The optimizer finds the same join path for the BSBM 100, 100M, * and 200M data sets - */ + */ if (true) { - /* + /* 100M: static: ids=[1, 2, 4, 6, 0, 3, 5] *** round=5, limit=600: paths{in=1,considered=1,out=1} @@ -470,14 +472,15 @@ 0 166410 * 1.00 ( 600/ 600/ 600) = 166410 : 998460 [ 1 2 0 4 6 3 5 ] test_bsbm_q5 : Total times: static=8871, runtime=8107, delta(static-runtime)=764 - */ + */ final IPredicate<?>[] runtimeOrder = doTest(preds, null/* constraints */); -// assertEquals("runtimeOrder", new int[] { 1, 2, 0, 4, 6, 3, 5 }, BOpUtility.getPredIds(runtimeOrder)); + assertEquals("runtimeOrder", new int[] { 1, 2, 0, 4, 6, 3, 5 }, + BOpUtility.getPredIds(runtimeOrder)); } // Run w/ constraints. if(true){ - /* + /* 100M: static: ids=[1, 2, 4, 6, 0, 3, 5] *** round=5, limit=600: paths{in=4,considered=4,out=1} @@ -503,12 +506,233 @@ 0 1941 * 1.00 ( 7/ 7/ 7) = 1941 : 344799 [ 1 2 4 3 6 5 0 ] test_bsbm_q5 : Total times: static=7312, runtime=3305, delta(static-runtime)=4007 - - */ + + */ final IPredicate<?>[] runtimeOrder = doTest(preds, constraints); -// assertEquals("runtimeOrder", new int[] { 1, 2, 0, 4, 6, 3, 5 }, BOpUtility.getPredIds(runtimeOrder)); + assertEquals("runtimeOrder", new int[] { 1, 2, 4, 3, 6, 5, 0 }, + BOpUtility.getPredIds(runtimeOrder)); } } + /** + * BSBM Q3 + * + * <pre> + * PREFIX bsbm-inst: <http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/> + * PREFIX bsbm: <http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/> + * PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> + * PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + * + * SELECT ?product ?label + * WHERE { + * ?product rdfs:label ?label . + * ?product a %ProductType% . + * ?product bsbm:productFeature %ProductFeature1% . + * ?product bsbm:productPropertyNumeric1 ?p1 . + * FILTER ( ?p1 > %x% ) + * ?product bsbm:productPropertyNumeric3 ?p3 . + * FILTER (?p3 < %y% ) + * OPTIONAL { + * ?product bsbm:productFeature %ProductFeature2% . + * ?product rdfs:label ?testVar } + * FILTER (!bound(?testVar)) + * } + * ORDER BY ?label + * LIMIT 10 + * </pre> + */ + public void test_bsbm_q3() throws Exception { + + fail("This test needs instance data for BSBM 100 and 100M"); + + QueryLog.logTableHeader(); + + final String namespace = getNamespace(); + + final AbstractTripleStore database = getDatabase(namespace); + + /* + * Resolve terms against the lexicon. + */ + final BigdataValueFactory valueFactory = database.getLexiconRelation() + .getValueFactory(); + + final String rdfs = "http://www.w3.org/2000/01/rdf-schema#"; + final String rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; + final String bsbm = "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/"; + final String bsbmInst ="http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/"; + + final BigdataURI rdfType = valueFactory.createURI(rdf + "type"); + + final BigdataURI rdfsLabel = valueFactory.createURI(rdfs + "label"); + + final BigdataURI productFeature = valueFactory.createURI(bsbm + + "productFeature"); + + final BigdataURI productPropertyNumeric1 = valueFactory.createURI(bsbm + + "productPropertyNumeric1"); + + final BigdataURI productPropertyNumeric3 = valueFactory.createURI(bsbm + + "productPropertyNumeric3"); + + // FIXME parameters + final BigdataURI productType = valueFactory.createURI(productInstance); + final BigdataURI productFeature1 = valueFactory.createURI(productInstance); + final BigdataURI productFeature2 = valueFactory.createURI(productInstance); + final BigdataLiteral x = valueFactory.createLiteral(productInstance); + final BigdataLiteral y = valueFactory.createLiteral(productInstance); + + final BigdataValue[] terms = new BigdataValue[] { rdfType, rdfsLabel, + productFeature, productPropertyNumeric1, + productPropertyNumeric3, productType, productFeature1, + productFeature2, x, y }; + + // resolve terms. + database.getLexiconRelation() + .addTerms(terms, terms.length, true/* readOnly */); + + { + for (BigdataValue tmp : terms) { + System.out.println(tmp + " : " + tmp.getIV()); + if (tmp.getIV() == null) + throw new RuntimeException("Not defined: " + tmp); + } + } + + final IConstraint[] constraints; + final IPredicate[] preds; + final IPredicate p0, p1, p2, p3, p4, p5, p6; + final IConstraint c0, c1, c2; + { + final IVariable product = Var.var("product"); + final IVariable label = Var.var("label"); + final IVariable p1Var = Var.var("p1"); + final IVariable p3Var = Var.var("p3"); + final IVariable testVar = Var.var("testVar"); + + // The name space for the SPO relation. + final String[] spoRelation = new String[] { namespace + ".spo" }; + +// // The name space for the Lexicon relation. +// final String[] lexRelation = new String[] { namespace + ".lex" }; + + final long timestamp = database.getIndexManager().getLastCommitTime(); + + int nextId = 0; + +// ?product rdfs:label ?label . + p0 = new SPOPredicate(new BOp[] {// + product, + new Constant(rdfsLabel.getIV()), + label// + },// + new NV(BOp.Annotations.BOP_ID, nextId++),// + new NV(Annotations.TIMESTAMP, timestamp),// + new NV(IPredicate.Annotations.RELATION_NAME, spoRelation)// + ); + + // ?product a %ProductType% . + p1 = new SPOPredicate(new BOp[] {// + product, + new Constant(rdfType.getIV()), + new Constant(productType.getIV())// + },// + new NV(BOp.Annotations.BOP_ID, nextId++),// + new NV(Annotations.TIMESTAMP, timestamp),// + new NV(IPredicate.Annotations.RELATION_NAME, spoRelation)// + ); + + // ?product bsbm:productFeature %ProductFeature1% . + p2 = new SPOPredicate(new BOp[] {// + product, + new Constant(productFeature.getIV()), + new Constant(productFeature1.getIV())// + },// + new NV(BOp.Annotations.BOP_ID, nextId++),// + new NV(Annotations.TIMESTAMP, timestamp),// + new NV(IPredicate.Annotations.RELATION_NAME, spoRelation)// + ); + + // ?product bsbm:productPropertyNumeric1 ?p1 . + p3 = new SPOPredicate(new BOp[] {// + product, + new Constant(productPropertyNumeric1.getIV()), + p1Var// + },// + new NV(BOp.Annotations.BOP_ID, nextId++),// + new NV(Annotations.TIMESTAMP, timestamp),// + new NV(IPredicate.Annotations.RELATION_NAME, spoRelation)// + ); + + // ?product bsbm:productPropertyNumeric3 ?p3 . + p4 = new SPOPredicate(new BOp[] {// + product, + new Constant(productPropertyNumeric3.getIV()), + p3Var// + },// + new NV(BOp.Annotations.BOP_ID, nextId++),// + new NV(Annotations.TIMESTAMP, timestamp),// + new NV(IPredicate.Annotations.RELATION_NAME, spoRelation)// + ); + + /* + * FIXME (p5,p6) below in an optional join group! + */ + + // ?product bsbm:productFeature %ProductFeature2% . + p5 = new SPOPredicate(new BOp[] {// + product, + new Constant(productFeature.getIV()), + new Constant(productFeature2.getIV()), + },// + new NV(BOp.Annotations.BOP_ID, nextId++),// + new NV(Annotations.TIMESTAMP, timestamp),// + new NV(IPredicate.Annotations.RELATION_NAME, spoRelation)// + ); + + // ?product rdfs:label ?testVar } + p6 = new SPOPredicate(new BOp[] {// + product, + new Constant(rdfsLabel.getIV()), + testVar, + },// + new NV(BOp.Annotations.BOP_ID, nextId++),// + new NV(Annotations.TIMESTAMP, timestamp),// + new NV(IPredicate.Annotations.RELATION_NAME, spoRelation)// + ); + + // the vertices of the join graph (the predicates). + preds = new IPredicate[] { p0, p1, p2, p3, p4, p5, p6 }; + + // FILTER ( ?p1 > %x% ) + c0 = Constraint.wrap(new CompareBOp(new BOp[] { p1Var, + new Constant(x.getIV()) }, NV.asMap(new NV[] { new NV( + CompareBOp.Annotations.OP, CompareOp.GT) }))); + + // FILTER (?p3 < %y% ) + c1 = Constraint.wrap(new CompareBOp(new BOp[] { p3Var, + new Constant(y.getIV()) }, NV.asMap(new NV[] { new NV( + CompareBOp.Annotations.OP, CompareOp.LT) }))); + + // FILTER (!bound(?testVar)) + c2 = Constraint.wrap(new NotBOp(new IsBoundBOp(testVar))); + + // the constraints on the join graph. + constraints = new IConstraint[] { c0, c1, c2 }; + + } + + /* + * Run the join graph w/ its constraints (?p1>%x% and ?p3<%y%), but not + * the optional join group nor its constraint (!bound(?testVar)). + * + * FIXME The optional join group is part of the tail plan and can not be + * fed into the RTO right now. + */ + final IPredicate<?>[] runtimeOrder = doTest(preds, new IConstraint[] { + c0, c1 }); + + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tho...@us...> - 2011-02-24 16:42:11
|
Revision: 4240 http://bigdata.svn.sourceforge.net/bigdata/?rev=4240&view=rev Author: thompsonbry Date: 2011-02-24 16:42:05 +0000 (Thu, 24 Feb 2011) Log Message: ----------- Disabled use of the external journal in the BSBM RTO test. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java 2011-02-24 16:41:18 UTC (rev 4239) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java 2011-02-24 16:42:05 UTC (rev 4240) @@ -97,7 +97,7 @@ * large data set to assess the relative performance of the static and * runtime query optimizers). */ - private static final boolean useExistingJournal = true; + private static final boolean useExistingJournal = false; private static final long existingPC = 284826; // BSBM 100M This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tho...@us...> - 2011-02-24 16:41:24
|
Revision: 4239 http://bigdata.svn.sourceforge.net/bigdata/?rev=4239&view=rev Author: thompsonbry Date: 2011-02-24 16:41:18 +0000 (Thu, 24 Feb 2011) Log Message: ----------- Reduced a log message from INFO to DEBUG for the initial set of vertices in the RTO. Clean up the RTO trace for (in/read/out) to present the data in a more natural order. Added some notes on the BSBM Q5 run. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java 2011-02-24 12:28:34 UTC (rev 4238) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java 2011-02-24 16:41:18 UTC (rev 4239) @@ -555,14 +555,14 @@ */ sampleAllVertices(queryEngine, limit); - if (log.isInfoEnabled()) { + if (log.isDebugEnabled()) { final StringBuilder sb = new StringBuilder(); sb.append("Vertices:\n"); for (Vertex v : V) { sb.append(v.toString()); sb.append("\n"); } - log.info(sb.toString()); + log.debug(sb.toString()); } /* @@ -1280,14 +1280,14 @@ static public String showTable(final Path[] a,final Path[] pruned) { final StringBuilder sb = new StringBuilder(); final Formatter f = new Formatter(sb); - f.format("%-6s %10s%1s * %10s (%6s/%6s/%6s) = %10s%1s : %10s %10s", + f.format("%-6s %10s%1s * %10s (%6s %6s %6s) = %10s%1s : %10s %10s", "path",// "sourceCard",// "",// sourceSampleExact "f",// - "out",// "in",// "read",// + "out",// "estCard",// "",// estimateIs(Exact|LowerBound|UpperBound) "sumEstCard",// @@ -1308,18 +1308,18 @@ } final EdgeSample edgeSample = x.edgeSample; if (edgeSample == null) { - f.format("%6d %10s%1s * %10s (%6s/%6s/%6s) = %10s%1s : %10s",// + f.format("%6d %10s%1s * %10s (%6s %6s %6s) = %10s%1s : %10s",// i, "N/A", "", "N/A", "N/A", "N/A", "N/A", "N/A", "", "N/A"); } else { - f.format("%6d %10d%1s * % 10.2f (%6d/%6d/%6d) = % 10d%1s : % 10d", // + f.format("%6d %10d%1s * % 10.2f (%6d %6d %6d) = % 10d%1s : % 10d", // i,// edgeSample.sourceSample.estimatedCardinality,// edgeSample.sourceSample.estimateEnum.getCode(),// edgeSample.f,// - edgeSample.outputCount,// edgeSample.inputCount,// edgeSample.tuplesRead,// + edgeSample.outputCount,// edgeSample.estimatedCardinality,// edgeSample.estimateEnum.getCode(),// x.cumulativeEstimatedCardinality// @@ -1360,14 +1360,14 @@ /* * @todo show limit on samples? */ - f.format("%6s %10s%1s * %10s (%6s/%6s/%6s) = %10s%1s : %10s",// + f.format("%6s %10s%1s * %10s (%6s %6s %6s) = %10s%1s : %10s",// "vertex", "sourceCard",// "",// sourceSampleExact "f",// - "out",// "in",// "read",// + "out",// "estCard",// "",// estimateIs(Exact|LowerBound|UpperBound) "sumEstCard"// @@ -1391,19 +1391,19 @@ } sb.append("\n"); if (sample == null) { - f.format("% 6d %10s%1s * %10s (%6s/%6s/%6s) = %10s%1s : %10s",// + f.format("% 6d %10s%1s * %10s (%6s %6s %6s) = %10s%1s : %10s",// predId,// "N/A", "", "N/A", "N/A", "N/A", "N/A", "N/A", "", "N/A"); } else if(sample instanceof VertexSample) { // Show the vertex sample for the initial vertex. - f.format("% 6d %10s%1s * %10s (%6s/%6s/%6s) = % 10d%1s : %10d",// + f.format("% 6d %10s%1s * %10s (%6s %6s %6s) = % 10d%1s : %10d",// predId,// - "NA",//sample.sourceSample.estimatedCardinality,// + "N/A",//sample.sourceSample.estimatedCardinality,// " ",//sample.sourceSample.isExact() ? "E" : "",// " ",//sample.f,// - "N/A",//sample.outputCount,// "N/A",//sample.inputCount,// "N/A",//sample.tuplesRead,// + "N/A",//sample.outputCount,// sample.estimatedCardinality,// sample.estimateEnum.getCode(),// sumEstCard// @@ -1412,14 +1412,14 @@ } else { // Show the sample for a cutoff join with the 2nd+ vertex. final EdgeSample edgeSample = (EdgeSample)sample; - f.format("% 6d %10d%1s * % 10.2f (%6d/%6d/%6d) = % 10d%1s : %10d",// + f.format("% 6d %10d%1s * % 10.2f (%6d %6d %6d) = % 10d%1s : %10d",// predId,// edgeSample.sourceSample.estimatedCardinality,// edgeSample.sourceSample.estimateEnum.getCode(),// edgeSample.f,// - edgeSample.outputCount,// edgeSample.inputCount,// edgeSample.tuplesRead,// + edgeSample.outputCount,// edgeSample.estimatedCardinality,// edgeSample.estimateEnum.getCode(),// sumEstCard// Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java 2011-02-24 12:28:34 UTC (rev 4238) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java 2011-02-24 16:41:18 UTC (rev 4239) @@ -97,11 +97,11 @@ * large data set to assess the relative performance of the static and * runtime query optimizers). */ - private static final boolean useExistingJournal = false; + private static final boolean useExistingJournal = true; -// private static final long existingPC = 284826; // BSBM 100M + private static final long existingPC = 284826; // BSBM 100M - private static final long existingPC = 566496; // BSBM 200M +// private static final long existingPC = 566496; // BSBM 200M private static final File existingJournal = new File("/data/bsbm/bsbm_" + existingPC + "/bigdata-bsbm.RW.jnl"); @@ -432,42 +432,81 @@ } - /* - * Run w/o constraints. - * - * Note: There are no solutions for this query against BSBM 100. The - * optimizer is only providing the fastest path to prove that. We have - * to use a larger data set if we want to verify the optimizers join - * path for a query which produces solutions in the data. - */ - if (false) { + /* + * Run w/o constraints. + * + * Note: There are no solutions for this query against BSBM 100. The + * optimizer is only providing the fastest path to prove that. We have + * to use a larger data set if we want to verify the optimizers join + * path for a query which produces solutions in the data. + * + * Note: The optimizer finds the same join path for the BSBM 100, 100M, + * and 200M data sets + */ + if (true) { + /* +100M: static: ids=[1, 2, 4, 6, 0, 3, 5] + +*** round=5, limit=600: paths{in=1,considered=1,out=1} +path sourceCard * f ( out/ in/ read) = estCard : sumEstCard joinPath + 0 2400 * 1.00 ( 600/ 600/ 600) = 2400 : 9066 [ 1 2 0 4 6 3 5 ] + +*** Selected join path: [1, 2, 0, 4, 6, 3, 5] +vertex sourceCard * f ( out/ in/ read) = estCard : sumEstCard + 1 NA * ( N/A/ N/A/ N/A) = 16E : 16 + 2 16E * 150.00 ( 600/ 4/ 10921) = 2400 : 13337 + 0 2400 * 1.00 ( 600/ 600/ 600) = 2400 : 16337 + 4 2400 * 1.00 ( 600/ 600/ 600) = 2400 : 19337 + 6 2400 * 1.00 ( 600/ 600/ 600) = 2400 : 22337 + 3 2400 * 1.00 ( 600/ 600/ 600) = 2400 : 25337 + 5 N/A * N/A ( N/A/ N/A/ N/A) = N/A : N/A + +test_bsbm_q5 : Total times: static=8741, runtime=8025, delta(static-runtime)=716 + +200M: static: ids=[1, 2, 4, 6, 0, 3, 5] + +*** round=5, limit=600: paths{in=1,considered=1,out=1} +path sourceCard * f ( out/ in/ read) = estCard : sumEstCard joinPath + 0 166410 * 1.00 ( 600/ 600/ 600) = 166410 : 998460 [ 1 2 0 4 6 3 5 ] + +test_bsbm_q5 : Total times: static=8871, runtime=8107, delta(static-runtime)=764 + */ final IPredicate<?>[] runtimeOrder = doTest(preds, null/* constraints */); - /* - * Verify that the runtime optimizer produced the expected join - * path. - * - * Note: The optimizer finds the same join path for the BSBM 100, - * 100M, and 200M data sets - */ - assertEquals("runtimeOrder", new int[] { 1, 2, 0, 4, 6, 3, 5 }, - BOpUtility.getPredIds(runtimeOrder)); +// assertEquals("runtimeOrder", new int[] { 1, 2, 0, 4, 6, 3, 5 }, BOpUtility.getPredIds(runtimeOrder)); } - /* - * Run w/ constraints. - */ + // Run w/ constraints. if(true){ + /* +100M: static: ids=[1, 2, 4, 6, 0, 3, 5] + +*** round=5, limit=600: paths{in=4,considered=4,out=1} +path sourceCard * f ( out/ in/ read) = estCard : sumEstCard joinPath + 0 107 * 1.00 ( 27/ 27/ 27) = 107 : 2541 [ 1 2 4 3 6 5 0 ] + + test_bsbm_q5 : Total times: static=7201, runtime=3686, delta(static-runtime)=3515 +*** Selected join path: [1, 2, 4, 3, 6, 5, 0] +vertex sourceCard * f ( out/ in/ read) = estCard : sumEstCard + 1 NA * ( N/A/ N/A/ N/A) = 16E : 16 + 2 16E * 150.00 ( 600/ 4/ 10921) = 2400 : 13337 + 4 2400 * 1.00 ( 600/ 600/ 600) = 2400 : 16337 + 3 2400 * 0.16 ( 97/ 600/ 600) = 387 : 17324 + 6 387 * 1.00 ( 97/ 97/ 97) = 387 : 17808 + 5 387 * 0.28 ( 27/ 97/ 97) = 107 : 18012 + 0 107 * 1.00 ( 27/ 27/ 27) = 107 : 18146 + +200M: static: ids=[1, 2, 4, 6, 0, 3, 5] + +*** round=5, limit=600: paths{in=4,considered=4,out=1} +path sourceCard * f ( out/ in/ read) = estCard : sumEstCard joinPath + 0 1941 * 1.00 ( 7/ 7/ 7) = 1941 : 344799 [ 1 2 4 3 6 5 0 ] + +test_bsbm_q5 : Total times: static=7312, runtime=3305, delta(static-runtime)=4007 + + */ final IPredicate<?>[] runtimeOrder = doTest(preds, constraints); - - /* - * Verify that the runtime optimizer produced the expected join - * path. - * - * FIXME Figure out what the right query is. - */ - assertEquals("runtimeOrder", new int[] { 1, 2, 0, 4, 6, 3, 5 }, - BOpUtility.getPredIds(runtimeOrder)); +// assertEquals("runtimeOrder", new int[] { 1, 2, 0, 4, 6, 3, 5 }, BOpUtility.getPredIds(runtimeOrder)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tho...@us...> - 2011-02-24 12:28:41
|
Revision: 4238 http://bigdata.svn.sourceforge.net/bigdata/?rev=4238&view=rev Author: thompsonbry Date: 2011-02-24 12:28:34 +0000 (Thu, 24 Feb 2011) Log Message: ----------- Improved RTO trace of cutoff joins. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Path.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Path.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Path.java 2011-02-24 09:10:56 UTC (rev 4237) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Path.java 2011-02-24 12:28:34 UTC (rev 4238) @@ -679,8 +679,9 @@ // Reservations for the bopIds used by the constraints. if (c != null) { for (IConstraint x : c) { - if (log.isDebugEnabled()) - log.debug("Attaching constraint: " + x); + if (log.isTraceEnabled()) + log.trace(Arrays.toString(BOpUtility.getPredIds(path)) + + ": constraint: " + x); final Iterator<BOp> itr = BOpUtility .preOrderIteratorWithAnnotations(x); while (itr.hasNext()) { @@ -774,7 +775,8 @@ .getStats().get(joinId); if (log.isTraceEnabled()) - log.trace(joinStats.toString()); + log.trace(Arrays.toString(BOpUtility.getPredIds(path)) + ": " + + joinStats.toString()); // #of solutions in. final int inputCount = (int) joinStats.inputSolutions.get(); @@ -869,7 +871,7 @@ if (log.isDebugEnabled()) log.debug(Arrays.toString(BOpUtility.getPredIds(path)) - + " : newSample=" + edgeSample); + + ": newSample=" + edgeSample); return edgeSample; Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java 2011-02-24 09:10:56 UTC (rev 4237) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java 2011-02-24 12:28:34 UTC (rev 4238) @@ -440,7 +440,7 @@ * to use a larger data set if we want to verify the optimizers join * path for a query which produces solutions in the data. */ - if (true) { + if (false) { final IPredicate<?>[] runtimeOrder = doTest(preds, null/* constraints */); /* * Verify that the runtime optimizer produced the expected join @@ -456,7 +456,7 @@ /* * Run w/ constraints. */ - if(false){ + if(true){ final IPredicate<?>[] runtimeOrder = doTest(preds, constraints); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2011-02-24 09:11:03
|
Revision: 4237 http://bigdata.svn.sourceforge.net/bigdata/?rev=4237&view=rev Author: martyncutcher Date: 2011-02-24 09:10:56 +0000 (Thu, 24 Feb 2011) Log Message: ----------- Related to ticket 243 and 244 after analysis of performance of deep striterations and implementing a generic prefetch pattern that allows efficient processing of hasNext for such structures. Associated is a tail optimisation that enables the collapse of the stack-based invocations analagous to tail recursion optimisation in functional programming. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Appenderator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Contractorator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Expanderator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Filterator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IStriterator.java branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Striterator.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Prefetch.java Modified: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Appenderator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Appenderator.java 2011-02-24 01:04:12 UTC (rev 4236) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Appenderator.java 2011-02-24 09:10:56 UTC (rev 4237) @@ -21,59 +21,70 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ + */ package cutthecrap.utils.striterators; import java.util.*; +import cutthecrap.utils.striterators.IStriterator.ITailOp; + /** * Appenderator **/ -public class Appenderator implements Iterator { +public class Appenderator extends Prefetch implements ITailOp { private final Iterator m_src; - protected final Object m_ctx; + protected final Object m_ctx; private final Iterator m_xtra; - + private Iterator m_current; + private boolean m_isxtra = false; - public Appenderator(Iterator src, Object ctx, Iterator xtra) { - m_src = src; - m_ctx = ctx; - m_xtra = xtra; + public Appenderator(Iterator src, Object ctx, Iterator xtra) { + m_src = src; + m_ctx = ctx; + m_xtra = xtra; - m_current = m_src; - } + m_current = m_src; + } - //------------------------------------------------------------- + // ------------------------------------------------------------- - public boolean hasNext() { - if (m_current.hasNext()) { - return true; - } else if (m_current == m_xtra) { // don't call twice - return false; - } - - m_current = m_xtra; - - return m_current.hasNext(); - } + protected Object getNext() { + Object ret = null; + if (m_current.hasNext()) { + ret = m_current.next(); + } else if (m_isxtra) { // no need to call twice + return null; + } else { + m_current = m_xtra; + m_isxtra = true; + + if (m_current.hasNext()) { + ret = m_current.next(); + } + } + // experimental tail optimisation + if (m_current instanceof ITailOp) { + m_current = ((ITailOp) m_current).availableTailOp(); + } + + return ret; + } - //------------------------------------------------------------- - // must call hasNext() to ensure m_current is correct - public Object next() { - if (hasNext()) { - return m_current.next(); - } + public Iterator availableTailOp() { + if (m_isxtra) { + return m_current; + } else { + return this; + } + } - throw new NoSuchElementException("Appenderator"); - } + // ------------------------------------------------------------- - //------------------------------------------------------------- - - public void remove() { - m_current.remove(); - } + public void remove() { + m_current.remove(); + } } \ No newline at end of file Modified: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Contractorator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Contractorator.java 2011-02-24 01:04:12 UTC (rev 4236) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Contractorator.java 2011-02-24 09:10:56 UTC (rev 4237) @@ -42,12 +42,10 @@ * * @author Martyn Cutcher */ -public class Contractorator implements Iterator { +public class Contractorator extends Prefetch { private final Iterator m_src; protected final Object m_ctx; private final Contractor m_contractor; - private Object m_next; - private boolean m_init = false; public Contractorator(Iterator src, final Object ctx, Contractor contractor) { m_src = src; @@ -55,30 +53,14 @@ m_contractor = contractor; } - private void init() { - if (!m_init) { - m_next = m_contractor.contract(m_src); - m_init = true; + protected Object getNext() { + if (m_src.hasNext()) { + return m_contractor.contract(m_src); + } else { + return null; } } - public boolean hasNext() { - init(); - - return m_next != null; - } - - public Object next() { - if (!hasNext()) { - throw new NoSuchElementException(); - } - - Object ret = m_next; - m_next = m_contractor.contract(m_src); - - return ret; - } - public void remove() { throw new UnsupportedOperationException(); } Modified: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Expanderator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Expanderator.java 2011-02-24 01:04:12 UTC (rev 4236) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Expanderator.java 2011-02-24 09:10:56 UTC (rev 4237) @@ -1,82 +1,55 @@ -/* -Striterator - transformation and mapping patterns over java Iterators +package cutthecrap.utils.striterators; -Copyright (C) SYSTAP, LLC 2010. All rights reserved. +import java.util.Iterator; +import java.util.NoSuchElementException; -Contact: - SYSTAP, LLC - 4501 Tower Road - Greensboro, NC 27410 - lic...@bi... +import cutthecrap.utils.striterators.IStriterator.ITailOp; -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. +public class Expanderator extends Prefetch implements ITailOp { -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. + private final Iterator m_src; + private Iterator m_child = null; + protected final Object m_context; + private final Expander m_expander; -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 -*/ + public Expanderator(Iterator src, Object context, Expander expander) { + m_src = src; + m_context = context; + m_expander = expander; + } -package cutthecrap.utils.striterators; + // ------------------------------------------------------------- -import java.util.*; + protected Object getNext() { + if (m_child != null && m_child.hasNext()) { + final Object ret = m_child.next(); + + // experimental tail optimisation + if (m_child instanceof ITailOp) { + m_child = ((ITailOp) m_child).availableTailOp(); + } -/** - * Expanderator - * - * Flattens out a two-level iteration. By combining Expanderators recursively a general tree - * iteration is provided. - * - * Provides resolution for both the child object and also the nested iterator. - * The actual expansion is via an Expander object that is passed in at construction. - */ + return ret; + } else if (m_src.hasNext()) { + m_child = m_expander.expand(m_src.next()); -public class Expanderator implements Iterator { + return getNext(); + } else { + return null; + } + } - private final Iterator m_src; - private Iterator m_child = null; - protected final Object m_context; - private final Expander m_expander; - - public Expanderator(Iterator src, Object context, Expander expander) { - m_src = src; - m_context = context; - m_expander = expander; - } + // ------------------------------------------------------------- - //------------------------------------------------------------- - - public boolean hasNext() { - if (m_child != null && m_child.hasNext()) { - return true; - } else if (m_src.hasNext()) { - m_child = m_expander.expand(m_src.next()); - - return hasNext(); - } else { - return false; - } - } - - //------------------------------------------------------------- - // must call hasNext() to ensure m_child is setup - public Object next() { - if (hasNext()) { - return m_child.next(); - } - - throw new NoSuchElementException("Expanderator"); - } - - //------------------------------------------------------------- - - public void remove() { - m_child.remove(); - } -} \ No newline at end of file + public void remove() { + m_child.remove(); + } + + public Iterator availableTailOp() { + if ((!ready()) && !m_src.hasNext()) { + return m_child; + } else { + return this; + } + } +} Modified: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Filterator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Filterator.java 2011-02-24 01:04:12 UTC (rev 4236) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Filterator.java 2011-02-24 09:10:56 UTC (rev 4237) @@ -41,20 +41,10 @@ * <p>The Filterator provide the protocol support to utilize Filter objects.</p> */ -public class Filterator implements Iterator { +public class Filterator extends Prefetch { final private Iterator m_src; - /** - * Flag set once {@link #getNext()} is invoked at least once. - */ - private boolean didInit = false; - - /** - * Pre-fetched, but initial prefetch must not be done in the constructor. - */ - private Object m_value = null; - final protected Object m_context; final protected Filter m_filter; @@ -62,38 +52,11 @@ m_src = src; m_context = context; m_filter = filter; - - /* - * Note: eager initialization causes problems when we are stacking - * filters. - */ -// m_value = getNext(); } - //------------------------------------------------------------- - public boolean hasNext() { - if (!didInit) { - m_value = getNext(); - } - return m_value != null; - } - //------------------------------------------------------------- - // must call hasNext() to ensure m_child is setup - public Object next() { - if (hasNext()) { - Object val = m_value; - m_value = getNext(); - return val; - } - - throw new NoSuchElementException("FilterIterator"); - } - - //------------------------------------------------------------- - public void remove() { m_src.remove(); } @@ -101,7 +64,6 @@ //------------------------------------------------------------- protected Object getNext() { - didInit = true; while (m_src.hasNext()) { final Object next = m_src.next(); Modified: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IStriterator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IStriterator.java 2011-02-24 01:04:12 UTC (rev 4236) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/IStriterator.java 2011-02-24 09:10:56 UTC (rev 4237) @@ -59,4 +59,16 @@ * iter.map(this, MyClass.aMethod); **/ public IStriterator map(Object client, Method method); + + public interface ITailOp { + /** + * Opportunity for a Striterator to provide a "tail iterator" to + * shorten the call stack. For example, an Appenderator would return + * the second iterator if current. Or an Expanderator the child iterator + * if there were no more source objects. + * + * @return a tail optimizing iterator if possible + */ + public Iterator availableTailOp(); + } } Added: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Prefetch.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Prefetch.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Prefetch.java 2011-02-24 09:10:56 UTC (rev 4237) @@ -0,0 +1,46 @@ +package cutthecrap.utils.striterators; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +public abstract class Prefetch implements Iterator { + private Object m_next; + private boolean m_ready = false; + + final private void checkInit() { + if (!m_ready) { + m_next = getNext(); + m_ready = true; + } + } + + abstract protected Object getNext(); + + public boolean hasNext() { + checkInit(); + + return m_next != null; + } + + public Object next() { + checkInit(); // check prefetch is ready + + if (m_next == null) { + throw new NoSuchElementException(); + } + + Object ret = m_next; + + // do not prefetch on next() since this may cause problems with + // side-effecting + // overides + m_next = null; + m_ready = false; + + return ret; + } + + protected boolean ready() { + return m_ready; + } +} Property changes on: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Prefetch.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Id Date Revision Author HeadURL Modified: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Striterator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Striterator.java 2011-02-24 01:04:12 UTC (rev 4236) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Striterator.java 2011-02-24 09:10:56 UTC (rev 4237) @@ -32,6 +32,8 @@ import java.util.LinkedList; import java.util.List; +import cutthecrap.utils.striterators.IStriterator.ITailOp; + /** * Striterator * @@ -40,7 +42,7 @@ * The IFilter objects passed to addFilter allow selection criteria for the iterated objects. * The <code>addTypeFilter</code> method allows easy specification of a class type restriction. */ -public class Striterator implements IStriterator { +public class Striterator implements IStriterator, ITailOp { volatile List<IFilter> filters = null; // Note: NOT serializable. private volatile Iterator realSource; private volatile Iterator m_src = null; @@ -82,7 +84,13 @@ public Object next() { if (m_src == null) compile(realSource); - return m_src.next(); + final Object ret = m_src.next(); + // experimental tail optimisation + if (m_src instanceof ITailOp) { + Object old = m_src; + m_src = ((ITailOp) m_src).availableTailOp(); + } + return ret; } /** Enumeration version of hasNext() **/ @@ -120,7 +128,7 @@ return this; } - + public void compile(final Iterator src) { compile(src, null/* context */); } @@ -190,4 +198,27 @@ return sb.toString(); } + /** + * If this Striterator has not been overriden then return the + * source iterator, or even better, try and recurse to the nested tailOp + * if available. + * + * This has been disabled since it appears to have a negative effect. + * + * To reactivate, uncomment the ITailOp implementation declaration. + * + * TODO: Investigate apparent performance degradation with activation + * + * @return + */ + boolean doneone = false; + public Iterator availableTailOp() { + final boolean avail = Striterator.class == this.getClass(); + + if (avail) { + return (m_src instanceof ITailOp) ? ((ITailOp) m_src).availableTailOp() : m_src; + } else { + return this; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tho...@us...> - 2011-02-24 01:04:19
|
Revision: 4236 http://bigdata.svn.sourceforge.net/bigdata/?rev=4236&view=rev Author: thompsonbry Date: 2011-02-24 01:04:12 +0000 (Thu, 24 Feb 2011) Log Message: ----------- More work on the runtime optimizer. - Fixed a problem in JGraph#expand() where it was not resampling vertices when the limit was increased. - Cleaned out dead code. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JoinGraph.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Path.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/SampleBase.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnLubm.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java 2011-02-23 21:52:48 UTC (rev 4235) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java 2011-02-24 01:04:12 UTC (rev 4236) @@ -233,51 +233,10 @@ */ private final SampleType sampleType; -// /** -// * The edges of the join graph as determined by static analysis. Each -// * edge is basically a possible join. This array is comprised of just -// * those edges which are determined by static analysis. Additional edges -// * MAY be identified dynamically. Altogether there are three categories -// * of edges: -// * <ol> -// * <li>The vertices directly share variables (join with shared -// * variable(s)). These edges are identified by static analysis in the -// * constructor are are represented in {@link #E}.</li> -// * <li>The vertices indirectly share variables via a constraint (join -// * with indirectly shared variable(s)). These edges are identified by -// * dynamic analysis. Each time we expand the set of join paths under -// * consideration, we examine {@link #unshared} vertices. Given the join -// * path under consideration and the set of constraints, it may be that -// * the vertex will indirectly share a variable via a constraint and can -// * therefore participate in a constrained join.</li> -// * <li>The vertices do not share variables, either directly or -// * indirectly (unconstrained join). All vertices can join. However, if -// * there are no shared variables then the join is unconstrained (full -// * cross product). These edges are identified dynamically. In each round -// * for which a constrained edge could not be identified, we consider all -// * vertices in {@link #unshared} and choose an unconstrained edge.</li> -// * </ol> -// * -// * @see BOpUtility#canJoinUsingConstraints(IPredicate[], IPredicate, IConstraint[]) -// */ -// private final Edge[] E; - -// /** -// * An unordered collection of vertices which do not share any variables -// * with the other vertices in the join graph. These vertices will -// * produce full cross product joins unless a constraint causes indirect -// * sharing of variables with a join path. -// */ -// private final Vertex[] unshared; - public List<Vertex> getVertices() { return Collections.unmodifiableList(Arrays.asList(V)); } -// public List<Edge> getEdges() { -// return Collections.unmodifiableList(Arrays.asList(E)); -// } - public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("JoinGraph"); @@ -289,14 +248,6 @@ for (IConstraint c : C) { sb.append("\nC[" + c.getId() + "]=" + c); } -// sb.append("\n],unshared=["); -// for (Vertex v : unshared) { -// sb.append("\n" + v); -// } -// sb.append("],E=["); -// for (Edge e : E) { -// sb.append("\n" + e); -// } sb.append("\n]}"); return sb.toString(); } @@ -364,161 +315,6 @@ this.sampleType = sampleType; -// /* -// * Create edges to represent possible joins between predicates based on -// * directly shared variables - these joins can be identified by a static -// * analysis of the join graph. -// */ -// { -// -// // The set of identified edges for vertices which share vars. -// final List<Edge> tmp = new LinkedList<Edge>(); -// -// // The set of vertices which share variables. -// final Set<Vertex> sharedEdgeVertices = new LinkedHashSet<Vertex>(); -// -//// // The set of vertices which do not share variables. -//// final List<Vertex> unsharedEdgeVertices = new LinkedList<Vertex>(); -// -// for (int i = 0; i < v.length; i++) { -// -// // consider a source vertex. -// final IPredicate<?> p1 = v[i]; -// -// // #of vertices which share a variable with source vertex. -// int nmatched = 0; -// -// for (int j = i + 1; j < v.length; j++) { -// -// // consider a possible target vertex. -// final IPredicate<?> p2 = v[j]; -// -//// final Set<IVariable<?>> shared = BOpUtility -//// .getSharedVars(p1, p2); -// -// if(BOpUtility.canJoin(p1, p2)) { -//// if (!shared.isEmpty()) { -// -// /* -// * The source and target vertices can join based on -// * one or more shared variable(s). -// */ -// -// if (log.isDebugEnabled()) -// log.debug("vertices shared variable(s): vars=" -// + BOpUtility.getSharedVars(p1, p2) -// + ", v1=" + p1 + ", v2=" + p2); -// -// tmp.add(new Edge(V[i], V[j]));//, shared)); -// -// sharedEdgeVertices.add(V[i]); -// -// sharedEdgeVertices.add(V[j]); -// -// nmatched++; -// -// } else if (constraints != null) { -// -// /* -// * The source and target vertices do not directly -// * share any variable(s). However, there may be a -// * constraint which shares a variable with both the -// * source and target vertex. If such a constraint is -// * found, then we add an edge now as that join is -// * potentially constrained (less than the full -// * Cartesian cross product). -// * -// * Note: While this identifies possible joins via a -// * constraint, such joins are only legal when all -// * variables used by the constraint are known to be -// * bound. -// * -// * FIXME Edges should be identified dynamically, not -// * statically. Probably all edges (aka possible -// * joins) should be identified dynamically given the -// * history represented by a given join path and the -// * set of constraints declared for the join graph. -// */ -// -// for(IConstraint c : constraints) { -// -// if(BOpUtility.getSharedVars(p1, c).isEmpty()) -// continue; -// -// if(BOpUtility.getSharedVars(p2, c).isEmpty()) -// continue; -// -// if (log.isDebugEnabled()) -// log -// .debug("vertices shared variable(s) via constraint: v1=" -// + p1 -// + ", v2=" -// + p2 -// + ", c=" + c); -// -// tmp.add(new Edge(V[i], V[j]));//, shared)); -// -// sharedEdgeVertices.add(V[i]); -// -// sharedEdgeVertices.add(V[j]); -// -// nmatched++; -// -// } -// -// } -// -// } -// -// if (nmatched == 0 && !sharedEdgeVertices.contains(V[i])) { -// -// /* -// * The source vertex does not share any variables. -// */ -// -// log.warn("Vertex does not share any variables: " + V[i]); -// -//// unsharedEdgeVertices.add(V[i]); -// -// } -// -// } // next vertex -// -// E = tmp.toArray(new Edge[0]); -// -//// this.unshared = unsharedEdgeVertices.toArray(new Vertex[0]); -// -//// if(!unsharedEdgeVertices.isEmpty()) { -//// -//// /* -//// * FIXME NO SHARED VARS : RUN LAST. This needs to be -//// * supported. When vertices that do not share variables -//// * either directly or via a constraint then they should run -//// * last as they can not constrain the query. In this case, -//// * they are not considered by the runtime optimizer when -//// * building up the join path until all vertices which share -//// * variables have been exhausted. At that point, the -//// * remaining vertices are just appended to whatever join -//// * path was selected as having the lowest cumulative -//// * estimated cardinality. -//// * -//// * However, if there exists for a vertex which otherwise -//// * does not share variables a constraint which should be -//// * evaluated against that vertex, then that constraint -//// * provides the basis for a edge (aka join). In this case, -//// * an edge must be created for the vertex based on the -//// * shared variable in the constraint and its position in the -//// * join path will be decided by the runtime optimizer. -//// */ -//// -//// throw new UnsupportedOperationException( -//// "Some predicates do not share any variables with other predicates: unshared=" -//// + unsharedEdgeVertices); -//// -//// } -// -// } // create edges. - } /** @@ -793,14 +589,6 @@ log.info("\n*** Paths @ t0\n" + JGraph.showTable(paths_t0)); /* - * Discard samples which will not be reused. - * - * @todo Do this in each round since with more than one starting vertex - * we have have starting vertices which will not be re-sampled at any - * round (assuming that all paths beginning with a given starting vertex - * get pruned). See runtimeOptimizer() for some more notes on this. - */ - /* * Discard samples for vertices which were not chosen as starting points * for join paths. * @@ -919,13 +707,6 @@ x.vertices[0].sample(queryEngine, limit, sampleType); -// for(Edge e : x.edges) { -// -// e.v1.sample(queryEngine, limit); -// e.v2.sample(queryEngine, limit); -// -// } - } /* @@ -946,162 +727,113 @@ for (Path x : a) { -// // The edges which we have visited in this path. -// final List<Edge> edges = new LinkedList<Edge>(); - - // The vertices which we have visited in this path. -// final Set<Vertex> vertices = new LinkedHashSet<Vertex>(); - // The cutoff join sample of the one step shorter path segment. EdgeSample priorEdgeSample = null; for (int segmentLength = 2; segmentLength <= x.vertices.length; segmentLength++) { -// for(Edge ex : x.edges) { - -// // Add edge to the visited set for this join path. -// edges.add(e); // Generate unique key for this join path segment. -// final int[] ids = Path.getVertexIds(edges); final PathIds ids = new PathIds(BOpUtility.getPredIds(x .getPathSegment(segmentLength))); + // Look for sample for this path in our cache. + EdgeSample edgeSample = edgeSamples.get(ids); + + if (edgeSample != null && edgeSample.limit < limit + && !edgeSample.isExact()) { + if (log.isDebugEnabled()) + log.debug("Will resample at higher limit: " + ids); + // Time to resample this edge. + edgeSamples.remove(ids); + edgeSample = null; + } + if (priorEdgeSample == null) { /* * This is the first edge in the path. * - * Test our local table of join path segment estimates - * to see if we have already re-sampled that edge. If - * not, then re-sample it now. + * Test our local table of join path segment estimates to + * see if we have already re-sampled that edge. If not, then + * re-sample it now. */ - + assert segmentLength == 2; - // Test sample cache. - EdgeSample edgeSample = edgeSamples.get(ids); - if (edgeSample == null) { - -// if (e.sample != null && e.sample.limit >= limit) { -// -// // The existing sample for that edge is fine. -// edgeSample = e.sample; -// -// } else { - /* - * Re-sample the 1st edge in the join path, updating - * the sample on the edge as a side-effect. The - * cutoff sample is based on the vertex sample for - * the minimum cardinality vertex. - */ + /* + * Re-sample the 1st edge in the join path, updating the + * sample on the edge as a side-effect. The cutoff + * sample is based on the vertex sample for the minimum + * cardinality vertex. + */ - edgeSample = Path.cutoffJoin(// - queryEngine, - limit,// - x.getPathSegment(2),// 1st edge. - C,// constraints - x.vertices[0].sample// source sample. - ); + edgeSample = Path.cutoffJoin(// + queryEngine, limit,// + x.getPathSegment(2),// 1st edge. + C,// constraints + x.vertices[0].sample// source sample. + ); -// } - // Cache the sample. if (edgeSamples.put(ids, edgeSample) != null) throw new AssertionError(); } -// // Add both vertices to the visited set. -// vertices.add(x.vertices[0]); -// vertices.add(x.vertices[1]); -// vertices.add(e.v1); -// vertices.add(e.v2); - // Save sample. It will be used to re-sample the next edge. priorEdgeSample = edgeSample; - + } else { /* * The path segment is at least 3 vertices long. */ assert ids.length() >= 3; - -// final boolean v1Found = vertices.contains(e.v1); -// // The source vertex for the new edge. -// final Vertex sVertex = v1Found ? e.v1 : e.v2; + if (edgeSample == null) { -//// // The target vertex for the new edge. -// final Vertex tVertex = x.vertices[segmentLength - 1]; -// final Vertex tVertex = v1Found ? e.v2 : e.v1; + /* + * This is some N-step edge in the path, where N is + * greater than ONE (1). The source vertex is the vertex + * which already appears in the prior edges of this join + * path. The target vertex is the next vertex which is + * visited by the join path. The sample passed in is the + * prior edge sample -- that is, the sample from the + * path segment without the target vertex. This is the + * sample that we just updated when we visited the prior + * edge of the path. + */ - // Look for sample for this path in our cache. - EdgeSample edgeSample = edgeSamples.get(ids); + edgeSample = Path.cutoffJoin(queryEngine,// + limit,// + x.getPathSegment(ids.length()),// + C, // constraints + priorEdgeSample// + ); - if (edgeSample != null && edgeSample.limit < limit - && !edgeSample.isExact()) { if (log.isDebugEnabled()) - log.debug("Will resample at higher limit: " + ids); - // Time to resample this edge. - edgeSamples.remove(ids); - edgeSample = null; - } - - if (edgeSample == null) { + log.debug("Resampled: " + ids + " : " + edgeSample); - /* - * This is some N-step edge in the path, where N is greater - * than ONE (1). The source vertex is the vertex which - * already appears in the prior edges of this join path. The - * target vertex is the next vertex which is visited by the - * join path. The sample passed in is the prior edge sample - * -- that is, the sample from the path segment without the - * target vertex. This is the sample that we just updated - * when we visited the prior edge of the path. - */ + if (edgeSamples.put(ids, edgeSample) != null) + throw new AssertionError(); - edgeSample = Path.cutoffJoin( - queryEngine,// - limit,// -// sVertex,// -// tVertex,// - x.getPathSegment(ids.length()),// - C, // constraints - priorEdgeSample// -// priorEdgeSample.estimatedCardinality,// -// priorEdgeSample.estimateEnum == EstimateEnum.Exact, -// priorEdgeSample.limit,// -// priorEdgeSample.sample// - ); + } - if (log.isDebugEnabled()) - log.debug("Resampled: " + ids - + " : " + edgeSample); - - if (edgeSamples.put(ids, edgeSample) != null) - throw new AssertionError(); + // Save sample. It will be used to re-sample the next edge. + priorEdgeSample = edgeSample; } - // Save sample. It will be used to re-sample the next edge. - priorEdgeSample = edgeSample; - -// // Add target vertex to the visited set. -// vertices.add(tVertex); - - } - } // next path prefix in Path [x] if (priorEdgeSample == null) throw new AssertionError(); - + // Save the result on the path. x.edgeSample = priorEdgeSample; - + } // next Path [x]. /* @@ -1114,7 +846,7 @@ + a.length); final List<Path> tmp = new LinkedList<Path>(); - + for (Path x : a) { /* @@ -1122,68 +854,6 @@ */ final Set<Vertex> used = new LinkedHashSet<Vertex>(); -// /* -// * First, consider the edges identified by static analysis. This -// * will create zero or more paths from the current join path. -// * -// * FIXME Change this to use canJoin() and get rid of E[] and of -// * Edges in general. -// */ -// // Check all edges in the graph. -// for (Edge edgeInGraph : E) { -// -// // Figure out which vertices are already part of this path. -// final boolean v1Found = x.contains(edgeInGraph.v1); -// final boolean v2Found = x.contains(edgeInGraph.v2); -// -// if (log.isTraceEnabled()) -// log.trace("Edge: " + edgeInGraph + ", v1Found=" -// + v1Found + ", v2Found=" + v2Found); -// -// if (!v1Found && !v2Found) { -// // Edge is not connected to this path. -// continue; -// } -// -// if (v1Found && v2Found) { -// // Edge is already present in this path. -// continue; -// } -// -// // the target vertex for the new edge. -// final Vertex tVertex = v1Found ? edgeInGraph.v2 -// : edgeInGraph.v1; -// -//// // the source vertex for the new edge. -//// final Vertex sVertex = v1Found ? edgeInGraph.v1 -//// : edgeInGraph.v2; -// -// if (used.contains(tVertex)) { -// // Vertex already used to extend this path. -// if (log.isTraceEnabled()) -// log.trace("Edge: " + edgeInGraph -// + " - already used to extend this path."); -// continue; -// } -// -// // add the new vertex to the set of used vertices. -// used.add(tVertex); -// -// // (Re-)sample vertex before we sample a new edge -// tVertex.sample(queryEngine, limit, sampleType); -// -// // Extend the path to the new vertex. -// final Path p = x.addEdge(queryEngine, limit, tVertex, /*edgeInGraph,*/ C); -// -// // Add to the set of paths for this round. -// tmp.add(p); -// -// if (log.isTraceEnabled()) -// log.trace("Extended path with static edge: " -// + edgeInGraph + ", new path=" + p); -// -// } - { /* @@ -1244,97 +914,6 @@ // add the new vertex to the set of used vertices. used.add(tVertex); -// // (Re-)sample vertex before we sample a new edge -// tVertex.sample(queryEngine, limit, sampleType); - -// // Analyze join path and constraints for new path. -// final PartitionedJoinGroup g; -// { -// // extract ordered preds from path to be extended -// final List<IPredicate<?>> preds = new LinkedList<IPredicate<?>>( -// Arrays.asList(x.getPredicates())); -// // append the target vertex. -// preds.add(tVertex.pred); -// // convert to an array. -// final IPredicate<?>[] newPath = preds -// .toArray(new IPredicate[preds.size()]); -// g = new PartitionedJoinGroup(newPath, C); -// } -// -// // The set of constraints which will run for this vertex. -// final IConstraint[] c = g -// .getJoinGraphConstraints(tVertex.pred.getId()); -// -// if (c == null || c.length == 0) { -// /* -// * Must not be null since the constraint(s) are what -// * license this as a constrained join. -// */ -// throw new AssertionError(); -// } - -// /* -// * Find any vertex in the path which we are extending -// * which shares at least one variable with one of the -// * constraints which will run with this edge. That will -// * be the "source" vertex for the purposes of this path -// * extension. -// */ -// Vertex vSource = null; -// { -// -// // The set of variables used by the constraints. -// final Set<IVariable<?>> vars = new LinkedHashSet<IVariable<?>>(); -// -// for (IConstraint aConstraint : c) { -// -// final Iterator<IVariable<?>> vitr = BOpUtility -// .getSpannedVariables(aConstraint); -// -// while (vitr.hasNext()) { -// -// vars.add(vitr.next()); -// -// } -// -// } -// -// // Find a vertex using any of those variables. -// for (Vertex aVertex : x.vertices) { -// -// if (vSource != null) { -// // Done. -// break; -// } -// -// final IPredicate<?> aPred = aVertex.pred; -// -// final Iterator<IVariable<?>> vitr = BOpUtility -// .getArgumentVariables(aPred); -// -// while (vSource == null && vitr.hasNext()) { -// -// final IVariable<?> aVar = vitr.next(); -// -// if (vars.contains(aVar)) { -// -// // Done. -// vSource = aVertex; -// -// } -// -// } // while -// -// } // for -// -// if (vSource == null) -// throw new AssertionError("No shared variables?"); -// -// } // end block - -// final Edge dynamicEdge = new Edge(/* x, */vSource, -// tVertex); - // Extend the path to the new vertex. final Path p = x.addEdge(queryEngine, limit, tVertex, /*dynamicEdge,*/ C); @@ -1356,12 +935,9 @@ if (tmp.isEmpty()) { /* - * NO edges were identified by static and dynamic analysis - * so we must consider edges which represent fully - * unconstrained joins. + * No constrained joins were identified so we must consider + * edges which represent fully unconstrained joins. */ - -// assert unshared.length != 0; assert !nothingShared.isEmpty(); @@ -1375,14 +951,6 @@ */ final Vertex tVertex = nothingShared.iterator().next(); -// /* -// * Since there are no shared variables, any vertex already -// * in the path may be used as the source for this edge. -// */ -// final Vertex vSource = x.vertices[0]; - -// final Edge dynamicEdge = new Edge(vSource, tVertex); - // Extend the path to the new vertex. final Path p = x.addEdge(queryEngine, limit, tVertex,/*dynamicEdge*/ C); @@ -1436,28 +1004,6 @@ return null; } -// /** -// * Return the {@link Edge} associated with the given vertices. The -// * vertices may appear in any order. -// * -// * @param v1 -// * One vertex. -// * @param v2 -// * Another vertex. -// * -// * @return The edge -or- <code>null</code> if there is no such edge in -// * the join graph. -// */ -// public Edge getEdge(Vertex v1, Vertex v2) { -// for (Edge e : E) { -// if (e.v1 == v1 && e.v2 == v2) -// return e; -// if (e.v1 == v2 && e.v2 == v1) -// return e; -// } -// return null; -// } - /** * Obtain a sample and estimated cardinality (fast range count) for each * vertex. @@ -1600,195 +1146,10 @@ } -// for (Edge e : E) { -// -// if (e.v1.sample == null || e.v2.sample == null) { -// -// /* -// * We can only estimate the cardinality of edges connecting -// * vertices for which samples were obtained. -// */ -// -// continue; -// -// } -// -// /* -// * Figure out which vertex has the smaller cardinality. The sample -// * of that vertex is used since it is more representative than the -// * sample of the other vertex. -// */ -// // vertex v, vprime -// final Vertex v, vp; -//// if (e.v1.sample == null) // vertex not sampled. -//// throw new IllegalStateException(); -//// if (e.v2.sample == null) // vertex not sampled. -//// throw new IllegalStateException(); -// if (e.v1.sample.estimatedCardinality < e.v2.sample.estimatedCardinality) { -// v = e.v1; -// vp = e.v2; -// } else { -// v = e.v2; -// vp = e.v1; -// } -// -// // The path segment -// final IPredicate<?>[] preds = new IPredicate[] { v.pred, vp.pred }; -// -// /* -// * TODO If we get rid of the static analysis to identify edges with -// * shared variables then make sure that however we sample the -// * initial edges we protect against sampling the same edge more than -// * once. -// */ -// -// // cutoff join of the edge (v,vp) -// final EdgeSample edgeSample = e.sample = Edge.estimateCardinality( -// queryEngine,// -// limit, // sample limit -// preds, // ordered path segment. -// C, // constraints -// v.sample // sourceSample -// ); -// -// final Path p = new Path(v, vp, edgeSample); -// -// paths.add(p); -// -// } - return paths.toArray(new Path[paths.size()]); } -// /** -// * Return the {@link Edge} having the minimum estimated cardinality out of -// * those edges whose cardinality has been estimated. -// * -// * @param visited -// * A set of vertices to be excluded from consideration -// * (optional). -// * -// * @return The minimum cardinality edge -or- <code>null</code> if there are -// * no {@link Edge}s having an estimated cardinality. -// */ -// public Edge getMinimumCardinalityEdge(final Set<Vertex> visited) { -// -// long minCard = Long.MIN_VALUE; -// Edge minEdge = null; -// -// for (Edge e : E) { -// -// if (e.sample == null) { -// -// // Edge has not been sampled. -// continue; -// -// } -// -// if (visited != null -// && (visited.contains(e.v1) || visited.contains(e.v2))) { -// -// // A vertex of that edge has already been consumed. -// continue; -// -// } -// -// final long estimatedCardinality = e.sample.estimatedCardinality; -// -// if (minEdge == null || estimatedCardinality < minCard) { -// -// minEdge = e; -// -// minCard = estimatedCardinality; -// -// } -// -// } -// -// return minEdge; -// -// } - - // /** - // * Return the {@link Edge} having the minimum estimated cardinality - // out - // * of those edges whose cardinality has been estimated. - // * - // * @return The minimum cardinality edge -or- <code>null</code> if - // there - // * are no {@link Edge}s having an estimated cardinality. - // */ - // public Edge getMinimumCardinalityEdge() { - // - // return getMinimumCardinalityEdge(null); - // - // } - -// /** -// * Return the #of edges in which the given vertex appears where the -// * other vertex of the edge does not appear in the set of visited -// * vertices. -// * -// * @param v -// * The vertex. -// * @param visited -// * A set of vertices to be excluded from consideration. -// * -// * @return The #of such edges. -// */ -// public int getEdgeCount(final Vertex v, final Set<Vertex> visited) { -// -// return getEdges(v, visited).size(); -// -// } -// -// /** -// * Return the edges in which the given vertex appears where the other -// * vertex of the edge does not appear in the set of visited vertices. -// * -// * @param v -// * The vertex. -// * @param visited -// * A set of vertices to be excluded from consideration -// * (optional). -// * -// * @return Those edges. -// */ -// public List<Edge> getEdges(final Vertex v, final Set<Vertex> visited) { -// -// if (v == null) -// throw new IllegalArgumentException(); -// -// if (visited != null && visited.contains(v)) -// return Collections.emptyList(); -// -// final List<Edge> tmp = new LinkedList<Edge>(); -// -// for (Edge e : E) { -// -// if (v.equals(e.v1) || v.equals(e.v2)) { -// -// if (visited != null) { -// -// if (visited.contains(e.v1)) -// continue; -// -// if (visited.contains(e.v2)) -// continue; -// -// } -// -// tmp.add(e); -// -// } -// -// } -// -// return tmp; -// -// } - /** * Prune paths which are dominated by other paths. Paths are extended in * each round. Paths from previous rounds are always pruned. Of the new @@ -1817,9 +1178,6 @@ if (p.vertices.length > maxPathLen) { maxPathLen = p.vertices.length; } -// if (p.edges.size() > maxPathLen) { -// maxPathLen = p.edges.size(); -// } } final StringBuilder sb = new StringBuilder(); final Formatter f = new Formatter(sb); @@ -1828,7 +1186,6 @@ final Path Pi = a[i]; if (Pi.edgeSample == null) throw new RuntimeException("Not sampled: " + Pi); -// if (Pi.edges.size() < maxPathLen) { if (Pi.vertices.length < maxPathLen) { /* * Only the most recently generated set of paths survive to @@ -1890,27 +1247,6 @@ return b; } -///** -//* Places vertices into order by the {@link BOp#getId()} associated with -//* their {@link IPredicate}. -//*/ -//private static class BOpIdComparator implements Comparator<Vertex> { -// -// private static final transient Comparator<Vertex> INSTANCE = new BOpIdComparator(); -// -//// @Override -// public int compare(final Vertex o1, final Vertex o2) { -// final int id1 = o1.pred.getId(); -// final int id2 = o2.pred.getId(); -// if (id1 < id2) -// return -1; -// if (id2 > id1) -// return 1; -// return 0; -// } -// -//} - /** * Comma delimited table showing the estimated join hit ratio, the estimated * cardinality, and the set of vertices for each of the specified join @@ -2090,9 +1426,7 @@ // e.cumulativeEstimatedCardinality// ); } -// sb.append("\nv[" + vertexIds[i] + "] " + e.toString()); } - /**/ } sb.append("\n"); return sb.toString(); Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JoinGraph.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JoinGraph.java 2011-02-23 21:52:48 UTC (rev 4235) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JoinGraph.java 2011-02-24 01:04:12 UTC (rev 4236) @@ -295,11 +295,10 @@ * query is long running. Samples must be held until we have * identified the final join path since each vertex will be used by * each maximum length join path and we use the samples from the - * vertices to re-sample the surviving join paths in each round. + * vertices to re-sample the surviving join paths in each round. [In + * fact, the samples are not being provided to this evaluation context + * right now.] * - * @todo If there is a slice on the outer query, then the query result may - * well be materialized by now. - * * @todo If there are source binding sets then they need to be applied above * (when we are sampling) and below (when we evaluate the selected * join path). @@ -336,12 +335,12 @@ parentContext.getSink(), null/* sink2 */, null/* constraints */, null/* stats */); - System.out.println("nout=" + nout); +// System.out.println("nout=" + nout); // verify no problems. runningQuery.get(); - System.out.println("Future Ok"); +// System.out.println("Future Ok"); } catch (Throwable t) { Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Path.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Path.java 2011-02-23 21:52:48 UTC (rev 4235) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Path.java 2011-02-24 01:04:12 UTC (rev 4236) @@ -81,20 +81,8 @@ private static final transient Logger log = Logger.getLogger(Path.class); -// /** -// * An immutable ordered list of the edges in the (aka the sequence of -// * joins represented by this path). -// * -// * @deprecated by with {@link #vertices}. -// */ -// final List<Edge> edges; - /** * An ordered list of the vertices in the {@link Path}. - * - * TODO Replace {@link #edges} with {@link #vertices} and declare a - * second array with the {@link VertexSample} for the initial vertex - * followed by the {@link EdgeSample} for each cutoff join in the path. */ final Vertex[] vertices; @@ -150,8 +138,8 @@ final EdgeSample edgeSample) { final long total = cumulativeEstimatedCardinality + // - edgeSample.estimatedCardinality + // - edgeSample.tuplesRead// this is part of the cost too. + edgeSample.estimatedCardinality // +// + edgeSample.tuplesRead // ; return total; @@ -431,44 +419,6 @@ } -// /** -// * Return the vertices in this path (in path order). For the first edge, -// * the minimum cardinality vertex is always reported first (this is -// * critical for producing the correct join plan). For the remaining -// * edges in the path, the unvisited is reported. -// * -// * @return The vertices (in path order). -// */ -// static private Vertex[] getVertices(final List<Edge> edges) { -// -// final Set<Vertex> tmp = new LinkedHashSet<Vertex>(); -// -// for (Edge e : edges) { -// -// if (tmp.isEmpty()) { -// /* -// * The first edge is handled specially in order to report -// * the minimum cardinality vertex first. -// */ -// tmp.add(e.getMinimumCardinalityVertex()); -// tmp.add(e.getMaximumCardinalityVertex()); -// -// } else { -// -// tmp.add(e.v1); -// -// tmp.add(e.v2); -// -// } -// -// } -// -// final Vertex[] a = tmp.toArray(new Vertex[tmp.size()]); -// -// return a; -// -// } - /** * Return the predicates associated with the vertices. * @@ -492,36 +442,6 @@ } -// /** -// * Return the {@link BOp} identifiers of the predicates associated with -// * each vertex in path order. -// */ -// static int[] getVertexIds(final List<Edge> edges) { -// -// final Set<Vertex> tmp = new LinkedHashSet<Vertex>(); -// -// for (Edge e : edges) { -// -// tmp.add(e.v1); -// -// tmp.add(e.v2); -// -// } -// -// final Vertex[] a = tmp.toArray(new Vertex[tmp.size()]); -// -// final int[] b = new int[a.length]; -// -// for (int i = 0; i < a.length; i++) { -// -// b[i] = a[i].pred.getId(); -// -// } -// -// return b; -// -// } - /** * Return <code>true</code> if this path begins with the given path. * @@ -543,14 +463,17 @@ } for (int i = 0; i < p.vertices.length; i++) { + final Vertex vSelf = vertices[i]; + final Vertex vOther = p.vertices[i]; -// final Edge eSelf = edges.get(i); -// final Edge eOther = p.edges.get(i); -// if (eSelf != eOther) { + if (vSelf != vOther) { + return false; + } + } return true; @@ -604,20 +527,6 @@ if (vnew == null) throw new IllegalArgumentException(); -// // Figure out which vertices are already part of this path. -// final boolean v1Found = contains(e.v1); -// final boolean v2Found = contains(e.v2); -// -// if (!v1Found && !v2Found) -// throw new IllegalArgumentException( -// "Edge does not extend path: edge=" + e + ", path=" -// + this); -// -// if (v1Found && v2Found) -// throw new IllegalArgumentException( -// "Edge already present in path: edge=" + e + ", path=" -// + this); - if(contains(vnew)) throw new IllegalArgumentException( "Vertex already present in path: vnew=" + vnew + ", path=" @@ -626,12 +535,9 @@ if (this.edgeSample == null) throw new IllegalStateException(); -// // The vertex which is already part of this path. -// final Vertex sourceVertex = v1Found ? e.v1 : e.v2; + // The new vertex. + final Vertex targetVertex = vnew; - // The new vertex, which is not part of this path. - final Vertex targetVertex = vnew;//v1Found ? e.v2 : e.v1; - /* * Chain sample the edge. * @@ -679,32 +585,15 @@ final EdgeSample edgeSample2 = cutoffJoin(// queryEngine,// limit, // -// sourceVertex, // -// targetVertex,// preds2,// constraints,// this.edgeSample // the source sample. -// this.sample.estimatedCardinality, -// this.sample.estimateEnum == EstimateEnum.Exact, -// this.sample.limit,// -// this.sample.sample// the sample fed into the cutoff join. ); { -// final List<Edge> edges = new ArrayList<Edge>( -// this.edges.size() + 1); -// -// edges.addAll(this.edges); -// -// edges.add(e); - final long cumulativeEstimatedCardinality = add( this.cumulativeEstimatedCardinality, edgeSample2); -// this.cumulativeEstimatedCardinality -// + edgeSample2.estimatedCardinality// -// + edgeSample2.tuplesRead// this is part of the cost too. -// ; // Extend the path. final Path tmp = new Path(vertices2, preds2, @@ -746,22 +635,12 @@ * * @throws Exception */ -// * @param vSource -// * The source vertex. -// * @param vTarget -// * The target vertex static public EdgeSample cutoffJoin(// final QueryEngine queryEngine,// final int limit,// final IPredicate<?>[] path,// final IConstraint[] constraints,// -// final Vertex vSource,// -// final Vertex vTarget,// final SampleBase sourceSample// -// final long sourceEstimatedCardinality,// -// final boolean sourceSampleExact,// -// final int sourceSampleLimit,// -// final IBindingSet[] sourceSample// ) throws Exception { if (path == null) @@ -826,12 +705,10 @@ * limit is satisfied, thus avoiding unnecessary effort. */ - // final int joinId = 1; final int joinId = idFactory.nextId(); - final Map<String, Object> anns = NV.asMap( - // + final Map<String, Object> anns = NV.asMap(// new NV(BOp.Annotations.BOP_ID, joinId),// - new NV(PipelineJoin.Annotations.PREDICATE, pred), + new NV(PipelineJoin.Annotations.PREDICATE, pred),// // Note: does not matter since not executed by the query // controller. // // disallow parallel evaluation of tasks @@ -979,9 +856,6 @@ final long estimatedCardinality = (long) (sourceSample.estimatedCardinality * f); final EdgeSample edgeSample = new EdgeSample(// -// sourceSample.estimatedCardinality, // -// sourceSample.estimateEnum, // -// sourceSample.limit, // sourceSample,// inputCount,// outputCount, // Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/SampleBase.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/SampleBase.java 2011-02-23 21:52:48 UTC (rev 4235) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/SampleBase.java 2011-02-24 01:04:12 UTC (rev 4236) @@ -59,7 +59,9 @@ * the sample as an inline access path. * * TODO This field should be used to avoid needless re-computation of a join - * whose exact solution is already known. + * whose exact solution is already known. We already do this within the + * runtime optimizer. To go further than that we need to do the partial + * evaluation of the join graph. */ public final EstimateEnum estimateEnum; Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnLubm.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnLubm.java 2011-02-23 21:52:48 UTC (rev 4235) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnLubm.java 2011-02-24 01:04:12 UTC (rev 4236) @@ -162,6 +162,8 @@ final File testDir = new File(tmpDir, "bigdata-tests"); testDir.mkdirs(); file = new File(testDir, resourceId + ".jnl"); + // uncomment to force a reload of the dataset. +// if(file.exists()) file.delete(); namespace = "LUBM_U1"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tho...@us...> - 2011-02-23 21:52:57
|
Revision: 4235 http://bigdata.svn.sourceforge.net/bigdata/?rev=4235&view=rev Author: thompsonbry Date: 2011-02-23 21:52:48 +0000 (Wed, 23 Feb 2011) Log Message: ----------- More work on the runtime query optimizer. As of this commit, it is finally paying attention to constraints on the join graph. The RTO continues to produce similar solutions other than for BSBM Q5. For BSBM Q5 it now considers the constraints on the join graph. However, I have not yet investigated the impact of the constraints on the selected join plan nor considered the efficiency of the new solution which is being produced for BSBM Q5 at the 100M or 200M data scales. - Dropped the Edge class which was making it impossible to apply constraints dynamically to cutoff joins. - Added support for constraints when computing cutoff joins. BSBM Q5 is the only query which we are running on the RTO which uses constraints so the solutions for the rest of the queries should not be changed as a result of this refactor. - Done: I am seeing too much edge resampling. The problem was that the LinkedHashMap with int[] keys was not recognizing when the keys were the same data. I introduced a PathIds class for the map key which fixes this. - Note: Estimates can randomly differ whenever there are two paths which span the same vertices and have exactly the same cost. For example, when the cost for all paths spanning some set of vertices is zero. In general, any path covering the same vertices for the same cost is as good as any other. In the special case when the cost is ZERO, this is either an underflow in the estimated cardinality or a true zero. [For LUBM Q2 on U1 it is a true zero.] - Added the EdgeSample for each new path to the edgeSamples map. Also added logic to clear samples from the edgeSamples map if we need to resample them at a higher limit. - Added Path#add/2 to centralize the logic for computing the cumulative cost of a join path. I am looking into ways of combining in the tuples read from the access path with the solutions produced as a better estimate of the access path cost and hence the total join path cost. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EdgeSample.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Path.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Vertex.java branches/QUADS_QUERY_BRANCH/bigdata/src/resources/logging/log4j.properties branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBarData.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnLubm.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimatedCardinalityComparator.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/PathIds.java Removed Paths: ------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Edge.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimatedEdgeCardinalityComparator.java Deleted: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Edge.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Edge.java 2011-02-23 14:44:18 UTC (rev 4234) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Edge.java 2011-02-23 21:52:48 UTC (rev 4235) @@ -1,556 +0,0 @@ -/** - -Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. - -Contact: - SYSTAP, LLC - 4501 Tower Road - Greensboro, NC 27410 - lic...@bi... - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ -/* - * Created on Feb 22, 2011 - */ -package com.bigdata.bop.joinGraph.rto; - -import java.io.Serializable; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.log4j.Logger; - -import com.bigdata.bop.BOp; -import com.bigdata.bop.BOpEvaluationContext; -import com.bigdata.bop.IBindingSet; -import com.bigdata.bop.IConstraint; -import com.bigdata.bop.IPredicate; -import com.bigdata.bop.NV; -import com.bigdata.bop.PipelineOp; -import com.bigdata.bop.engine.IRunningQuery; -import com.bigdata.bop.engine.LocalChunkMessage; -import com.bigdata.bop.engine.QueryEngine; -import com.bigdata.bop.join.PipelineJoin; -import com.bigdata.bop.join.PipelineJoin.PipelineJoinStats; -import com.bigdata.relation.accesspath.ThickAsynchronousIterator; -import com.bigdata.striterator.Dechunkerator; - -/** - * An edge of the join graph is an annotated join operator. The edges of the - * join graph are undirected. Edges exist when the vertices share at least one - * variable. - * <p> - * {@link #hashCode()} is defined in terms of the unordered hash codes of the - * individual vertices. - */ -public class Edge implements Serializable { - - private static final transient Logger log = Logger.getLogger(Edge.class); - - private static final long serialVersionUID = 1L; - - /** - * The vertices connected by that edge. - */ - public final Vertex v1, v2; - - // /** - // * The set of shared variables. - // */ - // public final Set<IVariable<?>> shared; - - /** - * The last sample for this edge and <code>null</code> if the edge has not - * been sampled. - * <p> - * Note: This sample is only the one-step cutoff evaluation of the edge - * given a sample of its vertex having the lesser cardinality. It is NOT the - * cutoff sample of a join path having this edge except for the degenerate - * case where the edge is the first edge in the join path. - */ - transient EdgeSample sample = null; - - /** - * - * @param path - * The path which the edge is extending. - * @param v1 - * A vertex in that path which serves as the source of this edge. - * @param v2 - * - * FIXME EDGES : The concept of the "source" of an edge is - * actually quite misleading. This was originally an (arbitrary) - * vertex which shared a variable with the target vertex. - * However, in order to handle joins which are only indirectly - * constrained by a constraint we need to allow for a source - * vertex which does not share any variable (directly) with the - * target vertex. In addition, we also need the source path or - * the set of constraints to be attached to the edge. Finally, we - * can no longer share edges since they have to have some aspect - * of history attached. All in all, the "edge" is really just the - * last aspect of a path so what we have are ordered arrays of - * predicates and the constraints which run when each predicate - * is evaluated as part of a join. - */ - // * @param shared - public Edge(// - // final IPredicate<?>[] path, - final Vertex v1, final Vertex v2 - // , final Set<IVariable<?>> shared - ) { - if (v1 == null) - throw new IllegalArgumentException(); - if (v2 == null) - throw new IllegalArgumentException(); - // if (shared == null) - // throw new IllegalArgumentException(); - // Note: We need to allow edges which do not share variables - // if (shared.isEmpty()) - // throw new IllegalArgumentException(); - this.v1 = v1; - this.v2 = v2; - // this.shared = shared; - } - - /** - * The edge label is formed from the {@link BOp.Annotations#BOP_ID} of its - * ordered vertices (v1,v2). - */ - public String getLabel() { - - return "(" + v1.pred.getId() + "," + v2.pred.getId() + ")"; - - } - - /** - * Note: The vertices of the edge are labeled using the - * {@link BOp.Annotations#BOP_ID} associated with the {@link IPredicate} for - * each vertex. - */ - public String toString() { - - return "Edge{ " + getLabel() + ", estCard=" - + (sample == null ? "N/A" : sample.estimatedCardinality) - // + ", shared=" + shared.toString() + - + ", sample=" + sample// - + "}"; - - } - - /** - * Equality is determined by reference testing. - */ - public boolean equals(final Object o) { - - return this == o; - - } - - /** - * The hash code of an edge is the hash code of the vertex with the smaller - * hash code X 31 plus the hash code of the vertex with the larger hash - * code. This definition compensates for the arbitrary order in which the - * vertices may be expressed and also recognizes that the vertex hash codes - * are based on the bop ids, which are often small integers. - */ - public int hashCode() { - - if (hash == 0) { - - final int h1 = v1.hashCode(); - final int h2 = v2.hashCode(); - - final int h; - if (h1 < h2) { - - h = h1 * 31 + h2; - - } else { - - h = h2 * 31 + h1; - - } - - hash = h; - - } - return hash; - - } - - private int hash; - - /** - * Return the vertex with the smaller estimated cardinality. - * - * @throws IllegalStateException - * if either vertex has not been sampled. - */ - public Vertex getMinimumCardinalityVertex() { - - if (v1.sample == null) // vertex not sampled. - throw new IllegalStateException(); - - if (v2.sample == null) // vertex not sampled. - throw new IllegalStateException(); - - return (v1.sample.estimatedCardinality < v2.sample.estimatedCardinality) ? v1 : v2; - - } - - /** - * Return the vertex with the larger estimated cardinality (the vertex not - * returned by {@link #getMinimumCardinalityVertex()}). - * - * @throws IllegalStateException - * if either vertex has not been sampled. - */ - public Vertex getMaximumCardinalityVertex() { - - // The vertex with the minimum cardinality. - final Vertex o = getMinimumCardinalityVertex(); - - // Return the other vertex. - return (v1 == o) ? v2 : v1; - - } - - /** - * Estimate the cardinality of the edge, updating {@link #sample} as a - * side-effect. This is a NOP if the edge has already been sampled at that - * <i>limit</i>. This is a NOP if the edge sample is exact. - * - * @param queryEngine - * The query engine. - * @param limit - * The sample size. - * - * @return The new {@link EdgeSample} (this is also updated on - * {@link #sample} as a side-effect). - * - * @throws Exception - * - * FIXME This is actually using the source vertex as the source - * sample which is WRONG. - */ - public EdgeSample estimateCardinality(final QueryEngine queryEngine, - final int limit) throws Exception { - - if (limit <= 0) - throw new IllegalArgumentException(); - - // /* - // * Note: There is never a need to "re-sample" the edge. Unlike ROX, - // * we always can sample a vertex. This means that we can sample the - // * edges exactly once, during the initialization of the join graph. - // */ - // if (sample != null) - // throw new RuntimeException(); - - if (sample != null) { - - if (sample.limit >= limit) { - - // Already sampled at that limit. - return sample; - - } - - if (sample.estimateEnum == EstimateEnum.Exact) { - - // Sample is exact (fully materialized result). - return sample; - - } - - } - - /* - * Figure out which vertex has the smaller cardinality. The sample of - * that vertex is used since it is more representative than the sample - * of the other vertex. - * - * Note: If there are constraints which can run for this edge, then they - * will be attached when the edge is sampled. - */ - // vertex v, vprime - final Vertex v, vp; - if (v1.sample == null) // vertex not sampled. - throw new IllegalStateException(); - if (v2.sample == null) // vertex not sampled. - throw new IllegalStateException(); - if (v1.sample.estimatedCardinality < v2.sample.estimatedCardinality) { - v = v1; - vp = v2; - } else { - v = v2; - vp = v1; - } - -// /* -// * Convert the source sample into an IBindingSet[]. -// * -// * Note: This is now done when we sample the vertex. -// */ -// final IBindingSet[] sourceSample = new IBindingSet[v.sample.sample.length]; -// { -// for (int i = 0; i < sourceSample.length; i++) { -// final IBindingSet bset = new HashBindingSet(); -// BOpContext.copyValues((IElement) v.sample.sample[i], v.pred, -// bset); -// sourceSample[i] = bset; -// } -// } - - // Sample the edge and save the sample on the edge as a side-effect. - this.sample = estimateCardinality(queryEngine, limit, v, vp, - v.sample // the source sample. -// v.sample.estimatedCardinality,// -// v.sample.estimateEnum == EstimateEnum.Exact, // -// v.sample.limit,// -// v.sample.sample// - ); - - return sample; - - } - - /** - * Estimate the cardinality of the edge given a sample of either a vertex or - * a join path leading up to that edge. - * <p> - * Note: The caller is responsible for protecting against needless - * re-sampling. - * - * @param queryEngine - * The query engine. - * @param limit - * The limit for the cutoff join. - * @param vSource - * The source vertex. - * @param vTarget - * The target vertex - * @param sourceSample - * The input sample for the cutoff join. When this is a one-step - * estimation of the cardinality of the edge, then this sample is - * taken from the {@link VertexSample}. When the edge (vSource, - * vTarget) extends some {@link Path}, then this is taken from - * the {@link EdgeSample} for that {@link Path}. - * - * @return The result of sampling that edge. - * - * @throws Exception - */ - // * @param path The path which is being extended. - public EdgeSample estimateCardinality(// - final QueryEngine queryEngine,// - final int limit,// - // final IPredicate<?>[] path,// - final Vertex vSource,// - final Vertex vTarget,// - final SampleBase sourceSample// -// final long sourceEstimatedCardinality,// -// final boolean sourceSampleExact,// -// final int sourceSampleLimit,// -// final IBindingSet[] sourceSample// - ) throws Exception { - - if (limit <= 0) - throw new IllegalArgumentException(); - - /* - * Note: This sets up a cutoff pipeline join operator which makes an - * accurate estimate of the #of input solutions consumed and the #of - * output solutions generated. From that, we can directly compute the - * join hit ratio. This approach is preferred to injecting a "RowId" - * column as the estimates are taken based on internal counters in the - * join operator and the join operator knows how to cutoff evaluation as - * soon as the limit is satisfied, thus avoiding unnecessary effort. - */ - /* - * The set of constraint(s) (if any) which will be applied when we - * perform the cutoff evaluation of this edge (aka join). - * - * FIXME CONSTRAINTS - we need the join path to decide which constraints - * will be attached when we sample this edge (or at least the set of - * variables which are already known to be bound). - */ - final IConstraint[] constraints = null; - final int joinId = 1; - final Map<String, Object> anns = NV.asMap( - // - new NV(BOp.Annotations.BOP_ID, joinId),// - // @todo Why not use a factory which avoids bopIds - // already in use? - new NV(PipelineJoin.Annotations.PREDICATE, vTarget.pred.setBOpId(3)), - // Note: does not matter since not executed by the query - // controller. - // // disallow parallel evaluation of tasks - // new NV(PipelineOp.Annotations.MAX_PARALLEL,1), - // disallow parallel evaluation of chunks. - new NV(PipelineJoin.Annotations.MAX_PARALLEL_CHUNKS, 0), - // disable access path coalescing - new NV( PipelineJoin.Annotations.COALESCE_DUPLICATE_ACCESS_PATHS, false), // - // pass in constraints on this join. - new NV(PipelineJoin.Annotations.CONSTRAINTS, constraints),// - // cutoff join. - new NV(PipelineJoin.Annotations.LIMIT, (long) limit), - /* - * Note: In order to have an accurate estimate of the - * join hit ratio we need to make sure that the join - * operator runs using a single PipelineJoinStats - * instance which will be visible to us when the query - * is cutoff. In turn, this implies that the join must - * be evaluated on the query controller. - * - * @todo This implies that sampling of scale-out joins - * must be done using remote access paths. - */ - new NV(PipelineJoin.Annotations.SHARED_STATE, true),// - new NV(PipelineJoin.Annotations.EVALUATION_CONTEXT, - BOpEvaluationContext.CONTROLLER)// - ); - - @SuppressWarnings("unchecked") - final PipelineJoin<?> joinOp = new PipelineJoin(new BOp[] {}, anns); - - final PipelineOp queryOp = joinOp; - - // run the cutoff sampling of the edge. - final UUID queryId = UUID.randomUUID(); - final IRunningQuery runningQuery = queryEngine.eval(queryId, queryOp, - new LocalChunkMessage<IBindingSet>(queryEngine, queryId, joinOp - .getId()/* startId */, -1 /* partitionId */, - new ThickAsynchronousIterator<IBindingSet[]>( - new IBindingSet[][] { sourceSample.sample }))); - - final List<IBindingSet> result = new LinkedList<IBindingSet>(); - try { - try { - IBindingSet bset = null; - // Figure out the #of source samples consumed. - final Iterator<IBindingSet> itr = new Dechunkerator<IBindingSet>( - runningQuery.iterator()); - while (itr.hasNext()) { - bset = itr.next(); - result.add(bset); - } - } finally { - // verify no problems. - runningQuery.get(); - } - } finally { - runningQuery.cancel(true/* mayInterruptIfRunning */); - } - - // The join hit ratio can be computed directly from these stats. - final PipelineJoinStats joinStats = (PipelineJoinStats) runningQuery - .getStats().get(joinId); - - if (log.isTraceEnabled()) - log.trace(joinStats.toString()); - - // #of solutions in. - final int inputCount = (int) joinStats.inputSolutions.get(); - - // #of solutions out. - long outputCount = joinStats.outputSolutions.get(); - - // cumulative range count of the sampled access paths. - final long sumRangeCount = joinStats.accessPathRangeCount.get(); - - final EstimateEnum estimateEnum; - if (sourceSample.estimateEnum == EstimateEnum.Exact - && outputCount < limit) { - /* - * Note: If the entire source vertex is being fed into the cutoff - * join and the cutoff join outputCount is LT the limit, then the - * sample is the actual result of the join. That is, feeding all - * source solutions into the join gives fewer than the desired - * number of output solutions. - */ - estimateEnum = EstimateEnum.Exact; - } else if (inputCount == 1 && outputCount == limit) { - /* - * If the inputCount is ONE (1) and the outputCount is the limit, - * then the estimated cardinality is a lower bound as more than - * outputCount solutions might be produced by the join when - * presented with a single input solution. - * - * However, this condition suggests that the sum of the sampled - * range counts is a much better estimate of the cardinality of this - * join. - * - * For example, consider a join feeding a rangeCount of 16 into a - * rangeCount of 175000. With a limit of 100, we estimated the - * cardinality at 1600L (lower bound). In fact, the cardinality is - * 16*175000. This falsely low estimate can cause solutions which - * are really better to be dropped. - */ - // replace outputCount with the sum of the sampled range counts. - outputCount = sumRangeCount; - estimateEnum = EstimateEnum.LowerBound; - } else if (!(sourceSample.estimateEnum != EstimateEnum.Exact) - && inputCount == Math.min(sourceSample.limit, - sourceSample.estimatedCardinality) && outputCount == 0) { - /* - * When the source sample was not exact, the inputCount is EQ to the - * lesser of the source range count and the source sample limit, and - * the outputCount is ZERO (0), then feeding in all source solutions - * in is not sufficient to generate any output solutions. In this - * case, the estimated join hit ratio appears to be zero. However, - * the estimation of the join hit ratio actually underflowed and the - * real join hit ratio might be a small non-negative value. A real - * zero can only be identified by executing the full join. - * - * Note: An apparent join hit ratio of zero does NOT imply that the - * join will be empty (unless the source vertex sample is actually - * the fully materialized access path - this case is covered above). - */ - estimateEnum = EstimateEnum.Underflow; - } else { - estimateEnum = EstimateEnum.Normal; - } - - final double f = outputCount == 0 ? 0 - : (outputCount / (double) inputCount); - - final long estimatedCardinality = (long) (sourceSample.estimatedCardinality * f); - - final EdgeSample edgeSample = new EdgeSample(// -// sourceSample.estimatedCardinality, // -// sourceSample.estimateEnum, // -// sourceSample.limit, // - sourceSample,// - inputCount,// - outputCount, // - f, // - // args to SampleBase - estimatedCardinality, // - limit, // - estimateEnum,// - result.toArray(new IBindingSet[result.size()])); - - if (log.isDebugEnabled()) - log.debug(getLabel() + " : newSample=" + edgeSample); - - return edgeSample; - - } - -} Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EdgeSample.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EdgeSample.java 2011-02-23 14:44:18 UTC (rev 4234) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EdgeSample.java 2011-02-23 21:52:48 UTC (rev 4235) @@ -26,59 +26,17 @@ import com.bigdata.bop.IBindingSet; /** - * A sample of an {@link Edge} (a join). + * A sample produced by a cutoff join. */ public class EdgeSample extends SampleBase { -// private static final transient Logger log = Logger -// .getLogger(EdgeSample.class); + // private static final transient Logger log = Logger + // .getLogger(EdgeSample.class); -// /** -// * The estimated cardinality of the cutoff join. -// */ -// public final long estimatedCardinality; -// -// /** -// * The limit used to sample the cutoff join. -// */ -// public final int limit; -// -// /** -// * Indicates whether the estimate is exact, an upper bound, or a lower -// * bound. -// */ -// public final EstimateEnum estimateEnum; -// -// /** -// * The sample of the solutions for the join path. -// */ -// final IBindingSet[] sample; - /** * The source sample used to compute the cutoff join. */ public final SampleBase sourceSample; - -// /** -// * The estimated cardinality of the source sample. -// */ -// public final long sourceEstimatedCardinality; -// -// /** -// * The sample type for the source sample. -// */ -// public final EstimateEnum sourceEstimateEnum; -// -// /** -// * Return <code>true</code> iff the source sample is exact (because the -// * source is either a fully materialized vertex or an edge whose solutions -// * have been fully materialized). -// */ -// public boolean isSourceSampleExact() { -// -// return sourceEstimateEnum == EstimateEnum.Exact; -// -// } /** * The #of binding sets out of the source sample vertex sample which were @@ -96,6 +54,11 @@ public final long outputCount; /** + * The #of tuples read from the access path when processing the cutoff join. + */ + public final long tuplesRead; + + /** * The ratio of the #of input samples consumed to the #of output samples * generated (the join hit ratio or scale factor). */ @@ -115,60 +78,47 @@ * which were consumed. * @param outputCount * The #of binding sets generated before the join was cutoff. + * @param tuplesRead + * The #of tuples read from the access path when processing the + * cutoff join. */ -// * @param sourceVertexSample -// * The sample for source vertex of the edge (whichever vertex has -// * the lower cardinality). - EdgeSample( - // final VertexSample sourceVertexSample, - final SampleBase sourceSample,// -// final long sourceEstimatedCardinality,// -// final EstimateEnum sourceEstimateEnum, // -// final int sourceSampleLimit,// + EdgeSample(final SampleBase sourceSample,// final int inputCount, // final long outputCount,// + final long tuplesRead,// final double f, // // args to SampleBase final long estimatedCardinality,// final int limit,// final EstimateEnum estimateEnum,// final IBindingSet[] sample// - ) { + ) { super(estimatedCardinality, limit, estimateEnum, sample); - if(sourceSample == null) + if (sourceSample == null) throw new IllegalArgumentException(); this.sourceSample = sourceSample; -// this.sourceEstimatedCardinality = sourceSample.estimatedCardinality; -// -// this.sourceEstimateEnum = sourceSample.estimateEnum; - this.inputCount = inputCount; this.outputCount = outputCount; + this.tuplesRead = tuplesRead; + this.f = f; } @Override protected void toString(final StringBuilder sb) { -// return getClass().getName() // -// + "{ estimatedCardinality=" + estimatedCardinality// -// + ", limit=" + limit // -// + ", estimateEnum=" + estimateEnum// - sb.append(", sourceEstimatedCardinality=" + sourceSample.estimatedCardinality); + sb.append(", sourceEstimatedCardinality=" + + sourceSample.estimatedCardinality); sb.append(", sourceEstimateEnum=" + sourceSample.estimateEnum); sb.append(", inputCount=" + inputCount); sb.append(", outputCount=" + outputCount); sb.append(", f=" + f); - // + ", estimateIsLowerBound=" + estimateIsLowerBound// - // + ", estimateIsUpperBound=" + estimateIsUpperBound// - // + ", sampleIsExactSolution=" + estimateIsExact // -// + "}"; } } Copied: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimatedCardinalityComparator.java (from rev 4234, branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimatedEdgeCardinalityComparator.java) =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimatedCardinalityComparator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimatedCardinalityComparator.java 2011-02-23 21:52:48 UTC (rev 4235) @@ -0,0 +1,62 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +package com.bigdata.bop.joinGraph.rto; + +import java.util.Comparator; + + +/** + * Places edges into order by ascending estimated cardinality. Edges which + * are not weighted are ordered to the end. + * + * TODO unit tests, including with unweighted edges. + */ +class EstimatedCardinalityComparator implements Comparator<Path> { + + public static final transient Comparator<Path> INSTANCE = new EstimatedCardinalityComparator(); + + // @Override + public int compare(final Path o1, final Path o2) { + if (o1.edgeSample == null && o2.edgeSample == null) { + // Neither edge is weighted. + return 0; + } + if (o1.edgeSample == null) { + // o1 is not weighted, but o2 is. sort o1 to the end. + return 1; + } + if (o2.edgeSample == null) { + // o2 is not weighted. sort o2 to the end. + return -1; + } + final long id1 = o1.edgeSample.estimatedCardinality; + final long id2 = o2.edgeSample.estimatedCardinality; + if (id1 < id2) + return -1; + if (id1 > id2) + return 1; + return 0; + } + +} Deleted: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimatedEdgeCardinalityComparator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimatedEdgeCardinalityComparator.java 2011-02-23 14:44:18 UTC (rev 4234) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimatedEdgeCardinalityComparator.java 2011-02-23 21:52:48 UTC (rev 4235) @@ -1,62 +0,0 @@ -/** - -Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. - -Contact: - SYSTAP, LLC - 4501 Tower Road - Greensboro, NC 27410 - lic...@bi... - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ -package com.bigdata.bop.joinGraph.rto; - -import java.util.Comparator; - - -/** - * Places edges into order by ascending estimated cardinality. Edges which - * are not weighted are ordered to the end. - * - * TODO unit tests, including with unweighted edges. - */ -class EstimatedEdgeCardinalityComparator implements Comparator<Edge> { - - public static final transient Comparator<Edge> INSTANCE = new EstimatedEdgeCardinalityComparator(); - - // @Override - public int compare(final Edge o1, final Edge o2) { - if (o1.sample == null && o2.sample == null) { - // Neither edge is weighted. - return 0; - } - if (o1.sample == null) { - // o1 is not weighted, but o2 is. sort o1 to the end. - return 1; - } - if (o2.sample == null) { - // o2 is not weighted. sort o2 to the end. - return -1; - } - final long id1 = o1.sample.estimatedCardinality; - final long id2 = o2.sample.estimatedCardinality; - if (id1 < id2) - return -1; - if (id1 > id2) - return 1; - return 0; - } - -} Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java 2011-02-23 14:44:18 UTC (rev 4234) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java 2011-02-23 21:52:48 UTC (rev 4235) @@ -30,7 +30,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.Formatter; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; @@ -44,11 +43,9 @@ import com.bigdata.bop.BOpUtility; import com.bigdata.bop.IConstraint; import com.bigdata.bop.IPredicate; -import com.bigdata.bop.IVariable; import com.bigdata.bop.ap.SampleIndex.SampleType; import com.bigdata.bop.engine.QueryEngine; import com.bigdata.bop.joinGraph.NoSolutionsException; -import com.bigdata.bop.joinGraph.PartitionedJoinGroup; import com.bigdata.bop.rdf.join.DataSetJoin; /** @@ -236,50 +233,50 @@ */ private final SampleType sampleType; - /** - * The edges of the join graph as determined by static analysis. Each - * edge is basically a possible join. This array is comprised of just - * those edges which are determined by static analysis. Additional edges - * MAY be identified dynamically. Altogether there are three categories - * of edges: - * <ol> - * <li>The vertices directly share variables (join with shared - * variable(s)). These edges are identified by static analysis in the - * constructor are are represented in {@link #E}.</li> - * <li>The vertices indirectly share variables via a constraint (join - * with indirectly shared variable(s)). These edges are identified by - * dynamic analysis. Each time we expand the set of join paths under - * consideration, we examine {@link #unshared} vertices. Given the join - * path under consideration and the set of constraints, it may be that - * the vertex will indirectly share a variable via a constraint and can - * therefore participate in a constrained join.</li> - * <li>The vertices do not share variables, either directly or - * indirectly (unconstrained join). All vertices can join. However, if - * there are no shared variables then the join is unconstrained (full - * cross product). These edges are identified dynamically. In each round - * for which a constrained edge could not be identified, we consider all - * vertices in {@link #unshared} and choose an unconstrained edge.</li> - * </ol> - * - * @see BOpUtility#canJoinUsingConstraints(IPredicate[], IPredicate, IConstraint[]) - */ - private final Edge[] E; +// /** +// * The edges of the join graph as determined by static analysis. Each +// * edge is basically a possible join. This array is comprised of just +// * those edges which are determined by static analysis. Additional edges +// * MAY be identified dynamically. Altogether there are three categories +// * of edges: +// * <ol> +// * <li>The vertices directly share variables (join with shared +// * variable(s)). These edges are identified by static analysis in the +// * constructor are are represented in {@link #E}.</li> +// * <li>The vertices indirectly share variables via a constraint (join +// * with indirectly shared variable(s)). These edges are identified by +// * dynamic analysis. Each time we expand the set of join paths under +// * consideration, we examine {@link #unshared} vertices. Given the join +// * path under consideration and the set of constraints, it may be that +// * the vertex will indirectly share a variable via a constraint and can +// * therefore participate in a constrained join.</li> +// * <li>The vertices do not share variables, either directly or +// * indirectly (unconstrained join). All vertices can join. However, if +// * there are no shared variables then the join is unconstrained (full +// * cross product). These edges are identified dynamically. In each round +// * for which a constrained edge could not be identified, we consider all +// * vertices in {@link #unshared} and choose an unconstrained edge.</li> +// * </ol> +// * +// * @see BOpUtility#canJoinUsingConstraints(IPredicate[], IPredicate, IConstraint[]) +// */ +// private final Edge[] E; - /** - * An unordered collection of vertices which do not share any variables - * with the other vertices in the join graph. These vertices will - * produce full cross product joins unless a constraint causes indirect - * sharing of variables with a join path. - */ - private final Vertex[] unshared; +// /** +// * An unordered collection of vertices which do not share any variables +// * with the other vertices in the join graph. These vertices will +// * produce full cross product joins unless a constraint causes indirect +// * sharing of variables with a join path. +// */ +// private final Vertex[] unshared; public List<Vertex> getVertices() { return Collections.unmodifiableList(Arrays.asList(V)); } - public List<Edge> getEdges() { - return Collections.unmodifiableList(Arrays.asList(E)); - } +// public List<Edge> getEdges() { +// return Collections.unmodifiableList(Arrays.asList(E)); +// } public String toString() { final StringBuilder sb = new StringBuilder(); @@ -292,14 +289,14 @@ for (IConstraint c : C) { sb.append("\nC[" + c.getId() + "]=" + c); } - sb.append("\n],unshared=["); - for (Vertex v : unshared) { - sb.append("\n" + v); - } - sb.append("],E=["); - for (Edge e : E) { - sb.append("\n" + e); - } +// sb.append("\n],unshared=["); +// for (Vertex v : unshared) { +// sb.append("\n" + v); +// } +// sb.append("],E=["); +// for (Edge e : E) { +// sb.append("\n" + e); +// } sb.append("\n]}"); return sb.toString(); } @@ -367,185 +364,160 @@ this.sampleType = sampleType; - /* - * Create edges to represent possible joins between predicates based - * on directly shared variables - these joins can be identified by a - * static analysis of the join graph. - * - * Note: There are really three classes of joins to be considered. - * - * (1) The target predicate directly shares a variable with the - * source predicate. These joins are always constrained since the - * source predicate will have bound that variable. This is the - * static analysis of the join graph. - * - * (2) When the source predicate shares a variable with a constraint - * which also shares a variable with the target predicate. While the - * predicates do not directly share a variable, these joins are - * constrained by the shared variable in the constraint on the - * target predicate. BSBM Q5 is an example of this case. We do not - * create edges for such joins here. Instead, we dynamically - * determine when a constrained join is possible when extending the - * join path in each round. Hence, this is part of the dynamic - * analysis of the join graph. - * - * (3) Any two predicates may always be joined. However, joins which - * do not share variables either directly or indirectly will be full - * cross products. Therefore such joins are run last and we do not - * create edges for them here. Again, this is part of the dynamic - * analysis of the join graph. - */ - { - - // The set of identified edges for vertices which share vars. - final List<Edge> tmp = new LinkedList<Edge>(); - - // The set of vertices which share variables. - final Set<Vertex> sharedEdgeVertices = new LinkedHashSet<Vertex>(); - - // The set of vertices which do not share variables. - final List<Vertex> unsharedEdgeVertices = new LinkedList<Vertex>(); - - for (int i = 0; i < v.length; i++) { - - // consider a source vertex. - final IPredicate<?> p1 = v[i]; - - // #of vertices which share a variable with source vertex. - int nmatched = 0; - - for (int j = i + 1; j < v.length; j++) { - - // consider a possible target vertex. - final IPredicate<?> p2 = v[j]; - -// final Set<IVariable<?>> shared = BOpUtility -// .getSharedVars(p1, p2); - - if(BOpUtility.canJoin(p1, p2)) { -// if (!shared.isEmpty()) { - - /* - * The source and target vertices can join based on - * one or more shared variable(s). - */ - - if (log.isDebugEnabled()) - log.debug("vertices shared variable(s): vars=" - + BOpUtility.getSharedVars(p1, p2) - + ", v1=" + p1 + ", v2=" + p2); - - tmp.add(new Edge(V[i], V[j]));//, shared)); - - sharedEdgeVertices.add(V[i]); - - sharedEdgeVertices.add(V[j]); - - nmatched++; - - } else if (constraints != null) { - - /* - * The source and target vertices do not directly - * share any variable(s). However, there may be a - * constraint which shares a variable with both the - * source and target vertex. If such a constraint is - * found, then we add an edge now as that join is - * potentially constrained (less than the full - * Cartesian cross product). - * - * Note: While this identifies possible joins via a - * constraint, such joins are only legal when all - * variables used by the constraint are known to be - * bound. - * - * FIXME Edges should be identified dynamically, not - * statically. Probably all edges (aka possible - * joins) should be identified dynamically given the - * history represented by a given join path and the - * set of constraints declared for the join graph. - */ - - for(IConstraint c : constraints) { - - if(BOpUtility.getSharedVars(p1, c).isEmpty()) - continue; - - if(BOpUtility.getSharedVars(p2, c).isEmpty()) - continue; - - if (log.isDebugEnabled()) - log - .debug("vertices shared variable(s) via constraint: v1=" - + p1 - + ", v2=" - + p2 - + ", c=" + c); - - tmp.add(new Edge(V[i], V[j]));//, shared)); - - sharedEdgeVertices.add(V[i]); - - sharedEdgeVertices.add(V[j]); - - nmatched++; - - } - - } - - } - - if (nmatched == 0 && !sharedEdgeVertices.contains(V[i])) { - - /* - * The source vertex does not share any variables. - */ - - log - .warn("Vertex does not share any variables: " - + V[i]); - - unsharedEdgeVertices.add(V[i]); - - } - - } // create edges - - E = tmp.toArray(new Edge[0]); - - this.unshared = unsharedEdgeVertices.toArray(new Vertex[0]); - -// if(!unsharedEdgeVertices.isEmpty()) { +// /* +// * Create edges to represent possible joins between predicates based on +// * directly shared variables - these joins can be identified by a static +// * analysis of the join graph. +// */ +// { // -// /* -// * FIXME NO SHARED VARS : RUN LAST. This needs to be -// * supported. When vertices that do not share variables -// * either directly or via a constraint then they should run -// * last as they can not constrain the query. In this case, -// * they are not considered by the runtime optimizer when -// * building up the join path until all vertices which share -// * variables have been exhausted. At that point, the -// * remaining vertices are just appended to whatever join -// * path was selected as having the lowest cumulative -// * estimated cardinality. -// * -// * However, if there exists for a vertex which otherwise -// * does not share variables a constraint which should be -// * evaluated against that vertex, then that constraint -// * provides the basis for a edge (aka join). In this case, -// * an edge must be created for the vertex based on the -// * shared variable in the constraint and its position in the -// * join path will be decided by the runtime optimizer. -// */ +// // The set of identified edges for vertices which share vars. +// final List<Edge> tmp = new LinkedList<Edge>(); // -// throw new UnsupportedOperationException( -// "Some predicates do not share any variables with other predicates: unshared=" -// + unsharedEdgeVertices); -// -// } - - } +// // The set of vertices which share variables. +// final Set<Vertex> sharedEdgeVertices = new LinkedHashSet<Vertex>(); +// +//// // The set of vertices which do not share variables. +//// final List<Vertex> unsharedEdgeVertices = new LinkedList<Vertex>(); +// +// for (int i = 0; i < v.length; i++) { +// +// // consider a source vertex. +// final IPredicate<?> p1 = v[i]; +// +// // #of vertices which share a variable with source vertex. +// int nmatched = 0; +// +// for (int j = i + 1; j < v.length; j++) { +// +// // consider a possible target vertex. +// final IPredicate<?> p2 = v[j]; +// +//// final Set<IVariable<?>> shared = BOpUtility +//// .getSharedVars(p1, p2); +// +// if(BOpUtility.canJoin(p1, p2)) { +//// if (!shared.isEmpty()) { +// +// /* +// * The source and target vertices can join based on +// * one or more shared variable(s). +// */ +// +// if (log.isDebugEnabled()) +// log.debug("vertices shared variable(s): vars=" +// + BOpUtility.getSharedVars(p1, p2) +// + ", v1=" + p1 + ", v2=" + p2); +// +// tmp.add(new Edge(V[i], V[j]));//, shared)); +// +// sharedEdgeVertices.add(V[i]); +// +// sharedEdgeVertices.add(V[j]); +// +// nmatched++; +// +// } else if (constraints != null) { +// +// /* +// * The source and target vertices do not directly +// * share any variable(s). However, there may be a +// * constraint which shares a variable with both the +// * source and target vertex. If such a constraint is +// * found, then we add an edge now as that join is +// * potentially constrained (less than the full +// * Cartesian cross product). +// * +// * Note: While this identifies possible joins via a +// * constraint, such joins are only legal when all +// * variables used by the constraint are known to be +// * bound. +// * +// * FIXME Edges should be identified dynamically, not +// * statically. Probably all edges (aka possible +// * joins) should be identified dynamically given the +// * history represented by a given join path and the +// * set of constraints declared for the join graph. +// */ +// +// for(IConstraint c : constraints) { +// +// if(BOpUtility.getSharedVars(p1, c).isEmpty()) +// continue; +// +// if(BOpUtility.getSharedVars(p2, c).isEmpty()) +// continue; +// +// if (log.isDebugEnabled()) +// log +// .debug("vertices shared variable(s) via constraint: v1=" +// + p1 +// + ", v2=" +// + p2 +// + ", c=" + c); +// +// tmp.add(new Edge(V[i], V[j]));//, shared)); +// +// sharedEdgeVertices.add(V[i]); +// +// sharedEdgeVertices.add(V[j]); +// +// nmatched++; +// +// } +// +// } +// +// } +// +// if (nmatched == 0 && !sharedEdgeVertices.contains(V[i])) { +// +// /* +// * The source vertex does not share any variables. +// */ +// +// log.warn("Vertex does not share any variables: " + V[i]); +// +//// unsharedEdgeVertices.add(V[i]); +// +// } +// +// } // next vertex +// +// E = tmp.toArray(new Edge[0]); +// +//// this.unshared = unsharedEdgeVertices.toArray(new Vertex[0]); +// +//// if(!unsharedEdgeVertices.isEmpty()) { +//// +//// /* +//// * FIXME NO SHARED VARS : RUN LAST. This needs to be +//// * supported. When vertices that do not share variables +//// * either directly or via a constraint then they should run +//// * last as they can not constrain the query. In this case, +//// * they are not considered by the runtime optimizer when +//// * building up the join path until all vertices which share +//// * variables have been exhausted. At that point, the +//// * remaining vertices are just appended to whatever join +//// * path was selected as having the lowest cumulative +//// * estimated cardinality. +//// * +//// * However, if there exists for a vertex which otherwise +//// * does not share variables a constraint which should be +//// * evaluated against that vertex, then that constraint +//// * provides the basis for a edge (aka join). In this case, +//// * an edge must be created for the vertex based on the +//// * shared variable in the constraint and its position in the +//// * join path will be decided by the runtime optimizer. +//// */ +//// +//// throw new UnsupportedOperationException( +//// "Some predicates do not share any variables with other predicates: unshared=" +//// + unsharedEdgeVertices); +//// +//// } +// +// } // create edges. } @@ -626,9 +598,27 @@ int round = 1; + /* + * This map is used to associate join path segments (expressed as an + * ordered array of bopIds) with edge sample to avoid redundant effort. + * + * FIXME HEAP MANAGMENT : This map holds references to the cutoff join + * samples. To ensure that the map has the minimum heap footprint, it + * must be scanned each time we prune the set of active paths and any + * entry which is not a prefix of an active path should be removed. + * + * TODO MEMORY MANAGER : When an entry is cleared from this map, the + * corresponding allocation in the memory manager (if any) must be + * released. The life cycle of the map needs to be bracketed by a + * try/finally in order to ensure that all allocations associated with + * the map are released no later than when we leave the lexicon scope of + * that clause. + */ + final Map<PathIds, EdgeSample> edgeSamples = new LinkedHashMap<PathIds, EdgeSample>(); + while (paths.length > 0 && round < nvertices - 1) { - paths = expand(queryEngine, limit, round++, paths); + paths = expand(queryEngine, limit, round++, paths, edgeSamples); } @@ -644,13 +634,9 @@ if (log.isInfoEnabled()) { - /* - * @todo It would be nice to show the plan with the filters - * attached, but that might be something that the caller does. - */ log.info("\n*** Selected join path: " + Arrays.toString(paths[0].getVertexIds()) + "\n" - + showPath(paths[0])); + + showPath(paths[0], edgeSamples)); } @@ -674,7 +660,7 @@ if(p == null) throw new IllegalArgumentException(); - final IPredicate[] path = p.getPredicates(); + final IPredicate<?>[] path = p.getPredicates(); if (path.length != V.length) { throw new IllegalArgumentException( @@ -712,46 +698,45 @@ * * @param nedges * The maximum #of edges to choose. + * @param paths + * The set of possible initial paths to choose from. + * + * @return Up to <i>nedges</i> minimum cardinality paths. */ - public Path[] chooseStartingPaths(final int nedges) { + public Path[] chooseStartingPaths(final int nedges, final Path[] paths) { final List<Path> tmp = new LinkedList<Path>(); - // All edges in the graph. - final Edge[] edges = getEdges().toArray(new Edge[0]); - // Sort them by ascending expected cardinality. - Arrays.sort(edges, 0, edges.length, - EstimatedEdgeCardinalityComparator.INSTANCE); + Arrays.sort(paths, 0, paths.length, + EstimatedCardinalityComparator.INSTANCE); // Choose the top-N edges (those with the least cardinality). - for (int i = 0; i < edges.length && i < nedges; i++) { + for (int i = 0; i < paths.length && i < nedges; i++) { - tmp.add(new Path(ed... [truncated message content] |
From: <tho...@us...> - 2011-02-23 14:44:26
|
Revision: 4234 http://bigdata.svn.sourceforge.net/bigdata/?rev=4234&view=rev Author: thompsonbry Date: 2011-02-23 14:44:18 +0000 (Wed, 23 Feb 2011) Log Message: ----------- Working on the runtime optimizer. - Split the JGraph class out of the JoinGraph operator. - Split out the static inner classes {Edge, Vertex, VertexSample, EdgeSample, Path, etc.} to reduce the complexity of the JGraph class file. Note that LUBM U1 has no solutions for Q2. Likewise, there are no solutions for BSBM Q5 for the 100 data set. However, it produces the same join ordering as the 100M and 200M data sets. - Added a SAMPLE_TYPE argument to the JoinGraph and modified JGraph to accept the SampleType as an argument in its constructor which is then passed through to the code which actually samples the vertices. - Modified the unit tests to use a non-random sample of the vertices by default in order to make the test results repeatable. However, it is interesting to run the tests against larger external data sets with random sampling to observe the effects of the sample bias on the estimated cost of the query! - Added a SampleBase which is extended by VertexSample and EdgeSample. - Modified SampleBase and SampleVertex to represent samples as IBindingSet[]s. Note: At some point we will need to generalize this to accept samples which are stored on the heap using the memory manager. This should be addressed when we integrate the memory manager into the query engine as the same abstraction is required in both places. In addition, the RTO will need to directly manage the allocation contexts associated with the samples so they can be released in a timely manner and no later than when the runtimeOptimization() method is done (except that exact samples could be used to execute the query once we drive the named and default graph query constructions down into the RTO by using an inline AP for the DataSetJoin). Note: This also fixes the build. My last commit included a reference to JGraph as a top-level class, which broken the build. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/ap/SampleIndex.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JoinGraph.java branches/QUADS_QUERY_BRANCH/bigdata/src/resources/logging/log4j.properties branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/rto/TestJGraph.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/AbstractJoinGraphTestCase.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBarData.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnLubm.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Edge.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EdgeSample.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimateEnum.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimatedEdgeCardinalityComparator.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Path.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/SampleBase.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Vertex.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/VertexSample.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/ap/SampleIndex.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/ap/SampleIndex.java 2011-02-23 13:43:56 UTC (rev 4233) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/ap/SampleIndex.java 2011-02-23 14:44:18 UTC (rev 4234) @@ -96,9 +96,12 @@ * sampling join paths. */ public static enum SampleType { - /** - * Samples are taken at even space offsets. - */ + /** + * Samples are taken at even space offsets. This produces a sample + * without any random effects. Re-sampling an index having the same data + * with the same key-range and the limit will always return the same + * results. This is useful to make unit test repeatable. + */ EVEN, /** * Sample offsets are computed randomly. @@ -153,19 +156,28 @@ super(args, annotations); } - + + /** + * @see Annotations#LIMIT + */ public int limit() { return getProperty(Annotations.LIMIT, Annotations.DEFAULT_LIMIT); } + /** + * @see Annotations#SEED + */ public long seed() { return getProperty(Annotations.SEED, Annotations.DEFAULT_SEED); } - + + /** + * @see Annotations#SAMPLE_TYPE + */ public SampleType getSampleType() { return SampleType.valueOf(getProperty(Annotations.SAMPLE_TYPE, Added: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Edge.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Edge.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Edge.java 2011-02-23 14:44:18 UTC (rev 4234) @@ -0,0 +1,556 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + * Created on Feb 22, 2011 + */ +package com.bigdata.bop.joinGraph.rto; + +import java.io.Serializable; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.log4j.Logger; + +import com.bigdata.bop.BOp; +import com.bigdata.bop.BOpEvaluationContext; +import com.bigdata.bop.IBindingSet; +import com.bigdata.bop.IConstraint; +import com.bigdata.bop.IPredicate; +import com.bigdata.bop.NV; +import com.bigdata.bop.PipelineOp; +import com.bigdata.bop.engine.IRunningQuery; +import com.bigdata.bop.engine.LocalChunkMessage; +import com.bigdata.bop.engine.QueryEngine; +import com.bigdata.bop.join.PipelineJoin; +import com.bigdata.bop.join.PipelineJoin.PipelineJoinStats; +import com.bigdata.relation.accesspath.ThickAsynchronousIterator; +import com.bigdata.striterator.Dechunkerator; + +/** + * An edge of the join graph is an annotated join operator. The edges of the + * join graph are undirected. Edges exist when the vertices share at least one + * variable. + * <p> + * {@link #hashCode()} is defined in terms of the unordered hash codes of the + * individual vertices. + */ +public class Edge implements Serializable { + + private static final transient Logger log = Logger.getLogger(Edge.class); + + private static final long serialVersionUID = 1L; + + /** + * The vertices connected by that edge. + */ + public final Vertex v1, v2; + + // /** + // * The set of shared variables. + // */ + // public final Set<IVariable<?>> shared; + + /** + * The last sample for this edge and <code>null</code> if the edge has not + * been sampled. + * <p> + * Note: This sample is only the one-step cutoff evaluation of the edge + * given a sample of its vertex having the lesser cardinality. It is NOT the + * cutoff sample of a join path having this edge except for the degenerate + * case where the edge is the first edge in the join path. + */ + transient EdgeSample sample = null; + + /** + * + * @param path + * The path which the edge is extending. + * @param v1 + * A vertex in that path which serves as the source of this edge. + * @param v2 + * + * FIXME EDGES : The concept of the "source" of an edge is + * actually quite misleading. This was originally an (arbitrary) + * vertex which shared a variable with the target vertex. + * However, in order to handle joins which are only indirectly + * constrained by a constraint we need to allow for a source + * vertex which does not share any variable (directly) with the + * target vertex. In addition, we also need the source path or + * the set of constraints to be attached to the edge. Finally, we + * can no longer share edges since they have to have some aspect + * of history attached. All in all, the "edge" is really just the + * last aspect of a path so what we have are ordered arrays of + * predicates and the constraints which run when each predicate + * is evaluated as part of a join. + */ + // * @param shared + public Edge(// + // final IPredicate<?>[] path, + final Vertex v1, final Vertex v2 + // , final Set<IVariable<?>> shared + ) { + if (v1 == null) + throw new IllegalArgumentException(); + if (v2 == null) + throw new IllegalArgumentException(); + // if (shared == null) + // throw new IllegalArgumentException(); + // Note: We need to allow edges which do not share variables + // if (shared.isEmpty()) + // throw new IllegalArgumentException(); + this.v1 = v1; + this.v2 = v2; + // this.shared = shared; + } + + /** + * The edge label is formed from the {@link BOp.Annotations#BOP_ID} of its + * ordered vertices (v1,v2). + */ + public String getLabel() { + + return "(" + v1.pred.getId() + "," + v2.pred.getId() + ")"; + + } + + /** + * Note: The vertices of the edge are labeled using the + * {@link BOp.Annotations#BOP_ID} associated with the {@link IPredicate} for + * each vertex. + */ + public String toString() { + + return "Edge{ " + getLabel() + ", estCard=" + + (sample == null ? "N/A" : sample.estimatedCardinality) + // + ", shared=" + shared.toString() + + + ", sample=" + sample// + + "}"; + + } + + /** + * Equality is determined by reference testing. + */ + public boolean equals(final Object o) { + + return this == o; + + } + + /** + * The hash code of an edge is the hash code of the vertex with the smaller + * hash code X 31 plus the hash code of the vertex with the larger hash + * code. This definition compensates for the arbitrary order in which the + * vertices may be expressed and also recognizes that the vertex hash codes + * are based on the bop ids, which are often small integers. + */ + public int hashCode() { + + if (hash == 0) { + + final int h1 = v1.hashCode(); + final int h2 = v2.hashCode(); + + final int h; + if (h1 < h2) { + + h = h1 * 31 + h2; + + } else { + + h = h2 * 31 + h1; + + } + + hash = h; + + } + return hash; + + } + + private int hash; + + /** + * Return the vertex with the smaller estimated cardinality. + * + * @throws IllegalStateException + * if either vertex has not been sampled. + */ + public Vertex getMinimumCardinalityVertex() { + + if (v1.sample == null) // vertex not sampled. + throw new IllegalStateException(); + + if (v2.sample == null) // vertex not sampled. + throw new IllegalStateException(); + + return (v1.sample.estimatedCardinality < v2.sample.estimatedCardinality) ? v1 : v2; + + } + + /** + * Return the vertex with the larger estimated cardinality (the vertex not + * returned by {@link #getMinimumCardinalityVertex()}). + * + * @throws IllegalStateException + * if either vertex has not been sampled. + */ + public Vertex getMaximumCardinalityVertex() { + + // The vertex with the minimum cardinality. + final Vertex o = getMinimumCardinalityVertex(); + + // Return the other vertex. + return (v1 == o) ? v2 : v1; + + } + + /** + * Estimate the cardinality of the edge, updating {@link #sample} as a + * side-effect. This is a NOP if the edge has already been sampled at that + * <i>limit</i>. This is a NOP if the edge sample is exact. + * + * @param queryEngine + * The query engine. + * @param limit + * The sample size. + * + * @return The new {@link EdgeSample} (this is also updated on + * {@link #sample} as a side-effect). + * + * @throws Exception + * + * FIXME This is actually using the source vertex as the source + * sample which is WRONG. + */ + public EdgeSample estimateCardinality(final QueryEngine queryEngine, + final int limit) throws Exception { + + if (limit <= 0) + throw new IllegalArgumentException(); + + // /* + // * Note: There is never a need to "re-sample" the edge. Unlike ROX, + // * we always can sample a vertex. This means that we can sample the + // * edges exactly once, during the initialization of the join graph. + // */ + // if (sample != null) + // throw new RuntimeException(); + + if (sample != null) { + + if (sample.limit >= limit) { + + // Already sampled at that limit. + return sample; + + } + + if (sample.estimateEnum == EstimateEnum.Exact) { + + // Sample is exact (fully materialized result). + return sample; + + } + + } + + /* + * Figure out which vertex has the smaller cardinality. The sample of + * that vertex is used since it is more representative than the sample + * of the other vertex. + * + * Note: If there are constraints which can run for this edge, then they + * will be attached when the edge is sampled. + */ + // vertex v, vprime + final Vertex v, vp; + if (v1.sample == null) // vertex not sampled. + throw new IllegalStateException(); + if (v2.sample == null) // vertex not sampled. + throw new IllegalStateException(); + if (v1.sample.estimatedCardinality < v2.sample.estimatedCardinality) { + v = v1; + vp = v2; + } else { + v = v2; + vp = v1; + } + +// /* +// * Convert the source sample into an IBindingSet[]. +// * +// * Note: This is now done when we sample the vertex. +// */ +// final IBindingSet[] sourceSample = new IBindingSet[v.sample.sample.length]; +// { +// for (int i = 0; i < sourceSample.length; i++) { +// final IBindingSet bset = new HashBindingSet(); +// BOpContext.copyValues((IElement) v.sample.sample[i], v.pred, +// bset); +// sourceSample[i] = bset; +// } +// } + + // Sample the edge and save the sample on the edge as a side-effect. + this.sample = estimateCardinality(queryEngine, limit, v, vp, + v.sample // the source sample. +// v.sample.estimatedCardinality,// +// v.sample.estimateEnum == EstimateEnum.Exact, // +// v.sample.limit,// +// v.sample.sample// + ); + + return sample; + + } + + /** + * Estimate the cardinality of the edge given a sample of either a vertex or + * a join path leading up to that edge. + * <p> + * Note: The caller is responsible for protecting against needless + * re-sampling. + * + * @param queryEngine + * The query engine. + * @param limit + * The limit for the cutoff join. + * @param vSource + * The source vertex. + * @param vTarget + * The target vertex + * @param sourceSample + * The input sample for the cutoff join. When this is a one-step + * estimation of the cardinality of the edge, then this sample is + * taken from the {@link VertexSample}. When the edge (vSource, + * vTarget) extends some {@link Path}, then this is taken from + * the {@link EdgeSample} for that {@link Path}. + * + * @return The result of sampling that edge. + * + * @throws Exception + */ + // * @param path The path which is being extended. + public EdgeSample estimateCardinality(// + final QueryEngine queryEngine,// + final int limit,// + // final IPredicate<?>[] path,// + final Vertex vSource,// + final Vertex vTarget,// + final SampleBase sourceSample// +// final long sourceEstimatedCardinality,// +// final boolean sourceSampleExact,// +// final int sourceSampleLimit,// +// final IBindingSet[] sourceSample// + ) throws Exception { + + if (limit <= 0) + throw new IllegalArgumentException(); + + /* + * Note: This sets up a cutoff pipeline join operator which makes an + * accurate estimate of the #of input solutions consumed and the #of + * output solutions generated. From that, we can directly compute the + * join hit ratio. This approach is preferred to injecting a "RowId" + * column as the estimates are taken based on internal counters in the + * join operator and the join operator knows how to cutoff evaluation as + * soon as the limit is satisfied, thus avoiding unnecessary effort. + */ + /* + * The set of constraint(s) (if any) which will be applied when we + * perform the cutoff evaluation of this edge (aka join). + * + * FIXME CONSTRAINTS - we need the join path to decide which constraints + * will be attached when we sample this edge (or at least the set of + * variables which are already known to be bound). + */ + final IConstraint[] constraints = null; + final int joinId = 1; + final Map<String, Object> anns = NV.asMap( + // + new NV(BOp.Annotations.BOP_ID, joinId),// + // @todo Why not use a factory which avoids bopIds + // already in use? + new NV(PipelineJoin.Annotations.PREDICATE, vTarget.pred.setBOpId(3)), + // Note: does not matter since not executed by the query + // controller. + // // disallow parallel evaluation of tasks + // new NV(PipelineOp.Annotations.MAX_PARALLEL,1), + // disallow parallel evaluation of chunks. + new NV(PipelineJoin.Annotations.MAX_PARALLEL_CHUNKS, 0), + // disable access path coalescing + new NV( PipelineJoin.Annotations.COALESCE_DUPLICATE_ACCESS_PATHS, false), // + // pass in constraints on this join. + new NV(PipelineJoin.Annotations.CONSTRAINTS, constraints),// + // cutoff join. + new NV(PipelineJoin.Annotations.LIMIT, (long) limit), + /* + * Note: In order to have an accurate estimate of the + * join hit ratio we need to make sure that the join + * operator runs using a single PipelineJoinStats + * instance which will be visible to us when the query + * is cutoff. In turn, this implies that the join must + * be evaluated on the query controller. + * + * @todo This implies that sampling of scale-out joins + * must be done using remote access paths. + */ + new NV(PipelineJoin.Annotations.SHARED_STATE, true),// + new NV(PipelineJoin.Annotations.EVALUATION_CONTEXT, + BOpEvaluationContext.CONTROLLER)// + ); + + @SuppressWarnings("unchecked") + final PipelineJoin<?> joinOp = new PipelineJoin(new BOp[] {}, anns); + + final PipelineOp queryOp = joinOp; + + // run the cutoff sampling of the edge. + final UUID queryId = UUID.randomUUID(); + final IRunningQuery runningQuery = queryEngine.eval(queryId, queryOp, + new LocalChunkMessage<IBindingSet>(queryEngine, queryId, joinOp + .getId()/* startId */, -1 /* partitionId */, + new ThickAsynchronousIterator<IBindingSet[]>( + new IBindingSet[][] { sourceSample.sample }))); + + final List<IBindingSet> result = new LinkedList<IBindingSet>(); + try { + try { + IBindingSet bset = null; + // Figure out the #of source samples consumed. + final Iterator<IBindingSet> itr = new Dechunkerator<IBindingSet>( + runningQuery.iterator()); + while (itr.hasNext()) { + bset = itr.next(); + result.add(bset); + } + } finally { + // verify no problems. + runningQuery.get(); + } + } finally { + runningQuery.cancel(true/* mayInterruptIfRunning */); + } + + // The join hit ratio can be computed directly from these stats. + final PipelineJoinStats joinStats = (PipelineJoinStats) runningQuery + .getStats().get(joinId); + + if (log.isTraceEnabled()) + log.trace(joinStats.toString()); + + // #of solutions in. + final int inputCount = (int) joinStats.inputSolutions.get(); + + // #of solutions out. + long outputCount = joinStats.outputSolutions.get(); + + // cumulative range count of the sampled access paths. + final long sumRangeCount = joinStats.accessPathRangeCount.get(); + + final EstimateEnum estimateEnum; + if (sourceSample.estimateEnum == EstimateEnum.Exact + && outputCount < limit) { + /* + * Note: If the entire source vertex is being fed into the cutoff + * join and the cutoff join outputCount is LT the limit, then the + * sample is the actual result of the join. That is, feeding all + * source solutions into the join gives fewer than the desired + * number of output solutions. + */ + estimateEnum = EstimateEnum.Exact; + } else if (inputCount == 1 && outputCount == limit) { + /* + * If the inputCount is ONE (1) and the outputCount is the limit, + * then the estimated cardinality is a lower bound as more than + * outputCount solutions might be produced by the join when + * presented with a single input solution. + * + * However, this condition suggests that the sum of the sampled + * range counts is a much better estimate of the cardinality of this + * join. + * + * For example, consider a join feeding a rangeCount of 16 into a + * rangeCount of 175000. With a limit of 100, we estimated the + * cardinality at 1600L (lower bound). In fact, the cardinality is + * 16*175000. This falsely low estimate can cause solutions which + * are really better to be dropped. + */ + // replace outputCount with the sum of the sampled range counts. + outputCount = sumRangeCount; + estimateEnum = EstimateEnum.LowerBound; + } else if (!(sourceSample.estimateEnum != EstimateEnum.Exact) + && inputCount == Math.min(sourceSample.limit, + sourceSample.estimatedCardinality) && outputCount == 0) { + /* + * When the source sample was not exact, the inputCount is EQ to the + * lesser of the source range count and the source sample limit, and + * the outputCount is ZERO (0), then feeding in all source solutions + * in is not sufficient to generate any output solutions. In this + * case, the estimated join hit ratio appears to be zero. However, + * the estimation of the join hit ratio actually underflowed and the + * real join hit ratio might be a small non-negative value. A real + * zero can only be identified by executing the full join. + * + * Note: An apparent join hit ratio of zero does NOT imply that the + * join will be empty (unless the source vertex sample is actually + * the fully materialized access path - this case is covered above). + */ + estimateEnum = EstimateEnum.Underflow; + } else { + estimateEnum = EstimateEnum.Normal; + } + + final double f = outputCount == 0 ? 0 + : (outputCount / (double) inputCount); + + final long estimatedCardinality = (long) (sourceSample.estimatedCardinality * f); + + final EdgeSample edgeSample = new EdgeSample(// +// sourceSample.estimatedCardinality, // +// sourceSample.estimateEnum, // +// sourceSample.limit, // + sourceSample,// + inputCount,// + outputCount, // + f, // + // args to SampleBase + estimatedCardinality, // + limit, // + estimateEnum,// + result.toArray(new IBindingSet[result.size()])); + + if (log.isDebugEnabled()) + log.debug(getLabel() + " : newSample=" + edgeSample); + + return edgeSample; + + } + +} Property changes on: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/Edge.java ___________________________________________________________________ Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EdgeSample.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EdgeSample.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EdgeSample.java 2011-02-23 14:44:18 UTC (rev 4234) @@ -0,0 +1,174 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +package com.bigdata.bop.joinGraph.rto; + +import com.bigdata.bop.IBindingSet; + +/** + * A sample of an {@link Edge} (a join). + */ +public class EdgeSample extends SampleBase { + +// private static final transient Logger log = Logger +// .getLogger(EdgeSample.class); + +// /** +// * The estimated cardinality of the cutoff join. +// */ +// public final long estimatedCardinality; +// +// /** +// * The limit used to sample the cutoff join. +// */ +// public final int limit; +// +// /** +// * Indicates whether the estimate is exact, an upper bound, or a lower +// * bound. +// */ +// public final EstimateEnum estimateEnum; +// +// /** +// * The sample of the solutions for the join path. +// */ +// final IBindingSet[] sample; + + /** + * The source sample used to compute the cutoff join. + */ + public final SampleBase sourceSample; + +// /** +// * The estimated cardinality of the source sample. +// */ +// public final long sourceEstimatedCardinality; +// +// /** +// * The sample type for the source sample. +// */ +// public final EstimateEnum sourceEstimateEnum; +// +// /** +// * Return <code>true</code> iff the source sample is exact (because the +// * source is either a fully materialized vertex or an edge whose solutions +// * have been fully materialized). +// */ +// public boolean isSourceSampleExact() { +// +// return sourceEstimateEnum == EstimateEnum.Exact; +// +// } + + /** + * The #of binding sets out of the source sample vertex sample which were + * consumed. + */ + public final int inputCount; + + /** + * The #of binding sets generated before the join was cutoff. + * <p> + * Note: If the outputCount is zero then this is a good indicator that there + * is an error in the query such that the join will not select anything. + * This is not 100%, merely indicative. + */ + public final long outputCount; + + /** + * The ratio of the #of input samples consumed to the #of output samples + * generated (the join hit ratio or scale factor). + */ + public final double f; + + /** + * Create an object which encapsulates a sample of an edge. + * + * @param sourceSample + * The input sample. + * @param limit + * The limit used to sample the edge (this is the limit on the + * #of solutions generated by the cutoff join used when this + * sample was taken). + * @param inputCount + * The #of binding sets out of the source sample vertex sample + * which were consumed. + * @param outputCount + * The #of binding sets generated before the join was cutoff. + */ +// * @param sourceVertexSample +// * The sample for source vertex of the edge (whichever vertex has +// * the lower cardinality). + EdgeSample( + // final VertexSample sourceVertexSample, + final SampleBase sourceSample,// +// final long sourceEstimatedCardinality,// +// final EstimateEnum sourceEstimateEnum, // +// final int sourceSampleLimit,// + final int inputCount, // + final long outputCount,// + final double f, // + // args to SampleBase + final long estimatedCardinality,// + final int limit,// + final EstimateEnum estimateEnum,// + final IBindingSet[] sample// + ) { + + super(estimatedCardinality, limit, estimateEnum, sample); + + if(sourceSample == null) + throw new IllegalArgumentException(); + + this.sourceSample = sourceSample; + +// this.sourceEstimatedCardinality = sourceSample.estimatedCardinality; +// +// this.sourceEstimateEnum = sourceSample.estimateEnum; + + this.inputCount = inputCount; + + this.outputCount = outputCount; + + this.f = f; + + } + + @Override + protected void toString(final StringBuilder sb) { +// return getClass().getName() // +// + "{ estimatedCardinality=" + estimatedCardinality// +// + ", limit=" + limit // +// + ", estimateEnum=" + estimateEnum// + sb.append(", sourceEstimatedCardinality=" + sourceSample.estimatedCardinality); + sb.append(", sourceEstimateEnum=" + sourceSample.estimateEnum); + sb.append(", inputCount=" + inputCount); + sb.append(", outputCount=" + outputCount); + sb.append(", f=" + f); + // + ", estimateIsLowerBound=" + estimateIsLowerBound// + // + ", estimateIsUpperBound=" + estimateIsUpperBound// + // + ", sampleIsExactSolution=" + estimateIsExact // +// + "}"; + } + +} Property changes on: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EdgeSample.java ___________________________________________________________________ Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimateEnum.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimateEnum.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimateEnum.java 2011-02-23 14:44:18 UTC (rev 4234) @@ -0,0 +1,68 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +package com.bigdata.bop.joinGraph.rto; + +/** + * Type safe enumeration describes the edge condition (if any) for a cardinality + * estimate. + */ +public enum EstimateEnum { + /** + * An estimate, but not any of the edge conditions. + */ + Normal(" "), + /** + * The cardinality estimate is exact. + */ + Exact("E"), + /** + * The cardinality estimation is a lower bound (the actual cardinality may + * be higher than the estimated value). + * <p> + * Note: The estimated cardinality reported for a {@link #LowerBound} is the + * sum of the fast range counts for the sampled access paths. See the logic + * which handles cutoff join sampling for details on this. + */ + LowerBound("L"), + /** + * Flag is set when the cardinality estimate underflowed (false zero (0)). + */ + Underflow("U"), + ; + + private EstimateEnum(final String code) { + + this.code = code; + + } + + private final String code; + + public String getCode() { + + return code; + + } + +} Property changes on: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimateEnum.java ___________________________________________________________________ Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimatedEdgeCardinalityComparator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimatedEdgeCardinalityComparator.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimatedEdgeCardinalityComparator.java 2011-02-23 14:44:18 UTC (rev 4234) @@ -0,0 +1,62 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +package com.bigdata.bop.joinGraph.rto; + +import java.util.Comparator; + + +/** + * Places edges into order by ascending estimated cardinality. Edges which + * are not weighted are ordered to the end. + * + * TODO unit tests, including with unweighted edges. + */ +class EstimatedEdgeCardinalityComparator implements Comparator<Edge> { + + public static final transient Comparator<Edge> INSTANCE = new EstimatedEdgeCardinalityComparator(); + + // @Override + public int compare(final Edge o1, final Edge o2) { + if (o1.sample == null && o2.sample == null) { + // Neither edge is weighted. + return 0; + } + if (o1.sample == null) { + // o1 is not weighted, but o2 is. sort o1 to the end. + return 1; + } + if (o2.sample == null) { + // o2 is not weighted. sort o2 to the end. + return -1; + } + final long id1 = o1.sample.estimatedCardinality; + final long id2 = o2.sample.estimatedCardinality; + if (id1 < id2) + return -1; + if (id1 > id2) + return 1; + return 0; + } + +} Property changes on: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/EstimatedEdgeCardinalityComparator.java ___________________________________________________________________ Added: svn:keywords + Id Date Revision Author HeadURL Added: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/rto/JGraph.java 2011-02-23 14:44:18 UTC (rev 4234) @@ -0,0 +1,1937 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + * Created on Feb 22, 2011 + */ + +package com.bigdata.bop.joinGraph.rto; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Formatter; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.log4j.Logger; + +import com.bigdata.bop.BOp; +import com.bigdata.bop.BOpUtility; +import com.bigdata.bop.IConstraint; +import com.bigdata.bop.IPredicate; +import com.bigdata.bop.IVariable; +import com.bigdata.bop.ap.SampleIndex.SampleType; +import com.bigdata.bop.engine.QueryEngine; +import com.bigdata.bop.joinGraph.NoSolutionsException; +import com.bigdata.bop.joinGraph.PartitionedJoinGroup; +import com.bigdata.bop.rdf.join.DataSetJoin; + +/** + * A runtime optimizer for a join graph. The {@link JoinGraph} bears some + * similarity to ROX (Runtime Optimizer for XQuery), but has several significant + * differences: + * <ol> + * <li> + * 1. ROX starts from the minimum cardinality edge of the minimum cardinality + * vertex. The {@link JoinGraph} starts with one or more low cardinality + * vertices.</li> + * <li> + * 2. ROX always extends the last vertex added to a given join path. The + * {@link JoinGraph} extends all vertices having unexplored edges in each + * breadth first expansion.</li> + * <li> + * 3. ROX is designed to interleave operator-at-once evaluation of join path + * segments which dominate other join path segments. The {@link JoinGraph} is + * designed to prune all join paths which are known to be dominated by other + * join paths for the same set of vertices in each round and iterates until a + * join path is identified which uses all vertices and has the minimum expected + * cumulative estimated cardinality. Join paths which survive pruning are + * re-sampled as necessary in order to obtain better information about edges in + * join paths which have a low estimated cardinality in order to address a + * problem with underflow of the cardinality estimates.</li> + * </ol> + * + * TODO For join graphs with a large number of vertices we may need to constrain + * the #of vertices which are explored in parallel. This could be done by only + * branching the N lowest cardinality vertices from the already connected edges. + * Since fewer vertices are being explored in parallel, paths are more likely to + * converge onto the same set of vertices at which point we can prune the + * dominated paths. + * + * TODO Compare the cumulative expected cardinality of a join path with the + * expected cost of a join path. The latter allows us to also explore + * alternative join strategies, such as the parallel subquery versus scan and + * filter decision for named graph and default graph SPARQL queries. + * + * TODO Coalescing duplicate access paths can dramatically reduce the work + * performed by a pipelined nested index subquery. (A hash join eliminates all + * duplicate access paths using a scan and filter approach.) If we will run a + * pipeline nested index subquery join, then should the runtime query optimizer + * prefer paths with duplicate access paths? + * + * TODO How can we handle things like lexicon joins. A lexicon join is is only + * evaluated when the dynamic type of a variable binding indicates that the RDF + * Value must be materialized by a join against the ID2T index. Binding sets + * having inlined values can simply be routed around the join against the ID2T + * index. Routing around saves network IO in scale-out where otherwise we would + * route binding sets having identifiers which do not need to be materialized to + * the ID2T shards. + * + * @todo Examine the overhead of the runtime optimizer. Look at ways to prune + * its costs. For example, by pruning the search, by recognizing when the + * query is simple enough to execute directly, by recognizing when we have + * already materialized the answer to the query, etc. + * + * @todo Cumulative estimated cardinality is an estimate of the work to be done. + * However, the actual cost of a join depends on whether we will use + * nested index subquery or a hash join and the cost of that operation on + * the database. There could be counter examples where the cost of the + * hash join with a range scan using the unbound variable is LT the nested + * index subquery. For those cases, we will do the same amount of IO on + * the hash join but there will still be a lower cardinality to the join + * path since we are feeding in fewer solutions to be joined. + * + * @todo Look at the integration with the SAIL. We decorate the joins with some + * annotations. Those will have to be correctly propagated to the "edges" + * in order for edge sampling and incremental evaluation (or final + * evaluation) to work. The {@link DataSetJoin} essentially inlines one of + * its access paths. That should really be changed into an inline access + * path and a normal join operator so we can defer some of the details + * concerning the join operator annotations until we decide on the join + * path to be executed. An inline AP really implies an inline relation, + * which in turn implies that the query is a searchable context for + * query-local resources. + * <p> + * For s/o, when the AP is remote, the join evaluation context must be ANY + * and otherwise (for s/o) it must be SHARDED. + * <p> + * Since the join graph is fed the vertices (APs), it does not have access + * to the annotated joins so we need to generated appropriately annotated + * joins when sampling an edge and when evaluation a subquery. + * <p> + * One solution would be to always use the unpartitioned views of the + * indices for the runtime query optimizer, which is how we are estimating + * the range counts of the access paths right now. [Note that the static + * query optimizer ignores named and default graphs, while the runtime + * query optimizer SHOULD pay attention to these things and exploit their + * conditional selectivity for the query plan.] + * + * @todo Handle optional join graphs by first applying the runtime optimizer to + * the main join graph and obtaining a sample for the selected join path. + * That sample will then be feed into the the optional join graph in order + * to optimize the join order within the optional join graph (a join order + * which is selective in the optional join graph is better since it build + * up the #of intermediate results more slowly and hence do less work). + * <p> + * This is very much related to accepting a collection of non-empty + * binding sets when running the join graph. However, optional join graph + * should be presented in combination with the original join graph and the + * starting paths must be constrained to have the selected join path for + * the original join graph as a prefix. With this setup, the original join + * graph has been locked in to a specific join path and the sampling of + * edges and vertices for the optional join graph can proceed normally. + * <p> + * True optionals will always be appended as part of the "tail plan" for + * any join graph and can not be optimized as each optional join must run + * regardless (as long as the intermediate solution survives the + * non-optional joins). + * + * @todo There are two cases where a join graph must be optimized against a + * specific set of inputs. In one case, it is a sample (this is how + * optimization of an optional join group proceeds per above). In the + * other case, the set of inputs is fixed and is provided instead of a + * single empty binding set as the starting condition. This second case is + * actually a bit more complicated since we can not use a random sample of + * vertices unless the do not share any variables with the initial binding + * sets. When there is a shared variable, we need to do a cutoff join of + * the edge with the initial binding sets. When there is not a shared + * variable, we can sample the vertex and then do a cutoff join. + * + * @todo When we run into a cardinality estimation underflow (the expected + * cardinality goes to zero) we could double the sample size for just + * those join paths which hit a zero estimated cardinality and re-run them + * within the round. This would imply that we keep per join path limits. + * The vertex and edge samples are already aware of the limit at which + * they were last sampled so this should not cause any problems there. + * <p> + * A related option would be to deepen the samples only when we are in + * danger of cardinality estimation underflow. E.g., a per-path limit. + * Resampling vertices may only make sense when we increase the limit + * since otherwise we may find a different correlation with the new sample + * but the comparison of paths using one sample base with paths using a + * different sample base in a different round does not carry forward the + * cardinality estimates from the prior round (unless we do something like + * a weighted moving average). + * + * @todo When comparing choices among join paths having fully bound tails where + * the estimated cardinality has also gone to zero, we should prefer to + * evaluate vertices in the tail with better index locality first. For + * example, if one vertex had one variable in the original plan while + * another had two variables, then solutions which reach the 2-var vertex + * could be spread out over a much wider range of the selected index than + * those which reach the 1-var vertex. [In order to support this, we would + * need a means to indicate that a fully bound access path should use an + * index specified by the query optimizer rather than the primary index + * for the relation. In addition, this suggests that we should keep bloom + * filters for more than just the SPO(C) index in scale-out.] + * + * @todo Examine behavior when we do not have perfect covering indices. This + * will mean that some vertices can not be sampled using an index and that + * estimation of their cardinality will have to await the estimation of + * the cardinality of the edge(s) leading to that vertex. Still, the + * approach should be able to handle queries without perfect / covering + * automatically. Then experiment with carrying fewer statement indices + * for quads. + * + * @todo Unit test when there are no solutions to the query. In this case there + * will be no paths identified by the optimizer and the final path length + * becomes zero. + * + * @see <a + * href="http://www-db.informatik.uni-tuebingen.de/files/research/pathfinder/publications/rox-demo.pdf"> + * ROX </a> + */ +public class JGraph { + + private static final transient Logger log = Logger.getLogger(JGraph.class); + + /** + * Vertices of the join graph. + */ + private final Vertex[] V; + + /** + * Constraints on the join graph. A constraint is applied once all + * variables referenced by a constraint are known to be bound. + */ + private final IConstraint[] C; + + /** + * The kind of samples that will be taken when we sample a {@link Vertex}. + */ + private final SampleType sampleType; + + /** + * The edges of the join graph as determined by static analysis. Each + * edge is basically a possible join. This array is comprised of just + * those edges which are determined by static analysis. Additional edges + * MAY be identified dynamically. Altogether there are three categories + * of edges: + * <ol> + * <li>The vertices directly share variables (join with shared + * variable(s)). These edges are identified by static analysis in the + * constructor are are represented in {@link #E}.</li> + * <li>The vertices indirectly share variables via a constraint (join + * with indirectly shared variable(s)). These edges are identified by + * dynamic analysis. Each time we expand the set of join paths under + * consideration, we examine {@link #unshared} vertices. Given the join + * path under consideration and the set of constraints, it may be that + * the vertex will indirectly share a variable via a constraint and can + * therefore participate in a constrained join.</li> + * <li>The vertices do not share variables, either directly or + * indirectly (unconstrained join). All vertices can join. However, if + * there are no shared variables then the join is unconstrained (full + * cross product). These edges are identified dynamically. In each round + * for which a constrained edge could not be identified, we consider all + * vertices in {@link #unshared} and choose an unconstrained edge.</li> + * </ol> + * + * @see BOpUtility#canJoinUsingConstraints(IPredicate[], IPredicate, IConstraint[]) + */ + private final Edge[] E; + + /** + * An unordered collection of vertices which do not share any variables + * with the other vertices in the join graph. These vertices will + * produce full cross product joins unless a constraint causes indirect + * sharing of variables with a join path. + */ + private final Vertex[] unshared; + + public List<Vertex> getVertices() { + return Collections.unmodifiableList(Arrays.asList(V)); + } + + public List<Edge> getEdges() { + return Collections.unmodifiableList(Arrays.asList(E)); + } + + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("JoinGraph"); + sb.append("{V=["); + for (Vertex v : V) { + sb.append("\nV[" + v.pred.getId() + "]=" + v); + } + sb.append("{C=["); + for (IConstraint c : C) { + sb.append("\nC[" + c.getId() + "]=" + c); + } + sb.append("\n],unshared=["); + for (Vertex v : unshared) { + sb.append("\n" + v); + } + sb.append("],E=["); + for (Edge e : E) { + sb.append("\n" + e); + } + sb.append("\n]}"); + return sb.toString(); + } + + /** + * + * @param v + * The vertices of the join graph. These are + * {@link IPredicate}s associated with required joins. + * @param constraints + * The constraints of the join graph (optional). Since all + * joins in the join graph are required, constraints are + * dynamically attached to the first join in which all of + * their variables are bound. + * + * @throws IllegalArgumentException + * if the vertices is <code>null</code>. + * @throws IllegalArgumentException + * if the vertices is an empty array. + * @throws IllegalArgumentException + * if any element of the vertices is <code>null</code>. + * @throws IllegalArgumentException + * if any constraint uses a variable which is never bound by + * the given predicates. + * @throws IllegalArgumentException + * if <i>sampleType</i> is <code>null</code>. + * + * @todo unit test for a constraint using a variable which is never + * bound. + */ + public JGraph(final IPredicate<?>[] v, final IConstraint[] constraints, + final SampleType sampleType) { + + if (v == null) + throw new IllegalArgumentException(); + + if (v.length < 2) + throw new IllegalArgumentException(); + + V = new Vertex[v.length]; + + for (int i = 0; i < v.length; i++) { + + if (v[i] == null) + throw new IllegalArgumentException(); + + V[i] = new Vertex(v[i]); + + } + + if (constraints != null) { + C = new IConstraint[constraints.length]; + for (int i = 0; i < constraints.length; i++) { + if (constraints[i] == null) + throw new IllegalArgumentException(); + C[i] = constraints[i]; + } + } else { + // No constraints. + C = null; + } + + if (sampleType == null) + throw new IllegalArgumentException(); + + this.sampleType = sampleType; + + /* + * Create edges to represent possible joins between predicates based + * on directly shared variables - these joins can be identified by a + * static analysis of the join graph. + * + * Note: There are really three classes of joins to be considered. + * + * (1) The target predicate directly shares a variable with the + * source predicate. These joins are always constrained since the + * source predicate will have bound that variable. This is the + * static analysis of the join graph. + * + * (2) When the source predicate shares a variable with a constraint + * which also shares a variable with the target predicate. While the + * predicates do not directly share a variable, these joins are + * constrained by the shared variable in the constraint on the + * target predicate. BSBM Q5 is an example of this case. We do not + * create edges for such joins here. Instead, we dynamically + * determine when a constrained join is possible when extending the + * join path in each round. Hence, this is part of the dynamic + * analysis of the join graph. + * + * (3) Any two predicates may always be joined. However, joins which + * do not share variables either directly or indirectly will be full + * cross products. Therefore such joins are run last and we do not + * create edges for them here. Again, this is part of the dynamic + * analysis of the join graph. + */ + { + + // The set of identified edges for vertices which share vars. + final List<Edge> tmp = new LinkedList<Edge>(); + + // The set of vertices which share variables. + final Set<Vertex> sharedEdgeVertices = new LinkedHashSet<Vertex>(); + + // The set of vertices which do not share variables. + final List<Vertex> unsharedEdgeVertices = new LinkedList<Vertex>(); + + for (int i = 0; i < v.length; i++) { + + // consider a source vertex. + final IPredicate<?> p1 = v[i]; + + // #of vertices which share a variable with source vertex. + int nmatched = 0; + + for (int j = i + 1; j < v.length; j++) { + + // consider a possible target vertex. + final IPredicate<?> p2 = v[j]; + +// final Set<IVariable<?>> shared = BOpUtility +// .getSharedVars(p1, p2); + + if(BOpUtility.canJoin(p1, p2)) { +// if (!shared.isEmpty()) { + + /* + * The source and target vertices can join based on + * one or more shared variable(s). + */ + + if (log.isDebugEnabled()) + log.debug("vertices shared variable(s): vars=" + + BOpUtility.getSharedVars(p1, p2) + + ", v1=" + p1 + ", v2=" + p2); + + tmp.add(new Edge(V[i], V[j]));//, shared)); + + sharedEdgeVertices.add(V[i]); + + sharedEdgeVertices.add(V[j]); + + nmatched++; + + } else if (constraints != null) { + + /* + * ... [truncated message content] |
From: <tho...@us...> - 2011-02-23 13:44:03
|
Revision: 4233 http://bigdata.svn.sourceforge.net/bigdata/?rev=4233&view=rev Author: thompsonbry Date: 2011-02-23 13:43:56 +0000 (Wed, 23 Feb 2011) Log Message: ----------- Reconciled. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/fast/TestDefaultEvaluationPlan.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/util/TestBOpUtility_canJoinUsingConstraints.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/fast/TestDefaultEvaluationPlan.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/fast/TestDefaultEvaluationPlan.java 2011-02-23 00:48:43 UTC (rev 4232) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/fast/TestDefaultEvaluationPlan.java 2011-02-23 13:43:56 UTC (rev 4233) @@ -101,8 +101,6 @@ * Per {@link IEvaluationPlanFactory} * @param rule * {@link IEvaluationPlanFactory} - * @param rangeCount - * The range count data for each predicate in the <i>rule</i>. */ final IEvaluationPlan newPlan(IJoinNexus joinNexus, final IRule rule) { @@ -274,17 +272,17 @@ final IAccessPathExpander expander = new IAccessPathExpander() { - @Override +// @Override public IAccessPath getAccessPath(IAccessPath accessPath) { throw new UnsupportedOperationException(); } - @Override +// @Override public boolean backchain() { return false; } - @Override +// @Override public boolean runFirst() { return true; } Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/util/TestBOpUtility_canJoinUsingConstraints.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/util/TestBOpUtility_canJoinUsingConstraints.java 2011-02-23 00:48:43 UTC (rev 4232) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/util/TestBOpUtility_canJoinUsingConstraints.java 2011-02-23 13:43:56 UTC (rev 4233) @@ -50,7 +50,7 @@ import com.bigdata.bop.constraint.AND; import com.bigdata.bop.constraint.BooleanValueExpression; import com.bigdata.bop.constraint.Constraint; -import com.bigdata.bop.joinGraph.rto.JoinGraph.JGraph; +import com.bigdata.bop.joinGraph.rto.JGraph; /** * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mrp...@us...> - 2011-02-23 00:48:50
|
Revision: 4232 http://bigdata.svn.sourceforge.net/bigdata/?rev=4232&view=rev Author: mrpersonick Date: 2011-02-23 00:48:43 +0000 (Wed, 23 Feb 2011) Log Message: ----------- modified the static query optimizer to give preferential treatment to tails that share variables with runFirst expanders Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/fast/DefaultEvaluationPlan2.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/fast/TestDefaultEvaluationPlan.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/fast/DefaultEvaluationPlan2.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/fast/DefaultEvaluationPlan2.java 2011-02-22 23:56:05 UTC (rev 4231) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/joinGraph/fast/DefaultEvaluationPlan2.java 2011-02-23 00:48:43 UTC (rev 4232) @@ -30,10 +30,15 @@ import java.util.Arrays; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; import org.apache.log4j.Logger; + +import com.bigdata.bop.BOpUtility; import com.bigdata.bop.IPredicate; +import com.bigdata.bop.IVariable; import com.bigdata.bop.IVariableOrConstant; +import com.bigdata.bop.Var; import com.bigdata.bop.joinGraph.IEvaluationPlan; import com.bigdata.bop.joinGraph.IRangeCountFactory; import com.bigdata.journal.ITx; @@ -195,7 +200,7 @@ /** * Compute the evaluation order. */ - private void calc(IRule rule) { + private void calc(final IRule rule) { if (order != null) return; @@ -224,16 +229,28 @@ } */ + final Set<IVariable<?>> runFirstVars = new HashSet<IVariable<?>>(); + int startIndex = 0; for (int i = 0; i < tailCount; i++) { - IAccessPathExpander expander = rule.getTail(i).getAccessPathExpander(); + final IPredicate pred = rule.getTail(i); + final IAccessPathExpander expander = pred.getAccessPathExpander(); if (expander != null && expander.runFirst()) { if (DEBUG) log.debug("found a run first, tail " + i); + final Iterator<IVariable<?>> it = BOpUtility.getArgumentVariables(pred); + while (it.hasNext()) { + runFirstVars.add(it.next()); + } order[startIndex++] = i; used[i] = true; } } + // if there are no more tails left after the expanders, we're done + if (startIndex == tailCount) { + return; + } + // if there is only one tail left after the expanders if (startIndex == tailCount-1) { if (DEBUG) log.debug("one tail left"); @@ -248,6 +265,25 @@ } } + int preferredFirstTail = -1; + // give preferential treatment to a tail that shares variables with the + // runFirst expanders + for (int i = 0; i < tailCount; i++) { + // only check unused tails + if (used[i]) { + continue; + } + final IPredicate pred = rule.getTail(i); + final Iterator<IVariable<?>> it = BOpUtility.getArgumentVariables(pred); + while (it.hasNext()) { + if (runFirstVars.contains(it.next())) { + preferredFirstTail = i; + } + } + if (preferredFirstTail != -1) + break; + } + // if there are only two tails left after the expanders if (startIndex == tailCount-2) { if (DEBUG) log.debug("two tails left"); @@ -267,8 +303,13 @@ } } if (DEBUG) log.debug(t1 + ", " + t2); - order[tailCount-2] = cardinality(t1) <= cardinality(t2) ? t1 : t2; - order[tailCount-1] = cardinality(t1) <= cardinality(t2) ? t2 : t1; + if (preferredFirstTail != -1) { + order[tailCount-2] = preferredFirstTail; + order[tailCount-1] = preferredFirstTail == t1 ? t2 : t1; + } else { + order[tailCount-2] = cardinality(t1) <= cardinality(t2) ? t1 : t2; + order[tailCount-1] = cardinality(t1) <= cardinality(t2) ? t2 : t1; + } return; } @@ -276,11 +317,16 @@ * There will be (tails-1) joins, we just need to figure out what * they should be. */ - Join join = getFirstJoin(); + Join join = preferredFirstTail == -1 ? getFirstJoin() : getFirstJoin(preferredFirstTail); int t1 = ((Tail) join.getD1()).getTail(); int t2 = ((Tail) join.getD2()).getTail(); - order[startIndex] = cardinality(t1) <= cardinality(t2) ? t1 : t2; - order[startIndex+1] = cardinality(t1) <= cardinality(t2) ? t2 : t1; + if (preferredFirstTail == -1) { + order[startIndex] = cardinality(t1) <= cardinality(t2) ? t1 : t2; + order[startIndex+1] = cardinality(t1) <= cardinality(t2) ? t2 : t1; + } else { + order[startIndex] = t1; + order[startIndex+1] = t2; + } used[order[startIndex]] = true; used[order[startIndex+1]] = true; for (int i = startIndex+2; i < tailCount; i++) { @@ -359,6 +405,48 @@ return new Join(minT1, minT2, minJoinCardinality, vars); } + private Join getFirstJoin(final int preferredFirstTail) { + if (DEBUG) { + log.debug("evaluating first join"); + } + + + long minJoinCardinality = Long.MAX_VALUE; + long minOtherTailCardinality = Long.MAX_VALUE; + Tail minT2 = null; + final int i = preferredFirstTail; + final Tail t1 = new Tail(i, rangeCount(i), getVars(i)); + for (int j = 0; j < tailCount; j++) { + // check only non-same and unused tails + if (i == j || used[j]) { + continue; + } + Tail t2 = new Tail(j, rangeCount(j), getVars(j)); + long t2Cardinality = cardinality(j); + long joinCardinality = computeJoinCardinality(t1, t2); + if(DEBUG) log.debug("evaluating " + i + " X " + j + ": cardinality= " + joinCardinality); + if (joinCardinality < minJoinCardinality) { + if(DEBUG) log.debug("found a new min: " + joinCardinality); + minJoinCardinality = joinCardinality; + minOtherTailCardinality = t2Cardinality; + minT2 = t2; + } else if (joinCardinality == minJoinCardinality) { + if (t2Cardinality < minOtherTailCardinality) { + if(DEBUG) log.debug("found a new min: " + joinCardinality); + minJoinCardinality = joinCardinality; + minOtherTailCardinality = t2Cardinality; + minT2 = t2; + } + } + } + + // the join variables is the union of the join dimensions' variables + Set<String> vars = new HashSet<String>(); + vars.addAll(t1.getVars()); + vars.addAll(minT2.getVars()); + return new Join(t1, minT2, minJoinCardinality, vars); + } + /** * Similar to {@link #getFirstJoin()}, but we have one join dimension * already calculated. Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/fast/TestDefaultEvaluationPlan.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/fast/TestDefaultEvaluationPlan.java 2011-02-22 23:56:05 UTC (rev 4231) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/fast/TestDefaultEvaluationPlan.java 2011-02-23 00:48:43 UTC (rev 4232) @@ -40,15 +40,14 @@ import com.bigdata.bop.IConstant; import com.bigdata.bop.IConstraint; import com.bigdata.bop.IPredicate; +import com.bigdata.bop.IPredicate.Annotations; import com.bigdata.bop.IVariableOrConstant; import com.bigdata.bop.NV; import com.bigdata.bop.Var; -import com.bigdata.bop.IPredicate.Annotations; import com.bigdata.bop.ap.Predicate; import com.bigdata.bop.joinGraph.IEvaluationPlan; import com.bigdata.bop.joinGraph.IEvaluationPlanFactory; import com.bigdata.bop.joinGraph.IRangeCountFactory; -import com.bigdata.bop.joinGraph.fast.DefaultEvaluationPlan2; import com.bigdata.btree.keys.ISortKeyBuilder; import com.bigdata.config.IValidator; import com.bigdata.io.IStreamSerializer; @@ -61,6 +60,7 @@ import com.bigdata.relation.accesspath.IBlockingBuffer; import com.bigdata.relation.accesspath.IBuffer; import com.bigdata.relation.accesspath.IElementFilter; +import com.bigdata.relation.rule.IAccessPathExpander; import com.bigdata.relation.rule.IRule; import com.bigdata.relation.rule.IStep; import com.bigdata.relation.rule.Rule; @@ -252,7 +252,120 @@ // fail("write test"); // // } + + + public void testRunFirstExpanders() { + + final String relation = "spo"; + final long timestamp = ITx.READ_COMMITTED; + /* + * ?l search Mike + * ?s ?p ?l + * ?s type Person + * ?p type Property + */ + + final Constant<?> search = new Constant<String>("search"); + final Constant<?> Mike = new Constant<String>("Mike"); + final Constant<?> type = new Constant<String>("type"); + final Constant<?> Person = new Constant<String>("Person"); + final Constant<?> Property = new Constant<String>("Property"); + + final IAccessPathExpander expander = new IAccessPathExpander() { + + @Override + public IAccessPath getAccessPath(IAccessPath accessPath) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean backchain() { + return false; + } + + @Override + public boolean runFirst() { + return true; + } + + }; + + final IPredicate<?> pred0 = new Predicate(// + new IVariableOrConstant[] {// + Var.var("l"), search, Mike },// + new NV(Predicate.Annotations.RELATION_NAME, + new String[] { relation }),// + new NV(Annotations.TIMESTAMP,timestamp),// + new NV(Predicate.Annotations.ACCESS_PATH_EXPANDER, expander) + ); + + final IPredicate<?> pred1 = new Predicate(// + new IVariableOrConstant[] {// + Var.var("s"), Var.var("p"), Var.var("l") },// + new NV(Predicate.Annotations.RELATION_NAME, + new String[] { relation }),// + new NV(Annotations.TIMESTAMP,timestamp)// + ); + + final IPredicate<?> pred2 = new Predicate( // + new IVariableOrConstant[] {// + Var.var("s"), type, Person },// + new NV(Predicate.Annotations.RELATION_NAME, + new String[] { relation }),// + new NV(Annotations.TIMESTAMP,timestamp)// + ); + + final IPredicate<?> pred3 = new Predicate( // + new IVariableOrConstant[] {// + Var.var("p"), type, Property },// + new NV(Predicate.Annotations.RELATION_NAME, + new String[] { relation }),// + new NV(Annotations.TIMESTAMP,timestamp)// + ); + + final IRule rule = new Rule(getName(), null/* head */, + new IPredicate[] { pred0, pred1, pred2, pred3 }, // + null// constraints + ); + + final Map<IPredicate,Long> rangeCount = new HashMap<IPredicate,Long>(); + { + rangeCount.put(pred0, 0L); + rangeCount.put(pred1, 1000000L); + rangeCount.put(pred2, 10000L); + rangeCount.put(pred3, 100L); + } + + final IEvaluationPlan plan = newPlan(new MockJoinNexus( + new MockRangeCountFactory(rangeCount)), rule); + + assertFalse(plan.isEmpty()); + + final int[] expected = new int[] { 0, 1, 3, 2 }; + + final int[] actual = plan.getOrder(); + + if (!Arrays.equals(expected, actual)) + fail("evaluation order: expected=" + Arrays.toString(expected) + + ", actual=" + Arrays.toString(actual)); + +// assertFalse("isFullyBound(0)", plan.isFullyBound(0)); +// assertTrue( "isFullyBound(1)", plan.isFullyBound(1)); +// assertFalse("isFullyBound(2)", plan.isFullyBound(2)); +// assertTrue( "isFullyBound(3)", plan.isFullyBound(3)); +// assertFalse("isFullyBound(4)", plan.isFullyBound(4)); +// +// assertEquals("getVarCount(0)", 1, plan.getVariableCount(0)); +// assertEquals("getVarCount(1)", 0, plan.getVariableCount(1)); +// assertEquals("getVarCount(2)", 1, plan.getVariableCount(2)); +// assertEquals("getVarCount(3)", 0, plan.getVariableCount(3)); +// assertEquals("getVarCount(4)", 1, plan.getVariableCount(4)); + + } + + + /** * Mock object. * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mrp...@us...> - 2011-02-22 23:56:12
|
Revision: 4231 http://bigdata.svn.sourceforge.net/bigdata/?rev=4231&view=rev Author: mrpersonick Date: 2011-02-22 23:56:05 +0000 (Tue, 22 Feb 2011) Log Message: ----------- testing rdf and and or semantics Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/AndBOp.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/OrBOp.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/constraints/TestInlineConstraints.java Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/AndBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/AndBOp.java 2011-02-22 23:40:52 UTC (rev 4230) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/AndBOp.java 2011-02-22 23:56:05 UTC (rev 4231) @@ -105,7 +105,7 @@ } - public IV get(final IBindingSet bs) { + public XSDBooleanIV get(final IBindingSet bs) { return accept(bs) ? XSDBooleanIV.TRUE : XSDBooleanIV.FALSE; Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/OrBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/OrBOp.java 2011-02-22 23:40:52 UTC (rev 4230) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/OrBOp.java 2011-02-22 23:56:05 UTC (rev 4231) @@ -105,7 +105,7 @@ } - public IV get(final IBindingSet bs) { + public XSDBooleanIV get(final IBindingSet bs) { return accept(bs) ? XSDBooleanIV.TRUE : XSDBooleanIV.FALSE; Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/constraints/TestInlineConstraints.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/constraints/TestInlineConstraints.java 2011-02-22 23:40:52 UTC (rev 4230) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/constraints/TestInlineConstraints.java 2011-02-22 23:56:05 UTC (rev 4231) @@ -48,12 +48,14 @@ import com.bigdata.bop.IConstant; import com.bigdata.bop.IConstraint; import com.bigdata.bop.IPredicate; +import com.bigdata.bop.IValueExpression; import com.bigdata.bop.IVariable; import com.bigdata.bop.IVariableOrConstant; import com.bigdata.bop.NV; import com.bigdata.bop.PipelineOp; import com.bigdata.bop.Var; import com.bigdata.bop.IPredicate.Annotations; +import com.bigdata.bop.bindingSet.HashBindingSet; import com.bigdata.bop.engine.IRunningQuery; import com.bigdata.bop.engine.QueryEngine; import com.bigdata.bop.fed.QueryEngineFactory; @@ -61,8 +63,10 @@ import com.bigdata.bop.joinGraph.IEvaluationPlanFactory; import com.bigdata.bop.joinGraph.fast.DefaultEvaluationPlanFactory2; import com.bigdata.btree.IRangeQuery; +import com.bigdata.rdf.error.SparqlTypeErrorException; import com.bigdata.rdf.internal.IV; import com.bigdata.rdf.internal.IVUtility; +import com.bigdata.rdf.internal.XSDBooleanIV; import com.bigdata.rdf.model.BigdataLiteral; import com.bigdata.rdf.model.BigdataURI; import com.bigdata.rdf.model.BigdataValue; @@ -796,6 +800,164 @@ } } + + public void testAnd() { + + final IValueExpression<IV> T = new ValueExpressionBOp(new BOp[] { }, null/*anns*/) { + public IV get(IBindingSet bindingSet) { + return XSDBooleanIV.TRUE; + } + }; + + final IValueExpression<IV> F = new ValueExpressionBOp(new BOp[] { }, null/*anns*/) { + public IV get(IBindingSet bindingSet) { + return XSDBooleanIV.FALSE; + } + }; + + final IValueExpression<IV> E = new ValueExpressionBOp(new BOp[] { }, null/*anns*/) { + public IV get(IBindingSet bindingSet) { + throw new SparqlTypeErrorException(); + } + }; + + final IBindingSet bs = new HashBindingSet(); + + { + final AndBOp and = new AndBOp(T, T); + final XSDBooleanIV iv = and.get(bs); + assertTrue(iv.booleanValue()); + } + { + final AndBOp and = new AndBOp(T, F); + final XSDBooleanIV iv = and.get(bs); + assertFalse(iv.booleanValue()); + } + { + final AndBOp and = new AndBOp(F, T); + final XSDBooleanIV iv = and.get(bs); + assertFalse(iv.booleanValue()); + } + { + final AndBOp and = new AndBOp(F, F); + final XSDBooleanIV iv = and.get(bs); + assertFalse(iv.booleanValue()); + } + { + final AndBOp and = new AndBOp(T, E); + try { + and.get(bs); + //should produce a type error + assertTrue(false); + } catch (SparqlTypeErrorException ex) { } + } + { + final AndBOp and = new AndBOp(E, T); + try { + and.get(bs); + //should produce a type error + assertTrue(false); + } catch (SparqlTypeErrorException ex) { } + } + { + final AndBOp and = new AndBOp(E, F); + final XSDBooleanIV iv = and.get(bs); + assertFalse(iv.booleanValue()); + } + { + final AndBOp and = new AndBOp(F, E); + final XSDBooleanIV iv = and.get(bs); + assertFalse(iv.booleanValue()); + } + { + final AndBOp and = new AndBOp(E, E); + try { + and.get(bs); + //should produce a type error + assertTrue(false); + } catch (SparqlTypeErrorException ex) { } + } + + } + + public void testOr() { + + final IValueExpression<IV> T = new ValueExpressionBOp(new BOp[] { }, null/*anns*/) { + public IV get(IBindingSet bindingSet) { + return XSDBooleanIV.TRUE; + } + }; + + final IValueExpression<IV> F = new ValueExpressionBOp(new BOp[] { }, null/*anns*/) { + public IV get(IBindingSet bindingSet) { + return XSDBooleanIV.FALSE; + } + }; + + final IValueExpression<IV> E = new ValueExpressionBOp(new BOp[] { }, null/*anns*/) { + public IV get(IBindingSet bindingSet) { + throw new SparqlTypeErrorException(); + } + }; + + final IBindingSet bs = new HashBindingSet(); + + { + final OrBOp or = new OrBOp(T, T); + final XSDBooleanIV iv = or.get(bs); + assertTrue(iv.booleanValue()); + } + { + final OrBOp or = new OrBOp(T, F); + final XSDBooleanIV iv = or.get(bs); + assertTrue(iv.booleanValue()); + } + { + final OrBOp or = new OrBOp(F, T); + final XSDBooleanIV iv = or.get(bs); + assertTrue(iv.booleanValue()); + } + { + final OrBOp or = new OrBOp(F, F); + final XSDBooleanIV iv = or.get(bs); + assertFalse(iv.booleanValue()); + } + { + final OrBOp or = new OrBOp(E, T); + final XSDBooleanIV iv = or.get(bs); + assertTrue(iv.booleanValue()); + } + { + final OrBOp or = new OrBOp(T, E); + final XSDBooleanIV iv = or.get(bs); + assertTrue(iv.booleanValue()); + } + { + final OrBOp or = new OrBOp(F, E); + try { + or.get(bs); + //should produce a type error + assertTrue(false); + } catch (SparqlTypeErrorException ex) { } + } + { + final OrBOp or = new OrBOp(E, F); + try { + or.get(bs); + //should produce a type error + assertTrue(false); + } catch (SparqlTypeErrorException ex) { } + } + { + final OrBOp or = new OrBOp(E, E); + try { + or.get(bs); + //should produce a type error + assertTrue(false); + } catch (SparqlTypeErrorException ex) { } + } + + } // private IChunkedOrderedIterator<ISolution> runQuery(AbstractTripleStore db, IRule rule) // throws Exception { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mrp...@us...> - 2011-02-22 23:40:59
|
Revision: 4230 http://bigdata.svn.sourceforge.net/bigdata/?rev=4230&view=rev Author: mrpersonick Date: 2011-02-22 23:40:52 +0000 (Tue, 22 Feb 2011) Log Message: ----------- refactor constraints -> value expressions Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/TestBOpUtility.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/constraints/TestInlineConstraints.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/rules/TestRuleExpansion.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/spo/TestSPORelation.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/TestBOpUtility.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/TestBOpUtility.java 2011-02-22 23:39:14 UTC (rev 4229) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/TestBOpUtility.java 2011-02-22 23:40:52 UTC (rev 4230) @@ -32,16 +32,30 @@ import junit.framework.TestCase2; +import org.openrdf.model.Literal; +import org.openrdf.model.URI; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.vocabulary.RDF; +import org.openrdf.model.vocabulary.RDFS; +import org.openrdf.query.QueryLanguage; +import org.openrdf.query.TupleQuery; +import org.openrdf.query.TupleQueryResult; +import org.openrdf.repository.Repository; +import org.openrdf.repository.RepositoryConnection; +import org.openrdf.repository.sail.SailRepository; +import org.openrdf.sail.Sail; +import org.openrdf.sail.memory.MemoryStore; + import com.bigdata.bop.BOp; -import com.bigdata.bop.BOpBase; import com.bigdata.bop.BOpUtility; import com.bigdata.bop.Constant; import com.bigdata.bop.IBindingSet; -import com.bigdata.bop.IConstraint; import com.bigdata.bop.IValueExpression; import com.bigdata.bop.Var; -import com.bigdata.bop.constraint.BOpConstraint; -import com.bigdata.bop.constraint.OR; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.constraints.OrBOp; +import com.bigdata.rdf.internal.constraints.ValueExpressionBOp; +import com.bigdata.rdf.store.BD; /** * Unit tests for {@link BOpUtility}. @@ -76,18 +90,18 @@ private BOp generateBOp(final int count,final IValueExpression<?> a) { - IConstraint bop = null; + IValueExpression bop = null; for (int i = 0; i < count; i++) { - final IConstraint c = new DummyConstraint( + final IValueExpression c = new DummyVE( new BOp[] { a, new Constant<Integer>(i) }, null/*annotations*/); if (bop == null) { bop = c; } else { - bop = new OR(c, bop); + bop = new OrBOp(c, bop); } } @@ -132,24 +146,66 @@ } - private static class DummyConstraint extends BOpConstraint { + private static class DummyVE extends ValueExpressionBOp { /** * */ private static final long serialVersionUID = 1942393209821562541L; - public DummyConstraint(BOp[] args, Map<String, Object> annotations) { + public DummyVE(BOp[] args, Map<String, Object> annotations) { super(args, annotations); } - public DummyConstraint(BOpBase op) { + public DummyVE(ValueExpressionBOp op) { super(op); } - public boolean accept(IBindingSet bindingSet) { + public IV get(IBindingSet bindingSet) { throw new RuntimeException(); } } + + public void testOpenWorldEq() throws Exception { + + final Sail sail = new MemoryStore(); + final Repository repo = new SailRepository(sail); + repo.initialize(); + final RepositoryConnection cxn = repo.getConnection(); + + try { + + final ValueFactory vf = sail.getValueFactory(); + + final URI mike = vf.createURI(BD.NAMESPACE + "mike"); + final URI age = vf.createURI(BD.NAMESPACE + "age"); + final Literal mikeAge = vf.createLiteral(34); + + cxn.add(vf.createStatement(mike, RDF.TYPE, RDFS.RESOURCE)); + cxn.add(vf.createStatement(mike, age, mikeAge)); + + final String query = + "select * " + + "where { " + + " ?s ?p ?o . " + + " filter (?o < 40) " + + "}"; + + final TupleQuery tupleQuery = + cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); + + final TupleQueryResult result = tupleQuery.evaluate(); + while (result.hasNext()) { + System.err.println(result.next()); + } + + + } finally { + cxn.close(); + repo.shutDown(); + } + + + } } Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java 2011-02-22 23:39:14 UTC (rev 4229) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java 2011-02-22 23:40:52 UTC (rev 4230) @@ -27,7 +27,7 @@ import com.bigdata.rdf.internal.constraints.MathBOp; import com.bigdata.rdf.internal.constraints.NotBOp; import com.bigdata.rdf.internal.constraints.SameTermBOp; -import com.bigdata.rdf.internal.constraints.ValueExpressionConstraint; +import com.bigdata.rdf.internal.constraints.Constraint; import com.bigdata.rdf.model.BigdataURI; import com.bigdata.rdf.model.BigdataValue; import com.bigdata.rdf.model.BigdataValueFactory; @@ -438,7 +438,7 @@ // the constraints on the join graph. constraints = new IConstraint[ves.length]; for (int i = 0; i < ves.length; i++) { - constraints[i] = ValueExpressionConstraint.wrap(ves[i]); + constraints[i] = Constraint.wrap(ves[i]); } } Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/constraints/TestInlineConstraints.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/constraints/TestInlineConstraints.java 2011-02-22 23:39:14 UTC (rev 4229) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/constraints/TestInlineConstraints.java 2011-02-22 23:40:52 UTC (rev 4230) @@ -180,7 +180,7 @@ }, // constraints on the rule. new IConstraint[] { - ValueExpressionConstraint.wrap(new CompareBOp(a, new Constant<IV>(_35.getIV()), CompareOp.GT)) + Constraint.wrap(new CompareBOp(a, new Constant<IV>(_35.getIV()), CompareOp.GT)) } ); @@ -286,7 +286,7 @@ }, // constraints on the rule. new IConstraint[] { - ValueExpressionConstraint.wrap(new CompareBOp(a, new Constant<IV>(_35.getIV()), CompareOp.GE)) + Constraint.wrap(new CompareBOp(a, new Constant<IV>(_35.getIV()), CompareOp.GE)) }); try { @@ -393,7 +393,7 @@ }, // constraints on the rule. new IConstraint[] { - ValueExpressionConstraint.wrap(new CompareBOp(a, new Constant<IV>(_35.getIV()), CompareOp.LT)) + Constraint.wrap(new CompareBOp(a, new Constant<IV>(_35.getIV()), CompareOp.LT)) }); if (log.isInfoEnabled()) @@ -501,7 +501,7 @@ }, // constraints on the rule. new IConstraint[] { - ValueExpressionConstraint.wrap(new CompareBOp(a, new Constant<IV>(_35.getIV()), CompareOp.LE)) + Constraint.wrap(new CompareBOp(a, new Constant<IV>(_35.getIV()), CompareOp.LE)) }); if (log.isInfoEnabled()) @@ -618,7 +618,7 @@ }, // constraints on the rule. new IConstraint[] { - ValueExpressionConstraint.wrap(new CompareBOp(a, new MathBOp(dAge, new Constant<IV>(_5.getIV()), MathOp.PLUS), CompareOp.GT)) + Constraint.wrap(new CompareBOp(a, new MathBOp(dAge, new Constant<IV>(_5.getIV()), MathOp.PLUS), CompareOp.GT)) }); try { @@ -731,7 +731,7 @@ }, // constraints on the rule. new IConstraint[] { - ValueExpressionConstraint.wrap(new CompareBOp(a, new Constant<IV>(l2.getIV()), CompareOp.GT)) + Constraint.wrap(new CompareBOp(a, new Constant<IV>(l2.getIV()), CompareOp.GT)) }); try { Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/rules/TestRuleExpansion.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/rules/TestRuleExpansion.java 2011-02-22 23:39:14 UTC (rev 4229) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/rules/TestRuleExpansion.java 2011-02-22 23:40:52 UTC (rev 4230) @@ -42,6 +42,7 @@ import com.bigdata.bop.IVariable; import com.bigdata.bop.IVariableOrConstant; import com.bigdata.bop.Var; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NEConstant; import com.bigdata.bop.joinGraph.IEvaluationPlan; import com.bigdata.bop.joinGraph.IEvaluationPlanFactory; @@ -322,7 +323,7 @@ }, // true, // distinct new IConstraint[] { - new NEConstant(_p, sameAs) + Constraint.wrap(new NEConstant(_p, sameAs)) } ); Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/spo/TestSPORelation.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/spo/TestSPORelation.java 2011-02-22 23:39:14 UTC (rev 4229) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/spo/TestSPORelation.java 2011-02-22 23:40:52 UTC (rev 4230) @@ -39,6 +39,7 @@ import com.bigdata.bop.IVariableOrConstant; import com.bigdata.bop.Var; import com.bigdata.bop.bindingSet.ArrayBindingSet; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NE; import com.bigdata.bop.joinGraph.IEvaluationPlan; import com.bigdata.bop.joinGraph.IEvaluationPlanFactory; @@ -149,7 +150,7 @@ new P(relation, var("v"), rdfType, var("u")) // },// new IConstraint[] { - new NE(var("u"),var("x")) + Constraint.wrap(new NE(var("u"),var("x"))) } ); 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-02-22 23:39:14 UTC (rev 4229) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java 2011-02-22 23:40:52 UTC (rev 4230) @@ -72,13 +72,6 @@ import com.bigdata.bop.NV; import com.bigdata.bop.PipelineOp; import com.bigdata.bop.ap.Predicate; -import com.bigdata.bop.constraint.AND; -import com.bigdata.bop.constraint.BOUND; -import com.bigdata.bop.constraint.EQ; -import com.bigdata.bop.constraint.INBinarySearch; -import com.bigdata.bop.constraint.NE; -import com.bigdata.bop.constraint.NOT; -import com.bigdata.bop.constraint.OR; import com.bigdata.bop.engine.IRunningQuery; import com.bigdata.bop.engine.QueryEngine; import com.bigdata.bop.solutions.ISortOrder; @@ -96,7 +89,7 @@ import com.bigdata.rdf.internal.constraints.NotBOp; import com.bigdata.rdf.internal.constraints.OrBOp; import com.bigdata.rdf.internal.constraints.SameTermBOp; -import com.bigdata.rdf.internal.constraints.ValueExpressionConstraint; +import com.bigdata.rdf.internal.constraints.Constraint; import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataValue; import com.bigdata.rdf.sail.BigdataSail.Options; @@ -206,18 +199,7 @@ * either as JOINs (generating an additional {@link IPredicate} in the * {@link IRule}) or as an {@link INBinarySearch} constraint, where the inclusion set is * pre-populated by some operation on the {@link LexiconRelation}. - * <dl> - * <dt>EQ</dt> - * <dd>Translated into an {@link EQ} constraint on an {@link IPredicate}.</dd> - * <dt>NE</dt> - * <dd>Translated into an {@link NE} constraint on an {@link IPredicate}.</dd> - * <dt>IN</dt> - * <dd>Translated into an {@link INBinarySearch} constraint on an {@link IPredicate}.</dd> - * <dt>OR</dt> - * <dd>Translated into an {@link OR} constraint on an {@link IPredicate}.</dd> - * <dt></dt> - * <dd></dd> - * </dl> + * <p> * <h2>Magic predicates</h2> * <p> * {@link BD#SEARCH} is the only magic predicate at this time. When the object @@ -2051,7 +2033,7 @@ private IConstraint toConstraint(final ValueExpr ve) { final IValueExpression<IV> veBOp = toVE(ve); - return ValueExpressionConstraint.wrap(veBOp); + return Constraint.wrap(veBOp); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mrp...@us...> - 2011-02-22 23:39:21
|
Revision: 4229 http://bigdata.svn.sourceforge.net/bigdata/?rev=4229&view=rev Author: mrpersonick Date: 2011-02-22 23:39:14 +0000 (Tue, 22 Feb 2011) Log Message: ----------- refactor constraints -> value expressions Modified Paths: -------------- 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/EBVBOp.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/FastClosure.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-rdf/src/java/com/bigdata/rdf/rules/RuleFastClosure11.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleFastClosure13.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlInverseOf1.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlSameAs1.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlSameAs1b.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlSameAs2.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlSameAs3.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlTransitiveProperty1.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlTransitiveProperty2.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleRdfs05.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleRdfs07.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleRdfs09.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleRdfs11.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/Constraint.java Removed Paths: ------------- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/ValueExpressionConstraint.java Modified: 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/inf/OwlSameAsPropertiesExpandingIterator.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/inf/OwlSameAsPropertiesExpandingIterator.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -13,7 +13,8 @@ import com.bigdata.bop.IVariable; import com.bigdata.bop.IVariableOrConstant; import com.bigdata.bop.Var; -import com.bigdata.bop.constraint.BOpConstraint; +import com.bigdata.bop.constraint.BooleanValueExpression; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.joinGraph.IEvaluationPlan; import com.bigdata.bop.joinGraph.IEvaluationPlanFactory; import com.bigdata.bop.joinGraph.fast.DefaultEvaluationPlanFactory2; @@ -28,8 +29,8 @@ import com.bigdata.rdf.spo.SPOPredicate; import com.bigdata.rdf.store.AbstractTripleStore; import com.bigdata.relation.accesspath.IAccessPath; +import com.bigdata.relation.rule.IAccessPathExpander; import com.bigdata.relation.rule.IRule; -import com.bigdata.relation.rule.IAccessPathExpander; import com.bigdata.relation.rule.QueryOptions; import com.bigdata.relation.rule.Rule; import com.bigdata.relation.rule.eval.ActionEnum; @@ -119,8 +120,8 @@ new SPOPredicate(SPO, _sameS, _p, _sameO) }, QueryOptions.DISTINCT, // distinct // constraints on the rule. - new IConstraint[] { new RejectSameAsSelf(head.s(), head - .p(), head.o()) }); + new IConstraint[] { Constraint.wrap(new RejectSameAsSelf(head.s(), head + .p(), head.o())) }); runQuery(rule); } @@ -151,8 +152,8 @@ sameAsSelfExpander) }, QueryOptions.DISTINCT, // distinct // constraints on the rule. - new IConstraint[] { new RejectSameAsSelf(head.s(), head - .p(), head.o()) }); + new IConstraint[] { Constraint.wrap(new RejectSameAsSelf(head.s(), head + .p(), head.o())) }); runQuery(rule); } @@ -183,8 +184,8 @@ sameAsSelfExpander) }, QueryOptions.DISTINCT, // distinct // constraints on the rule. - new IConstraint[] { new RejectSameAsSelf(head.s(), head - .p(), head.o()) }); + new IConstraint[] { Constraint.wrap(new RejectSameAsSelf(head.s(), head + .p(), head.o())) }); runQuery(rule); } @@ -215,8 +216,8 @@ new SPOPredicate(SPO, _s, _p, _o) }, QueryOptions.DISTINCT, // distinct // constraints on the rule. - new IConstraint[] { new RejectSameAsSelf(head.s(), head - .p(), head.o()) }); + new IConstraint[] { Constraint.wrap(new RejectSameAsSelf(head.s(), head + .p(), head.o())) }); runQuery(rule); } @@ -495,9 +496,14 @@ } }; - private class RejectSameAsSelf extends BOpConstraint { + private class RejectSameAsSelf extends BooleanValueExpression { - public RejectSameAsSelf(final IVariableOrConstant<IV> _s, + /** + * + */ + private static final long serialVersionUID = -7877904606067597254L; + + public RejectSameAsSelf(final IVariableOrConstant<IV> _s, final IVariableOrConstant<IV> _p, final IVariableOrConstant<IV> _o) { @@ -505,7 +511,7 @@ } - public boolean accept(final IBindingSet bindings) { + public Boolean get(final IBindingSet bindings) { final IV sVal = getValue((IVariableOrConstant)get(0/*_s*/), bindings); final IV pVal = getValue((IVariableOrConstant)get(1/*_p*/), bindings); final IV oVal = getValue((IVariableOrConstant)get(2/*_o*/), bindings); Copied: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/Constraint.java (from rev 4219, branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/ValueExpressionConstraint.java) =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/Constraint.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/Constraint.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -0,0 +1,106 @@ +/* + +Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ +package com.bigdata.rdf.internal.constraints; + +import java.util.Map; + +import org.apache.log4j.Logger; + +import com.bigdata.bop.BOp; +import com.bigdata.bop.IBindingSet; +import com.bigdata.bop.IConstraint; +import com.bigdata.bop.IValueExpression; +import com.bigdata.rdf.error.SparqlTypeErrorException; +import com.bigdata.rdf.internal.IV; + +/** + * BOpConstraint that wraps a {@link EBVBOp}, which itself computes the + * effective boolean value of an IValueExpression. + */ +public class Constraint extends com.bigdata.bop.constraint.Constraint { + + /** + * + */ + private static final long serialVersionUID = -5796492538735372727L; + + protected static final Logger log = Logger.getLogger(Constraint.class); + + /** + * Convenience method to generate a constraint from a value expression. + */ + public static IConstraint wrap(final IValueExpression<IV> ve) { + if (ve instanceof EBVBOp) + return new Constraint((EBVBOp) ve); + else + return new Constraint(new EBVBOp(ve)); + } + + + public Constraint(final EBVBOp x) { + + this(new BOp[] { x }, null/*annocations*/); + + } + + /** + * Required shallow copy constructor. + */ + public Constraint(final BOp[] args, + final Map<String, Object> anns) { + super(args, anns); + } + + /** + * Required deep copy constructor. + */ + public Constraint(final Constraint op) { + super(op); + } + + @Override + public EBVBOp get(final int i) { + return (EBVBOp) super.get(i); + } + + public boolean accept(final IBindingSet bs) { + + try { + + // evaluate the EBV operator + return get(0).get(bs).booleanValue(); + + } catch (SparqlTypeErrorException ex) { + + // trap the type error and filter out the solution + if (log.isInfoEnabled()) + log.info("discarding solution due to type error: " + bs); + return false; + + } + + } + +} Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/EBVBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/EBVBOp.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/EBVBOp.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -37,8 +37,7 @@ * Calculates the "effective boolean value" of an IValueExpression. See the * SPARQL spec for details. */ -public class EBVBOp extends ValueExpressionBOp - implements IValueExpression<IV> { +public class EBVBOp extends ValueExpressionBOp { /** * Deleted: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/ValueExpressionConstraint.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/ValueExpressionConstraint.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/ValueExpressionConstraint.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -1,109 +0,0 @@ -/* - -Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. - -Contact: - SYSTAP, LLC - 4501 Tower Road - Greensboro, NC 27410 - lic...@bi... - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -*/ -package com.bigdata.rdf.internal.constraints; - -import java.util.Map; - -import org.apache.log4j.Logger; - -import com.bigdata.bop.BOp; -import com.bigdata.bop.IBindingSet; -import com.bigdata.bop.IConstraint; -import com.bigdata.bop.IValueExpression; -import com.bigdata.bop.constraint.BOpConstraint; -import com.bigdata.rdf.error.SparqlTypeErrorException; -import com.bigdata.rdf.internal.IV; - -/** - * BOpConstraint that wraps a {@link EBVBOp}, which itself computes the - * effective boolean value of an IValueExpression. - */ -public class ValueExpressionConstraint extends BOpConstraint { - - /** - * - */ - private static final long serialVersionUID = -7068219781217676085L; - - protected static final Logger log = Logger.getLogger(ValueExpressionConstraint.class); - - /** - * Convenience method to generate a constraint from a value expression. - */ - public static IConstraint wrap(final IValueExpression<IV> ve) { - return new ValueExpressionConstraint(new EBVBOp(ve)); - } - - - public ValueExpressionConstraint(final EBVBOp x) { - - this(new BOp[] { x }, null/*annocations*/); - - } - - /** - * Required shallow copy constructor. - */ - public ValueExpressionConstraint(final BOp[] args, - final Map<String, Object> anns) { - - super(args, anns); - - if (args.length != 1 || args[0] == null) - throw new IllegalArgumentException(); - - } - - /** - * Required deep copy constructor. - */ - public ValueExpressionConstraint(final ValueExpressionConstraint op) { - super(op); - } - - @Override - public EBVBOp get(final int i) { - return (EBVBOp) super.get(i); - } - - public boolean accept(final IBindingSet bs) { - - try { - - // evaluate the EBV operator - return get(0).get(bs).booleanValue(); - - } catch (SparqlTypeErrorException ex) { - - // trap the type error and filter out the solution - if (log.isInfoEnabled()) - log.info("discarding solution due to type error: " + bs); - return false; - - } - - } - -} Modified: 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/magic/IRISUtils.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/magic/IRISUtils.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -32,6 +32,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; + import org.apache.log4j.Logger; import org.deri.iris.api.IProgramOptimisation.Result; import org.deri.iris.api.basics.ILiteral; @@ -45,8 +46,7 @@ import org.deri.iris.builtins.BuiltinsFactory; import org.deri.iris.optimisations.magicsets.MagicSets; import org.deri.iris.terms.TermFactory; -import com.bigdata.rdf.internal.IV; -import com.bigdata.rdf.internal.IVUtility; + import com.bigdata.bop.Constant; import com.bigdata.bop.IConstant; import com.bigdata.bop.IConstraint; @@ -55,6 +55,8 @@ import com.bigdata.bop.IVariableOrConstant; import com.bigdata.bop.NV; import com.bigdata.bop.Var; +import com.bigdata.bop.constraint.BooleanValueExpression; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.EQ; import com.bigdata.bop.constraint.EQConstant; import com.bigdata.bop.constraint.INBinarySearch; @@ -631,8 +633,14 @@ * @return * the bigdata constraint */ - private static IConstraint convertToBigdataConstraint(ILiteral literal) { + private static IConstraint convertToBigdataConstraint(final ILiteral literal) { + return Constraint.wrap(convertToBigdataVE(literal)); + + } + + private static BooleanValueExpression convertToBigdataVE(final ILiteral literal) { + ITuple tuple = literal.getAtom().getTuple(); org.deri.iris.api.basics.IPredicate p = literal.getAtom().getPredicate(); Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/FastClosure.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/FastClosure.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/FastClosure.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -10,6 +10,7 @@ import com.bigdata.bop.IConstraint; import com.bigdata.bop.IVariable; import com.bigdata.bop.bindingSet.ArrayBindingSet; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NEConstant; import com.bigdata.rdf.internal.IV; import com.bigdata.rdf.store.AbstractTripleStore; @@ -279,7 +280,7 @@ program.addStep(tmp.specialize(// noBindings,// new IConstraint[] { // - new NEConstant(p, owlSameAs) // + Constraint.wrap(new NEConstant(p, owlSameAs)) // }// )); @@ -297,7 +298,7 @@ program.addStep(tmp.specialize(// noBindings,// new IConstraint[] { // - new NEConstant(p, owlSameAs) // + Constraint.wrap(new NEConstant(p, owlSameAs)) // }// )); Modified: 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/MatchRule.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/MatchRule.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -11,6 +11,7 @@ import com.bigdata.bop.IPredicate; import com.bigdata.bop.IVariable; import com.bigdata.bop.NV; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.INBinarySearch; import com.bigdata.rdf.internal.IV; import com.bigdata.rdf.spo.ExplicitSPOFilter; @@ -59,7 +60,7 @@ .getConstant(RDFS.SUBCLASSOF), cls) // }, new IConstraint[] { - new INBinarySearch(var("p"), preds) // p IN preds + Constraint.wrap(new INBinarySearch(var("p"), preds)) // p IN preds }); } Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RejectAnythingSameAsItself.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RejectAnythingSameAsItself.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RejectAnythingSameAsItself.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -30,22 +30,19 @@ import com.bigdata.bop.IBindingSet; import com.bigdata.bop.IConstant; import com.bigdata.bop.IVariable; -import com.bigdata.bop.constraint.BOpConstraint; +import com.bigdata.bop.constraint.BooleanValueExpression; /** * Rejects (x y z) iff x==z and y==owl:sameAs, where x, y, and z are variables. - * - * @author <a href="mailto:tho...@us...">Bryan Thompson</a> - * @version $Id$ */ -public class RejectAnythingSameAsItself extends BOpConstraint { +public class RejectAnythingSameAsItself extends BooleanValueExpression { /** - * - */ - private static final long serialVersionUID = 1L; + * + */ + private static final long serialVersionUID = -44020295153412258L; - /** + /** * Required shallow copy constructor. */ public RejectAnythingSameAsItself(final BOp[] values, @@ -79,7 +76,7 @@ } @SuppressWarnings("unchecked") - public boolean accept(final IBindingSet bindingSet) { + public Boolean get(final IBindingSet bindingSet) { // get binding for "x". final IConstant<Long> s = bindingSet.get((IVariable<?>) get(0)/* s */); Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleFastClosure11.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleFastClosure11.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleFastClosure11.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -28,6 +28,7 @@ import org.openrdf.model.vocabulary.RDFS; import com.bigdata.bop.IConstraint; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NE; import com.bigdata.rdf.spo.SPOPredicate; import com.bigdata.rdf.vocab.Vocabulary; @@ -65,7 +66,7 @@ new SPOPredicate(relationName,var("a"), vocab.getConstant(RDFS.DOMAIN), var("b"))// }, new IConstraint[] { - new NE(var("y"),var("a")) + Constraint.wrap(new NE(var("y"),var("a"))) }); } Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleFastClosure13.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleFastClosure13.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleFastClosure13.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -28,6 +28,7 @@ import org.openrdf.model.vocabulary.RDFS; import com.bigdata.bop.IConstraint; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NE; import com.bigdata.rdf.spo.SPOPredicate; import com.bigdata.rdf.vocab.Vocabulary; @@ -65,7 +66,7 @@ new SPOPredicate(relationName,var("a"), vocab.getConstant(RDFS.RANGE), var("b"))// }, new IConstraint[] { - new NE(var("y"),var("a")) + Constraint.wrap(new NE(var("y"),var("a"))) }); } Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlInverseOf1.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlInverseOf1.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlInverseOf1.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -30,6 +30,7 @@ import org.openrdf.model.vocabulary.OWL; import com.bigdata.bop.IConstraint; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NE; import com.bigdata.rdf.spo.SPOPredicate; import com.bigdata.rdf.vocab.Vocabulary; @@ -63,7 +64,7 @@ new SPOPredicate(relationName,var("a"), vocab.getConstant(OWL.INVERSEOF), var("b")),// }, new IConstraint[] { - new NE(var("a"),var("b")) + Constraint.wrap(new NE(var("a"),var("b"))) } ); Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlSameAs1.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlSameAs1.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlSameAs1.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -30,6 +30,7 @@ import org.openrdf.model.vocabulary.OWL; import com.bigdata.bop.IConstraint; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NE; import com.bigdata.rdf.spo.SPOPredicate; import com.bigdata.rdf.vocab.Vocabulary; @@ -63,7 +64,7 @@ new SPOPredicate(relationName,var("x"), vocab.getConstant(OWL.SAMEAS), var("y"))// }, new IConstraint[] { - new NE(var("x"),var("y")) + Constraint.wrap(new NE(var("x"),var("y"))) } ); Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlSameAs1b.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlSameAs1b.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlSameAs1b.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -30,6 +30,7 @@ import org.openrdf.model.vocabulary.OWL; import com.bigdata.bop.IConstraint; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NE; import com.bigdata.rdf.spo.SPOPredicate; import com.bigdata.rdf.vocab.Vocabulary; @@ -64,9 +65,9 @@ new SPOPredicate(relationName,var("x"), vocab.getConstant(OWL.SAMEAS), var("y")),// new SPOPredicate(relationName,var("y"), vocab.getConstant(OWL.SAMEAS), var("z"))// }, new IConstraint[] { - new NE(var("x"),var("y")), - new NE(var("y"),var("z")), - new NE(var("x"),var("z")), + Constraint.wrap(new NE(var("x"),var("y"))), + Constraint.wrap(new NE(var("y"),var("z"))), + Constraint.wrap(new NE(var("x"),var("z"))), } ); Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlSameAs2.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlSameAs2.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlSameAs2.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -29,6 +29,7 @@ import org.openrdf.model.vocabulary.OWL; import com.bigdata.bop.IConstraint; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NE; import com.bigdata.bop.constraint.NEConstant; import com.bigdata.rdf.spo.SPOPredicate; @@ -68,8 +69,8 @@ * Reject (y sameAs z) as the head. */ // new RejectAnythingSameAsItself(var("y"),var("a"),var("z"),vocab.getConstant(OWL.SAMEAS)) - new NEConstant(var("a"),vocab.getConstant(OWL.SAMEAS)), - new NE(var("x"),var("y")) + Constraint.wrap(new NEConstant(var("a"),vocab.getConstant(OWL.SAMEAS))), + Constraint.wrap(new NE(var("x"),var("y"))) } ); Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlSameAs3.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlSameAs3.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlSameAs3.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -30,6 +30,7 @@ import org.openrdf.model.vocabulary.OWL; import com.bigdata.bop.IConstraint; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NE; import com.bigdata.bop.constraint.NEConstant; import com.bigdata.rdf.spo.SPOPredicate; @@ -67,8 +68,8 @@ * Reject (z sameAs y) as the head. */ // new RejectAnythingSameAsItself(var("z"),var("a"),var("y"),vocab.getConstant(OWL.SAMEAS)) - new NEConstant(var("a"),vocab.getConstant(OWL.SAMEAS)), - new NE(var("x"),var("y")) + Constraint.wrap(new NEConstant(var("a"),vocab.getConstant(OWL.SAMEAS))), + Constraint.wrap(new NE(var("x"),var("y"))) } ); Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlTransitiveProperty1.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlTransitiveProperty1.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlTransitiveProperty1.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -31,6 +31,7 @@ import org.openrdf.model.vocabulary.RDF; import com.bigdata.bop.IConstraint; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NE; import com.bigdata.rdf.spo.SPOPredicate; import com.bigdata.rdf.vocab.Vocabulary; @@ -66,9 +67,9 @@ new SPOPredicate(relationName,var("x"), var("a"), var("y")),// new SPOPredicate(relationName,var("y"), var("a"), var("z"))// }, new IConstraint[] { - new NE(var("x"),var("y")), - new NE(var("y"),var("z")), - new NE(var("x"),var("z")), + Constraint.wrap(new NE(var("x"),var("y"))), + Constraint.wrap(new NE(var("y"),var("z"))), + Constraint.wrap(new NE(var("x"),var("z"))), } ); Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlTransitiveProperty2.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlTransitiveProperty2.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleOwlTransitiveProperty2.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -32,6 +32,7 @@ import org.openrdf.model.vocabulary.RDFS; import com.bigdata.bop.IConstraint; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NE; import com.bigdata.rdf.spo.SPOPredicate; import com.bigdata.rdf.vocab.Vocabulary; @@ -66,7 +67,7 @@ new SPOPredicate(relationName,var("a"), vocab.getConstant(RDF.TYPE), vocab.getConstant(OWL.TRANSITIVEPROPERTY)),// new SPOPredicate(relationName,var("b"), vocab.getConstant(RDFS.SUBPROPERTYOF), var("a"))// }, new IConstraint[] { - new NE(var("a"),var("b")), + Constraint.wrap(new NE(var("a"),var("b"))), } ); Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleRdfs05.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleRdfs05.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleRdfs05.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -26,6 +26,7 @@ import org.openrdf.model.vocabulary.RDFS; import com.bigdata.bop.IConstraint; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NE; import com.bigdata.rdf.spo.SPOPredicate; import com.bigdata.rdf.vocab.Vocabulary; @@ -57,8 +58,8 @@ new SPOPredicate(relationName,var("v"), vocab.getConstant(RDFS.SUBPROPERTYOF), var("x")) // }, new IConstraint[] { - new NE(var("u"),var("v")), - new NE(var("v"),var("x")) + Constraint.wrap(new NE(var("u"),var("v"))), + Constraint.wrap(new NE(var("v"),var("x"))) }); } Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleRdfs07.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleRdfs07.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleRdfs07.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -26,6 +26,7 @@ import org.openrdf.model.vocabulary.RDFS; import com.bigdata.bop.IConstraint; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NE; import com.bigdata.rdf.spo.SPOPredicate; import com.bigdata.rdf.vocab.Vocabulary; @@ -55,7 +56,7 @@ new SPOPredicate(relationName,var("u"), var("a"), var("y"))// }, new IConstraint[] { - new NE(var("a"),var("b")) + Constraint.wrap(new NE(var("a"),var("b"))) } ); Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleRdfs09.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleRdfs09.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleRdfs09.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -27,6 +27,7 @@ import org.openrdf.model.vocabulary.RDFS; import com.bigdata.bop.IConstraint; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NE; import com.bigdata.rdf.spo.SPOPredicate; import com.bigdata.rdf.vocab.Vocabulary; @@ -55,7 +56,7 @@ new SPOPredicate(relationName,var("v"), vocab.getConstant(RDF.TYPE), var("u"))// }, new IConstraint[] { - new NE(var("u"),var("x")) + Constraint.wrap(new NE(var("u"),var("x"))) }); } Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleRdfs11.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleRdfs11.java 2011-02-22 23:38:00 UTC (rev 4228) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rules/RuleRdfs11.java 2011-02-22 23:39:14 UTC (rev 4229) @@ -26,6 +26,7 @@ import org.openrdf.model.vocabulary.RDFS; import com.bigdata.bop.IConstraint; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NE; import com.bigdata.rdf.spo.SPOPredicate; import com.bigdata.rdf.vocab.Vocabulary; @@ -59,8 +60,8 @@ new SPOPredicate(relationName,var("v"), vocab.getConstant(RDFS.SUBCLASSOF), var("x")) // }, new IConstraint[] { - new NE(var("u"),var("v")), - new NE(var("v"),var("x")) + Constraint.wrap(new NE(var("u"),var("v"))), + Constraint.wrap(new NE(var("v"),var("x"))) }); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mrp...@us...> - 2011-02-22 23:38:07
|
Revision: 4228 http://bigdata.svn.sourceforge.net/bigdata/?rev=4228&view=rev Author: mrpersonick Date: 2011-02-22 23:38:00 +0000 (Tue, 22 Feb 2011) Log Message: ----------- refactor constraints -> value expressions Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/bset/TestConditionalRoutingOp.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/bset/TestCopyBindingSets.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestEQ.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/TestINConstraint.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/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 branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/controller/TestSubqueryOp.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/fed/TestFederatedQueryEngine.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/join/TestPipelineJoin.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestPartitionedJoinGroup.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/rto/TestJoinGraph.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/util/TestBOpUtility.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/util/TestBOpUtility_canJoinUsingConstraints.java branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/relation/rule/AbstractRuleTestCase.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/bset/TestConditionalRoutingOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/bset/TestConditionalRoutingOp.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/bset/TestConditionalRoutingOp.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -44,6 +44,7 @@ import com.bigdata.bop.Var; import com.bigdata.bop.bindingSet.ArrayBindingSet; import com.bigdata.bop.bindingSet.HashBindingSet; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.EQConstant; import com.bigdata.bop.engine.BOpStats; import com.bigdata.bop.engine.BlockingBufferWithStats; @@ -151,7 +152,7 @@ NV.asMap(new NV[]{// new NV(BOp.Annotations.BOP_ID,bopId),// new NV(ConditionalRoutingOp.Annotations.CONDITION, - new EQConstant(x,new Constant<String>("Mary"))),// + Constraint.wrap(new EQConstant(x,new Constant<String>("Mary")))),// })); // the expected solutions (default sink). Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/bset/TestCopyBindingSets.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/bset/TestCopyBindingSets.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/bset/TestCopyBindingSets.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -42,6 +42,7 @@ import com.bigdata.bop.NV; import com.bigdata.bop.Var; import com.bigdata.bop.bindingSet.HashBindingSet; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.EQConstant; import com.bigdata.bop.engine.BOpStats; import com.bigdata.bop.engine.BlockingBufferWithStats; @@ -246,7 +247,7 @@ new NV(BOp.Annotations.BOP_ID, bopId),// new NV(CopyOp.Annotations.CONSTRAINTS, new IConstraint[] { - new EQConstant(x, new Constant<String>("Mary")) + Constraint.wrap(new EQConstant(x, new Constant<String>("Mary"))) }),// })); Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestEQ.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestEQ.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestEQ.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -94,7 +94,7 @@ new IConstant[] { new Constant<String>("1"), new Constant<String>("1") }); - assertTrue(op.accept(bs1)); + assertTrue(op.get(bs1)); } @@ -110,7 +110,7 @@ new IConstant[] { new Constant<String>("1"), new Constant<String>("2") }); - assertFalse(op.accept(bs1)); + assertFalse(op.get(bs1)); } @@ -122,7 +122,7 @@ new IVariable[] { Var.var("x") }, // new IConstant[] { new Constant<String>("1") }); - assertTrue(op.accept(bs1)); + assertTrue(op.get(bs1)); } } Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestEQConstant.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestEQConstant.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestEQConstant.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -88,9 +88,9 @@ IBindingSet ne2 = new ArrayBindingSet ( new IVariable<?> [] { var }, new IConstant [] { val3 } ) ; IBindingSet nb = new ArrayBindingSet ( new IVariable<?> [] {}, new IConstant [] {} ) ; - assertTrue ( op.accept ( eq ) ) ; - assertFalse ( op.accept ( ne1 ) ) ; - assertFalse ( op.accept ( ne2 ) ) ; - assertTrue ( op.accept ( nb ) ) ; + assertTrue ( op.get ( eq ) ) ; + assertFalse ( op.get ( ne1 ) ) ; + assertFalse ( op.get ( ne2 ) ) ; + assertTrue ( op.get ( nb ) ) ; } } \ No newline at end of file Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestINConstraint.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestINConstraint.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestINConstraint.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -123,9 +123,9 @@ IBindingSet notin = new ArrayBindingSet ( new IVariable<?> [] { x }, new IConstant [] { val3 } ) ; IBindingSet nb = new ArrayBindingSet ( new IVariable<?> [] {}, new IConstant [] {} ) ; - assertTrue ( op.accept ( in ) ) ; - assertFalse ( op.accept ( notin ) ) ; - assertTrue ( op.accept ( nb ) ) ; + assertTrue ( op.get ( in ) ) ; + assertFalse ( op.get ( notin ) ) ; + assertTrue ( op.get ( nb ) ) ; } protected abstract INConstraint newINConstraint ( IVariable<?> var, IConstant<?> vals [] ) ; Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestInBinarySearch.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestInBinarySearch.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestInBinarySearch.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -79,10 +79,10 @@ INConstraint op = new INBinarySearch ( x, vals ) ; - assertTrue ( op.accept ( new ArrayBindingSet ( new IVariable<?> [] { x }, new IConstant [] { new Constant<Integer> ( 21 ) } ) ) ) ; - assertTrue ( op.accept ( new ArrayBindingSet ( new IVariable<?> [] { x }, new IConstant [] { new Constant<Integer> ( 37 ) } ) ) ) ; - assertTrue ( op.accept ( new ArrayBindingSet ( new IVariable<?> [] { x }, new IConstant [] { new Constant<Integer> ( 75 ) } ) ) ) ; - assertFalse ( op.accept ( new ArrayBindingSet ( new IVariable<?> [] { x }, new IConstant [] { new Constant<Integer> ( 101 ) } ) ) ) ; + assertTrue ( op.get ( new ArrayBindingSet ( new IVariable<?> [] { x }, new IConstant [] { new Constant<Integer> ( 21 ) } ) ) ) ; + assertTrue ( op.get ( new ArrayBindingSet ( new IVariable<?> [] { x }, new IConstant [] { new Constant<Integer> ( 37 ) } ) ) ) ; + assertTrue ( op.get ( new ArrayBindingSet ( new IVariable<?> [] { x }, new IConstant [] { new Constant<Integer> ( 75 ) } ) ) ) ; + assertFalse ( op.get ( new ArrayBindingSet ( new IVariable<?> [] { x }, new IConstant [] { new Constant<Integer> ( 101 ) } ) ) ) ; } @Override protected INConstraint newINConstraint ( IVariable<?> var, IConstant<?> vals [] ) Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestNE.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestNE.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestNE.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -75,9 +75,9 @@ } /** - * Unit test for {@link NE#accept(IBindingSet)} + * Unit test for {@link NE#get(IBindingSet)} */ - public void testAccept () + public void testGet () { Var<?> x = Var.var ( "x" ) ; Var<?> y = Var.var ( "y" ) ; @@ -89,8 +89,8 @@ IBindingSet ne = new ArrayBindingSet ( vars, new IConstant [] { new Constant<String> ( "1" ), new Constant<String> ( "2" ) } ) ; IBindingSet nb = new ArrayBindingSet ( new IVariable<?> [] { x }, new IConstant [] { new Constant<String> ( "1" ) } ) ; - assertTrue ( op.accept ( ne ) ) ; - assertFalse ( op.accept ( eq ) ) ; - assertTrue ( op.accept ( nb ) ) ; + assertTrue ( op.get ( ne ) ) ; + assertFalse ( op.get ( eq ) ) ; + assertTrue ( op.get ( nb ) ) ; } } \ No newline at end of file Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestNEConstant.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestNEConstant.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestNEConstant.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -72,7 +72,7 @@ } /** - * Unit test for {@link NEConstant#accept(IBindingSet)} + * Unit test for {@link NEConstant#get(IBindingSet)} */ public void testAccept () { @@ -88,9 +88,9 @@ IBindingSet ne2 = new ArrayBindingSet ( new IVariable<?> [] { var }, new IConstant [] { val3 } ) ; IBindingSet nb = new ArrayBindingSet ( new IVariable<?> [] {}, new IConstant [] {} ) ; - assertFalse ( op.accept ( eq ) ) ; - assertTrue ( op.accept ( ne1 ) ) ; - assertTrue ( op.accept ( ne2 ) ) ; - assertTrue ( op.accept ( nb ) ) ; + assertFalse ( op.get ( eq ) ) ; + assertTrue ( op.get ( ne1 ) ) ; + assertTrue ( op.get ( ne2 ) ) ; + assertTrue ( op.get ( nb ) ) ; } } \ No newline at end of file Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestOR.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestOR.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/constraint/TestOR.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -63,8 +63,8 @@ */ public void testConstructor () { - IConstraint eq = new EQ ( Var.var ( "x" ), Var.var ( "y" ) ) ; - IConstraint ne = new EQ ( Var.var ( "x" ), Var.var ( "y" ) ) ; + BooleanValueExpression eq = new EQ ( Var.var ( "x" ), Var.var ( "y" ) ) ; + BooleanValueExpression ne = new EQ ( Var.var ( "x" ), Var.var ( "y" ) ) ; try { assertTrue ( null != new OR ( null, eq ) ) ; fail ( "IllegalArgumentException expected, lhs was null" ) ; } catch ( IllegalArgumentException e ) {} @@ -76,7 +76,7 @@ } /** - * Unit test for {@link OR#accept(IBindingSet)} + * Unit test for {@link OR#get(IBindingSet)} */ public void testAccept () { @@ -85,8 +85,8 @@ Constant<Integer> val1 = new Constant<Integer> ( 1 ) ; Constant<Integer> val2 = new Constant<Integer> ( 2 ) ; - IConstraint eq = new EQ ( x, y ) ; - IConstraint eqc = new EQConstant ( y, val2 ) ; + BooleanValueExpression eq = new EQ ( x, y ) ; + BooleanValueExpression eqc = new EQConstant ( y, val2 ) ; OR op = new OR ( eq, eqc ) ; @@ -94,8 +94,8 @@ IBindingSet eqrhs = new ArrayBindingSet ( new IVariable<?> [] { x, y }, new IConstant [] { val1, val2 } ) ; IBindingSet ne = new ArrayBindingSet ( new IVariable<?> [] { x, y }, new IConstant [] { val2, val1 } ) ; - assertTrue ( op.accept ( eqlhs ) ) ; - assertTrue ( op.accept ( eqrhs ) ) ; - assertFalse ( op.accept ( ne ) ) ; + assertTrue ( op.get ( eqlhs ) ) ; + assertTrue ( op.get ( eqrhs ) ) ; + assertFalse ( op.get ( ne ) ) ; } } \ No newline at end of file Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/controller/TestSubqueryOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/controller/TestSubqueryOp.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/controller/TestSubqueryOp.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -56,6 +56,7 @@ import com.bigdata.bop.bindingSet.HashBindingSet; import com.bigdata.bop.bset.ConditionalRoutingOp; import com.bigdata.bop.bset.StartOp; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NEConstant; import com.bigdata.bop.engine.BOpStats; import com.bigdata.bop.engine.IChunkMessage; @@ -598,7 +599,7 @@ new NV(PipelineJoin.Annotations.PREDICATE, pred3Op),// // constraint d != Leon new NV(PipelineJoin.Annotations.CONSTRAINTS, - new IConstraint[] { new NEConstant(d, new Constant<String>("Leon")) }) + new IConstraint[] { Constraint.wrap(new NEConstant(d, new Constant<String>("Leon"))) }) // // join is optional. // new NV(PipelineJoin.Annotations.OPTIONAL, true),// // // optional target is the same as the default target. @@ -834,7 +835,7 @@ new NV(Predicate.Annotations.BOP_ID, joinId1),// new NV(PipelineJoin.Annotations.PREDICATE,pred1Op)); - final IConstraint condition = new NEConstant(a, new Constant<String>("Paul")); + final IConstraint condition = Constraint.wrap(new NEConstant(a, new Constant<String>("Paul"))); final ConditionalRoutingOp condOp = new ConditionalRoutingOp(new BOp[]{join1Op}, NV.asMap(new NV[]{// Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -62,6 +62,7 @@ import com.bigdata.bop.bindingSet.HashBindingSet; import com.bigdata.bop.bset.ConditionalRoutingOp; import com.bigdata.bop.bset.StartOp; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.EQ; import com.bigdata.bop.constraint.EQConstant; import com.bigdata.bop.fed.TestFederatedQueryEngine; @@ -1144,8 +1145,8 @@ new NV(PipelineJoin.Annotations.PREDICATE, predOp),// // impose constraint on the join. new NV(PipelineJoin.Annotations.CONSTRAINTS, - new IConstraint[] { new EQConstant(y, - new Constant<String>("Paul")) })// + new IConstraint[] { Constraint.wrap(new EQConstant(y, + new Constant<String>("Paul"))) })// ); final PipelineOp query = new SliceOp(new BOp[] { joinOp }, @@ -1610,7 +1611,7 @@ new NV(PipelineJoin.Annotations.PREDICATE, pred2Op),// // constraint x == z new NV(PipelineJoin.Annotations.CONSTRAINTS, - new IConstraint[] { new EQ(x, z) }), + new IConstraint[] { Constraint.wrap(new EQ(x, z)) }), // join is optional. // optional target is the same as the default target. new NV(PipelineOp.Annotations.ALT_SINK_REF, sliceId)); @@ -1769,7 +1770,7 @@ int joinId1 = 2; int joinId2 = 3; - IConstraint condition = new EQConstant(Var.var("x"), new Constant<String>("Mary")); + IConstraint condition = Constraint.wrap(new EQConstant(Var.var("x"), new Constant<String>("Mary"))); IRunningQuery runningQuery = initQueryWithConditionalRoutingOp(condition, startId, joinId1, joinId2); // verify solutions. @@ -1851,7 +1852,7 @@ int joinId2 = 3; // 'x' is actually bound to "Mary" so this condition will be false. - IConstraint condition = new EQConstant(Var.var("x"), new Constant<String>("Fred")); + IConstraint condition = Constraint.wrap(new EQConstant(Var.var("x"), new Constant<String>("Fred"))); IRunningQuery runningQuery = initQueryWithConditionalRoutingOp(condition, startId, joinId1, joinId2); Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/fed/TestFederatedQueryEngine.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/fed/TestFederatedQueryEngine.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/fed/TestFederatedQueryEngine.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -38,18 +38,19 @@ import com.bigdata.bop.IBindingSet; import com.bigdata.bop.IConstant; import com.bigdata.bop.IConstraint; +import com.bigdata.bop.IPredicate.Annotations; import com.bigdata.bop.IVariable; import com.bigdata.bop.IVariableOrConstant; import com.bigdata.bop.NV; import com.bigdata.bop.PipelineOp; import com.bigdata.bop.Var; -import com.bigdata.bop.IPredicate.Annotations; import com.bigdata.bop.ap.E; import com.bigdata.bop.ap.Predicate; import com.bigdata.bop.ap.R; import com.bigdata.bop.bindingSet.ArrayBindingSet; import com.bigdata.bop.bindingSet.HashBindingSet; import com.bigdata.bop.bset.StartOp; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.EQ; import com.bigdata.bop.constraint.EQConstant; import com.bigdata.bop.engine.BOpStats; @@ -719,8 +720,8 @@ BOpEvaluationContext.SHARDED),// // impose constraint on the join. new NV(PipelineJoin.Annotations.CONSTRAINTS, - new IConstraint[] { new EQConstant(y, - new Constant<String>("Paul")) })); + new IConstraint[] { Constraint.wrap(new EQConstant(y, + new Constant<String>("Paul"))) })); final PipelineOp query = new SliceOp(new BOp[] { joinOp }, // slice annotations @@ -1240,7 +1241,7 @@ BOpEvaluationContext.SHARDED),// // constraint x == z new NV(PipelineJoin.Annotations.CONSTRAINTS, - new IConstraint[] { new EQ(x, z) }), + new IConstraint[] { Constraint.wrap(new EQ(x,z)) }), // optional target is the same as the default target. new NV(PipelineOp.Annotations.ALT_SINK_REF, sliceId)); Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/join/TestPipelineJoin.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/join/TestPipelineJoin.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/join/TestPipelineJoin.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -51,6 +51,7 @@ import com.bigdata.bop.bindingSet.ArrayBindingSet; import com.bigdata.bop.bindingSet.HashBindingSet; import com.bigdata.bop.bset.CopyOp; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.INBinarySearch; import com.bigdata.bop.engine.BlockingBufferWithStats; import com.bigdata.bop.engine.MockRunningQuery; @@ -393,7 +394,7 @@ new NV(BOpBase.Annotations.BOP_ID, joinId),// new NV(PipelineJoin.Annotations.PREDICATE, predOp),// new NV(PipelineJoin.Annotations.CONSTRAINTS, - new IConstraint[] { new INBinarySearch<String>(y, set) })); + new IConstraint[] { Constraint.wrap(new INBinarySearch<String>(y, set)) })); // the expected solution (just one). final IBindingSet[] expected = new IBindingSet[] {// Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestPartitionedJoinGroup.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestPartitionedJoinGroup.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/TestPartitionedJoinGroup.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -30,30 +30,19 @@ import java.util.Arrays; import java.util.Iterator; -import org.openrdf.query.algebra.Compare.CompareOp; -import org.openrdf.query.algebra.MathExpr.MathOp; - import junit.framework.TestCase2; import com.bigdata.bop.BOp; import com.bigdata.bop.Constant; import com.bigdata.bop.IConstraint; import com.bigdata.bop.IPredicate; +import com.bigdata.bop.IPredicate.Annotations; import com.bigdata.bop.IVariable; import com.bigdata.bop.NV; import com.bigdata.bop.Var; -import com.bigdata.bop.IPredicate.Annotations; import com.bigdata.bop.ap.Predicate; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NEConstant; -import com.bigdata.bop.joinGraph.PartitionedJoinGroup; -import com.bigdata.rdf.internal.XSDIntIV; -import com.bigdata.rdf.internal.constraints.CompareBOp; -import com.bigdata.rdf.internal.constraints.MathBOp; -import com.bigdata.rdf.model.BigdataURI; -import com.bigdata.rdf.model.BigdataValue; -import com.bigdata.rdf.model.BigdataValueFactory; -import com.bigdata.rdf.spo.SPOPredicate; -import com.bigdata.rdf.store.AbstractTripleStore; /** * Unit tests for {@link PartitionedJoinGroup}. @@ -220,11 +209,11 @@ // Test w/ constraint(s) on the join graph. { - final IConstraint c1 = new NEConstant(x, - new Constant<String>("Bob")); + final IConstraint c1 = Constraint.wrap(new NEConstant(x, + new Constant<String>("Bob"))); - final IConstraint c2 = new NEConstant(y, - new Constant<String>("UNCG")); + final IConstraint c2 = Constraint.wrap(new NEConstant(y, + new Constant<String>("UNCG"))); final IConstraint[] constraints = new IConstraint[] { c1, c2 }; @@ -417,14 +406,14 @@ // Test w/ constraint(s) on the join graph. { - final IConstraint c1 = new NEConstant(x, - new Constant<String>("Bob")); + final IConstraint c1 = Constraint.wrap(new NEConstant(x, + new Constant<String>("Bob"))); - final IConstraint c2 = new NEConstant(y, - new Constant<String>("UNCG")); + final IConstraint c2 = Constraint.wrap(new NEConstant(y, + new Constant<String>("UNCG"))); - final IConstraint c3 = new NEConstant(z, - new Constant<String>("Physics")); + final IConstraint c3 = Constraint.wrap(new NEConstant(z, + new Constant<String>("Physics"))); final IConstraint[] constraints = new IConstraint[] { c1, c2, c3 }; Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/rto/TestJoinGraph.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/rto/TestJoinGraph.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/joinGraph/rto/TestJoinGraph.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -37,6 +37,7 @@ import com.bigdata.bop.NV; import com.bigdata.bop.Var; import com.bigdata.bop.ap.Predicate; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NEConstant; /** @@ -94,7 +95,7 @@ new Predicate(new BOp[]{Var.var("y"),Var.var("z")}),// }; final IConstraint[] constraints = new IConstraint[] { // - new NEConstant(Var.var("x"), new Constant<Long>(12L)) // + Constraint.wrap(new NEConstant(Var.var("x"), new Constant<Long>(12L))) // }; final JoinGraph joinGraph = new JoinGraph(new BOp[0],// new NV(JoinGraph.Annotations.VERTICES, vertices),// @@ -118,7 +119,7 @@ new Predicate(new BOp[]{Var.var("y"),Var.var("z")}),// }; final IConstraint[] constraints = new IConstraint[] { // - new NEConstant(Var.var("x"), new Constant<Long>(12L)) // + Constraint.wrap(new NEConstant(Var.var("x"), new Constant<Long>(12L))) // }; final int limit = 50; final int nedges = 1; @@ -234,7 +235,7 @@ new Predicate(new BOp[] { Var.var("y"), Var.var("z") }),// }; final IConstraint[] constraints = new IConstraint[] { // - new NEConstant(Var.var("x"), new Constant<Long>(12L)) // + Constraint.wrap(new NEConstant(Var.var("x"), new Constant<Long>(12L))) // }; final int limit = 0; final int nedges = 1; @@ -262,7 +263,7 @@ new Predicate(new BOp[] { Var.var("y"), Var.var("z") }),// }; final IConstraint[] constraints = new IConstraint[] { // - new NEConstant(Var.var("x"), new Constant<Long>(12L)) // + Constraint.wrap(new NEConstant(Var.var("x"), new Constant<Long>(12L))) // }; final int limit = 10; final int nedges = 0; Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/util/TestBOpUtility.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/util/TestBOpUtility.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/util/TestBOpUtility.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -29,7 +29,6 @@ import java.util.Iterator; import java.util.Map; -import java.util.Set; import java.util.concurrent.FutureTask; import junit.framework.TestCase2; @@ -48,9 +47,6 @@ import com.bigdata.bop.NV; import com.bigdata.bop.PipelineOp; import com.bigdata.bop.Var; -import com.bigdata.bop.BOp.Annotations; -import com.bigdata.bop.ap.Predicate; -import com.bigdata.bop.constraint.BOpConstraint; /** * Unit tests for {@link BOpUtility}. Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/util/TestBOpUtility_canJoinUsingConstraints.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/util/TestBOpUtility_canJoinUsingConstraints.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/util/TestBOpUtility_canJoinUsingConstraints.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -46,10 +46,10 @@ import com.bigdata.bop.ImmutableBOp; import com.bigdata.bop.NV; import com.bigdata.bop.Var; -import com.bigdata.bop.BOp.Annotations; import com.bigdata.bop.ap.Predicate; import com.bigdata.bop.constraint.AND; -import com.bigdata.bop.constraint.BOpConstraint; +import com.bigdata.bop.constraint.BooleanValueExpression; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.joinGraph.rto.JoinGraph.JGraph; /** @@ -214,7 +214,7 @@ new IPredicate[] { p2 }, // path p1,// vertex new IConstraint[] { // - new NEConstant(x, new Constant<Integer>(12)), // + Constraint.wrap(new NEConstant(x, new Constant<Integer>(12))), // null // }// constraints ); @@ -240,7 +240,7 @@ * used to test the logic which decides when two predicates can join based * on variable(s) shared via a constraint. */ - static private final class MyCompareOp extends BOpConstraint { + static private final class MyCompareOp extends BooleanValueExpression { private static final long serialVersionUID = 1L; @@ -261,7 +261,7 @@ super(args, annotations); } - public boolean accept(IBindingSet bindingSet) { + public Boolean get(IBindingSet bindingSet) { throw new UnsupportedOperationException(); } @@ -272,7 +272,7 @@ * used to test the logic which decides when two predicates can join based * on variable(s) shared via a constraint. */ - static private final class NEConstant extends BOpConstraint { + static private final class NEConstant extends BooleanValueExpression { private static final long serialVersionUID = 1L; @@ -297,7 +297,7 @@ this(new BOp[] { var, value }, null/* annotations */); } - public boolean accept(IBindingSet bindingSet) { + public Boolean get(IBindingSet bindingSet) { throw new UnsupportedOperationException(); } @@ -449,8 +449,8 @@ /** * FILTER (productInstance != ?product) */ - final IConstraint c0 = new NEConstant(product, new Constant<String>( - productInstance)); + final IConstraint c0 = Constraint.wrap(new NEConstant(product, new Constant<String>( + productInstance))); /** * FILTER (?simProperty1 < (?origProperty1 + 120) && ?simProperty1 > @@ -460,7 +460,7 @@ * that each of these is represented as its own IConstraint, but I have * combined them for the purposes of these unit tests. */ - final IConstraint c1 = new AND(// + final IConstraint c1 = Constraint.wrap(new AND(// new MyCompareOp( new BOp[] { simProperty1, @@ -471,7 +471,7 @@ simProperty1, new MathBOp(origProperty1, new Constant<Integer>(120), MINUS) }, NV.asMap(new NV[] { new NV(OP, GT) }))// - ); + )); /** * FILTER (?simProperty2 < (?origProperty2 + 170) && ?simProperty2 > @@ -481,7 +481,7 @@ * that each of these is represented as its own IConstraint, but I have * combined them for the purposes of these unit tests. */ - final IConstraint c2 = new AND(// + final IConstraint c2 = Constraint.wrap(new AND(// new MyCompareOp( new BOp[] { simProperty2, @@ -492,7 +492,7 @@ simProperty2, new MathBOp(origProperty2, new Constant<Integer>(170), MINUS) }, NV.asMap(new NV[] { new NV(OP, GT) }))// - ); + )); /** The constraints on the join graph. */ final IConstraint[] constraints = new IConstraint[] { c0, c1, c2 }; Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/relation/rule/AbstractRuleTestCase.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/relation/rule/AbstractRuleTestCase.java 2011-02-22 23:36:59 UTC (rev 4227) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/relation/rule/AbstractRuleTestCase.java 2011-02-22 23:38:00 UTC (rev 4228) @@ -30,15 +30,14 @@ import java.util.Map; import junit.framework.TestCase2; -import com.bigdata.rdf.internal.IV; -import com.bigdata.rdf.internal.TermId; -import com.bigdata.rdf.internal.VTE; + import com.bigdata.bop.BOp; import com.bigdata.bop.Constant; import com.bigdata.bop.IConstraint; import com.bigdata.bop.IPredicate; import com.bigdata.bop.IVariableOrConstant; import com.bigdata.bop.Var; +import com.bigdata.bop.constraint.Constraint; import com.bigdata.bop.constraint.NE; import com.bigdata.rdf.internal.IV; import com.bigdata.rdf.internal.TermId; @@ -102,7 +101,7 @@ new P(relation, var("v"), rdfType, var("u")) // },// new IConstraint[] { - new NE(var("u"),var("x")) + Constraint.wrap(new NE(var("u"),var("x"))) } ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mrp...@us...> - 2011-02-22 23:37:08
|
Revision: 4227 http://bigdata.svn.sourceforge.net/bigdata/?rev=4227&view=rev Author: mrpersonick Date: 2011-02-22 23:36:59 +0000 (Tue, 22 Feb 2011) Log Message: ----------- refactor constraints -> value expressions Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/AND.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/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/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 Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/BooleanValueExpression.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/Constraint.java Removed Paths: ------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/BOUND.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/NOT.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/AND.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/AND.java 2011-02-22 21:13:14 UTC (rev 4226) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/AND.java 2011-02-22 23:36:59 UTC (rev 4227) @@ -26,26 +26,34 @@ import java.util.Map; -import com.bigdata.bop.BOpBase; import com.bigdata.bop.BOp; import com.bigdata.bop.IBindingSet; -import com.bigdata.bop.IConstraint; /** * Imposes the constraint <code>x AND y</code>. */ -public class AND extends BOpConstraint { +public class AND extends BooleanValueExpression { /** * */ private static final long serialVersionUID = -8146965892831895463L; + public AND(final BooleanValueExpression x, final BooleanValueExpression y) { + + this(new BOp[] { x, y }, null/*annocations*/); + + } + /** * Required deep copy constructor. */ - public AND(final BOp[] args, final Map<String, Object> annotations) { - super(args, annotations); + public AND(final BOp[] args, final Map<String, Object> anns) { + super(args, anns); + + if (args.length != 2 || args[0] == null || args[1] == null) + throw new IllegalArgumentException(); + } /** @@ -55,20 +63,15 @@ super(op); } - public AND(final IConstraint x, final IConstraint y) { - - super(new BOp[] { x, y }, null/*annocations*/); - - if (x == null || y == null) - throw new IllegalArgumentException(); - + @Override + public BooleanValueExpression get(final int i) { + return (BooleanValueExpression) super.get(i); } + + public Boolean get(final IBindingSet s) { - public boolean accept(final IBindingSet s) { + return get(0).get(s) && get(1).get(s); - return ((IConstraint) get(0)).accept(s) - && ((IConstraint) get(1)).accept(s); - } } Deleted: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/BOUND.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/BOUND.java 2011-02-22 21:13:14 UTC (rev 4226) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/BOUND.java 2011-02-22 23:36:59 UTC (rev 4227) @@ -1,73 +0,0 @@ -/* - -Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. - -Contact: - SYSTAP, LLC - 4501 Tower Road - Greensboro, NC 27410 - lic...@bi... - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -*/ -package com.bigdata.bop.constraint; - -import java.util.Map; - -import com.bigdata.bop.BOp; -import com.bigdata.bop.IBindingSet; -import com.bigdata.bop.IConstraint; -import com.bigdata.bop.IVariable; - -/** - * Imposes the constraint <code>bound(x)</code> for the variable x. - */ -public class BOUND extends BOpConstraint { - - /** - * - */ - private static final long serialVersionUID = -7408654639183330874L; - - /** - * Required deep copy constructor. - */ - public BOUND(final BOp[] args, final Map<String, Object> annotations) { - super(args, annotations); - } - - /** - * Required deep copy constructor. - */ - public BOUND(final BOUND op) { - super(op); - } - - public BOUND(final IVariable x) { - - super(new BOp[] { x }, null/*annocations*/); - - if (x == null) - throw new IllegalArgumentException(); - - } - - public boolean accept(final IBindingSet s) { - - return ((IVariable) get(0)).get(s) != null; - - } - -} Deleted: 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 2011-02-22 21:13:14 UTC (rev 4226) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/BOpConstraint.java 2011-02-22 23:36:59 UTC (rev 4227) @@ -1,66 +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 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); - } - -} Added: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/BooleanValueExpression.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/BooleanValueExpression.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/BooleanValueExpression.java 2011-02-22 23:36:59 UTC (rev 4227) @@ -0,0 +1,64 @@ +/* + +Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ +package com.bigdata.bop.constraint; + +import java.util.Map; + +import com.bigdata.bop.BOp; +import com.bigdata.bop.IBindingSet; +import com.bigdata.bop.IValueExpression; +import com.bigdata.bop.ImmutableBOp; + +/** + * Base class for boolean value expression BOps. Value expressions perform some + * evaluation on one or more value expressions as input and produce one + * boolean as output. + */ +public abstract class BooleanValueExpression extends ImmutableBOp + implements IValueExpression<Boolean> { + + /** + * + */ + private static final long serialVersionUID = 1140290634566864478L; + + /** + * Required shallow copy constructor. + */ + public BooleanValueExpression(final BOp[] args, + final Map<String, Object> anns) { + super(args, anns); + } + + /** + * Required deep copy constructor. + */ + public BooleanValueExpression(final BooleanValueExpression op) { + super(op); + } + + public abstract Boolean get(final IBindingSet bs); + +} Added: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/Constraint.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/Constraint.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/Constraint.java 2011-02-22 23:36:59 UTC (rev 4227) @@ -0,0 +1,100 @@ +/* + +Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ +package com.bigdata.bop.constraint; + +import java.util.Map; + +import org.apache.log4j.Logger; + +import com.bigdata.bop.BOp; +import com.bigdata.bop.IBindingSet; +import com.bigdata.bop.IConstraint; +import com.bigdata.bop.ImmutableBOp; + +/** + * BOpConstraint that wraps a {@link BooleanValueExpression}. + */ +public class Constraint extends ImmutableBOp implements IConstraint { + + /** + * + */ + private static final long serialVersionUID = -9144690224260823279L; + + protected static final Logger log = Logger.getLogger(Constraint.class); + + /** + * Convenience method to generate a constraint from a value expression. + */ + public static IConstraint wrap(final BooleanValueExpression ve) { + return new Constraint(ve); + } + + + public Constraint(final BooleanValueExpression x) { + + this(new BOp[] { x }, null/*annocations*/); + + } + + /** + * Required shallow copy constructor. + */ + public Constraint(final BOp[] args, + final Map<String, Object> anns) { + + super(args, anns); + + if (args.length != 1 || args[0] == null) + throw new IllegalArgumentException(); + + } + + /** + * Required deep copy constructor. + */ + public Constraint(final Constraint op) { + super(op); + } + + public boolean accept(final IBindingSet bs) { + + try { + + // evaluate the BVE operator + return ((BooleanValueExpression) get(0)).get(bs); + + } catch (Exception ex) { + + // trap the type error and filter out the solution + if (log.isInfoEnabled()) + log.info("discarding solution due to error: " + bs); + return false; + + } + + } + +} 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 2011-02-22 21:13:14 UTC (rev 4226) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/EQ.java 2011-02-22 23:36:59 UTC (rev 4227) @@ -33,19 +33,32 @@ /** * Imposes the constraint <code>x == y</code>. - * - * @author <a href="mailto:tho...@us...">Bryan Thompson</a> - * @version $Id$ */ -public class EQ extends BOpConstraint { +public class EQ extends BooleanValueExpression { - private static final long serialVersionUID = 1L; + /** + * + */ + private static final long serialVersionUID = 9207324734456820516L; + public EQ(final IVariable<?> x, final IVariable<?> y) { + + this(new BOp[] { x, y }, null/* annotations */); + + } + /** - * Required deep copy constructor. + * Required shallow copy constructor. */ public EQ(final BOp[] args, final Map<String, Object> annotations) { super(args, annotations); + + if (args.length != 2 || args[0] == null || args[1] == null) + throw new IllegalArgumentException(); + + if (args[0] == args[1]) + throw new IllegalArgumentException(); + } /** @@ -55,20 +68,8 @@ super(op); } - public EQ(final IVariable<?> x, final IVariable<?> y) { - - super(new BOp[] { x, y }, null/* annotations */); - - if (x == null || y == null) - throw new IllegalArgumentException(); - - if (x == y) - throw new IllegalArgumentException(); + public Boolean get(final IBindingSet s) { - } - - public boolean accept(final IBindingSet s) { - // get binding for "x". final IConstant<?> x = s.get((IVariable<?>) get(0)/* x */); 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 2011-02-22 21:13:14 UTC (rev 4226) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/EQConstant.java 2011-02-22 23:36:59 UTC (rev 4227) @@ -33,22 +33,29 @@ /** * Imposes the constraint <code>var == constant</code>. - * - * @author <a href="mailto:tho...@us...">Bryan Thompson</a> - * @version $Id$ */ -public class EQConstant extends BOpConstraint { +public class EQConstant extends BooleanValueExpression { - /** - * - */ - private static final long serialVersionUID = 1L; + /** + * + */ + private static final long serialVersionUID = 4619002304068158318L; + public EQConstant(final IVariable<?> x, final IConstant<?> y) { + + this(new BOp[] { x, y }, null/* annotations */); + + } + /** - * Required deep copy constructor. + * Required shallow copy constructor. */ public EQConstant(final BOp[] args, final Map<String, Object> annotations) { super(args, annotations); + + if (args.length != 2 || args[0] == null || args[1] == null) + throw new IllegalArgumentException(); + } /** @@ -58,20 +65,8 @@ super(op); } - public EQConstant(final IVariable<?> var, final IConstant<?> val) { - - super(new BOp[] { var, val }, null/*annotations*/); + public Boolean get(final IBindingSet bset) { - if (var == null) - throw new IllegalArgumentException(); - - if (val == null) - throw new IllegalArgumentException(); - - } - - public boolean accept(final IBindingSet bset) { - final IVariable<?> var = (IVariable<?>) get(0)/* var */; // get binding for the variable. Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/INBinarySearch.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/INBinarySearch.java 2011-02-22 21:13:14 UTC (rev 4226) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/INBinarySearch.java 2011-02-22 23:36:59 UTC (rev 4227) @@ -49,7 +49,6 @@ import java.util.Arrays; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import com.bigdata.bop.BOp; import com.bigdata.bop.IBindingSet; @@ -67,11 +66,11 @@ public class INBinarySearch<T> extends INConstraint<T> { /** - * - */ - private static final long serialVersionUID = 1L; + * + */ + private static final long serialVersionUID = 2251370041131847351L; - /** + /** * The variable (cached). * <p> * Note: This cache is not serialized and is compiled on demand when the @@ -154,7 +153,7 @@ } - public boolean accept(final IBindingSet bindingSet) { + public Boolean get(final IBindingSet bindingSet) { if (var == null) { Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/INConstraint.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/INConstraint.java 2011-02-22 21:13:14 UTC (rev 4226) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/INConstraint.java 2011-02-22 23:36:59 UTC (rev 4227) @@ -47,14 +47,14 @@ * {@link InGraphHashSetFilter} and also with the use of an in-memory * join against the incoming binding sets to handle SPARQL data sets. */ -abstract public class INConstraint<T> extends BOpConstraint { +abstract public class INConstraint<T> extends BooleanValueExpression { /** - * - */ - private static final long serialVersionUID = 1L; + * + */ + private static final long serialVersionUID = -774833617971700165L; - public interface Annotations extends BOpConstraint.Annotations { + public interface Annotations extends BOpBase.Annotations { /** * The variable against which the constraint is applied. @@ -74,7 +74,7 @@ /** * @param op */ - public INConstraint(BOpBase op) { + public INConstraint(final INConstraint<T> op) { super(op); } Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/INHashMap.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/INHashMap.java 2011-02-22 21:13:14 UTC (rev 4226) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/INHashMap.java 2011-02-22 23:36:59 UTC (rev 4227) @@ -66,11 +66,11 @@ public class INHashMap<T> extends INConstraint<T> { /** - * - */ - private static final long serialVersionUID = 1L; + * + */ + private static final long serialVersionUID = 8032412126003678642L; - /** + /** * The variable (cached). * <p> * Note: This cache is not serialized and is compiled on demand when the @@ -136,7 +136,7 @@ } - public boolean accept(final IBindingSet bindingSet) { + public Boolean get(final IBindingSet bindingSet) { if (var == null) { Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/NE.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/NE.java 2011-02-22 21:13:14 UTC (rev 4226) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/NE.java 2011-02-22 23:36:59 UTC (rev 4227) @@ -33,22 +33,32 @@ /** * Imposes the constraint <code>x != y</code>. - * - * @author <a href="mailto:tho...@us...">Bryan Thompson</a> - * @version $Id$ */ -public class NE extends BOpConstraint { +public class NE extends BooleanValueExpression { - /** - * - */ - private static final long serialVersionUID = 1L; + /** + * + */ + private static final long serialVersionUID = -2511708022205706034L; + public NE(final IVariable<?> x, final IVariable<?> y) { + + this(new BOp[] { x, y }, null/* annotations */); + + } + /** - * Required deep copy constructor. + * Required shallow copy constructor. */ public NE(final BOp[] args, final Map<String, Object> annotations) { super(args, annotations); + + if (args.length != 2 || args[0] == null || args[1] == null) + throw new IllegalArgumentException(); + + if (args[0] == args[1]) + throw new IllegalArgumentException(); + } /** @@ -58,20 +68,8 @@ super(op); } - public NE(final IVariable<?> x, final IVariable<?> y) { - - super(new BOp[] { x, y }, null/*annotations*/); + public Boolean get(final IBindingSet s) { - if (x == null || y == null) - throw new IllegalArgumentException(); - - if (x == y) - throw new IllegalArgumentException(); - - } - - public boolean accept(final IBindingSet s) { - // get binding for "x". final IConstant<?> x = s.get((IVariable<?>) get(0)/* x */); Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/NEConstant.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/NEConstant.java 2011-02-22 21:13:14 UTC (rev 4226) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/NEConstant.java 2011-02-22 23:36:59 UTC (rev 4227) @@ -33,22 +33,29 @@ /** * Imposes the constraint <code>var != constant</code>. - * - * @author <a href="mailto:tho...@us...">Bryan Thompson</a> - * @version $Id$ */ -public class NEConstant extends BOpConstraint { - +public class NEConstant extends BooleanValueExpression { + /** - * - */ - private static final long serialVersionUID = 1L; + * + */ + private static final long serialVersionUID = 7260967777291997075L; + public NEConstant(final IVariable<?> x, final IConstant<?> y) { + + this(new BOp[] { x, y }, null/* annotations */); + + } + /** - * Required deep copy constructor. + * Required shallow copy constructor. */ public NEConstant(final BOp[] args, final Map<String, Object> annotations) { super(args, annotations); + + if (args.length != 2 || args[0] == null || args[1] == null) + throw new IllegalArgumentException(); + } /** @@ -58,20 +65,8 @@ super(op); } - public NEConstant(final IVariable<?> var, final IConstant<?> val) { - - super(new BOp[] { var, val }, null/*annotations*/); + public Boolean get(final IBindingSet s) { - if (var == null) - throw new IllegalArgumentException(); - - if (val == null) - throw new IllegalArgumentException(); - - } - - public boolean accept(final IBindingSet s) { - // get binding for the variable. final IConstant<?> tmp = s.get((IVariable<?>) get(0)/* var */); Deleted: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/NOT.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/NOT.java 2011-02-22 21:13:14 UTC (rev 4226) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/NOT.java 2011-02-22 23:36:59 UTC (rev 4227) @@ -1,73 +0,0 @@ -/* - -Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. - -Contact: - SYSTAP, LLC - 4501 Tower Road - Greensboro, NC 27410 - lic...@bi... - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -*/ -package com.bigdata.bop.constraint; - -import java.util.Map; - -import com.bigdata.bop.BOpBase; -import com.bigdata.bop.BOp; -import com.bigdata.bop.IBindingSet; -import com.bigdata.bop.IConstraint; - -/** - * Imposes the constraint <code>!x</code>. - */ -public class NOT extends BOpConstraint { - - /** - * - */ - private static final long serialVersionUID = -5701967329003122236L; - - /** - * Required deep copy constructor. - */ - public NOT(final BOp[] args, final Map<String, Object> annotations) { - super(args, annotations); - } - - /** - * Required deep copy constructor. - */ - public NOT(final NOT op) { - super(op); - } - - public NOT(final IConstraint x) { - - super(new BOp[] { x }, null/*Annotations*/); - - if (x == null) - throw new IllegalArgumentException(); - - } - - public boolean accept(final IBindingSet s) { - - return !((IConstraint) get(0)).accept(s); - - } - -} Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/OR.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/OR.java 2011-02-22 21:13:14 UTC (rev 4226) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/constraint/OR.java 2011-02-22 23:36:59 UTC (rev 4227) @@ -1,6 +1,6 @@ /* -Copyright (C) SYSTAP, LLC 2006-2007. All rights reserved. +Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. Contact: SYSTAP, LLC @@ -26,29 +26,34 @@ import java.util.Map; -import com.bigdata.bop.BOpBase; import com.bigdata.bop.BOp; import com.bigdata.bop.IBindingSet; -import com.bigdata.bop.IConstraint; /** * Imposes the constraint <code>x OR y</code>. - * - * @author <a href="mailto:tho...@us...">Bryan Thompson</a> - * @version $Id$ */ -public class OR extends BOpConstraint { +public class OR extends BooleanValueExpression { /** - * - */ - private static final long serialVersionUID = 1L; + * + */ + private static final long serialVersionUID = 5066076800100837774L; - /** + public OR(final BooleanValueExpression x, final BooleanValueExpression y) { + + this(new BOp[] { x, y }, null/*annocations*/); + + } + + /** * Required deep copy constructor. */ - public OR(final BOp[] args, final Map<String, Object> annotations) { - super(args, annotations); + public OR(final BOp[] args, final Map<String, Object> anns) { + super(args, anns); + + if (args.length != 2 || args[0] == null || args[1] == null) + throw new IllegalArgumentException(); + } /** @@ -58,20 +63,15 @@ super(op); } - public OR(final IConstraint x, final IConstraint y) { - - super(new BOp[] { x, y }, null/*annocations*/); - - if (x == null || y == null) - throw new IllegalArgumentException(); - + @Override + public BooleanValueExpression get(final int i) { + return (BooleanValueExpression) super.get(i); } + + public Boolean get(final IBindingSet s) { - public boolean accept(final IBindingSet s) { + return get(0).get(s) || get(1).get(s); - return ((IConstraint) get(0)).accept(s) - || ((IConstraint) get(1)).accept(s); - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mrp...@us...> - 2011-02-22 21:13:21
|
Revision: 4226 http://bigdata.svn.sourceforge.net/bigdata/?rev=4226&view=rev Author: mrpersonick Date: 2011-02-22 21:13:14 +0000 (Tue, 22 Feb 2011) Log Message: ----------- added the inlining values test to the suite, and got rid of the no-inline tests entirely Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestAll.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuads.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithSids.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithoutSids.java Removed Paths: ------------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuadsWithoutInlining.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithSidsWithoutInlining.java Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestAll.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestAll.java 2011-02-22 20:57:55 UTC (rev 4225) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestAll.java 2011-02-22 21:13:14 UTC (rev 4226) @@ -86,18 +86,12 @@ // run the test suite with statement identifiers enabled. suite.addTest(TestBigdataSailWithSids.suite()); - suite.addTest(TestBigdataSailWithSidsWithoutInlining.suite()); // run the test suite without statement identifiers enabled. suite.addTest(TestBigdataSailWithoutSids.suite()); - // nestedSubquery is deprecated. -// // quad store test suite w/ nested subquery joins. -// suite.addTest(TestBigdataSailWithQuads.suite()); - // quad store test suite w/ pipeline joins. suite.addTest(TestBigdataSailWithQuads.suite()); - suite.addTest(TestBigdataSailWithQuadsWithoutInlining.suite()); // quad store in scale-out. suite.addTest(TestBigdataSailEmbeddedFederationWithQuads.suite()); Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuads.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuads.java 2011-02-22 20:57:55 UTC (rev 4225) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuads.java 2011-02-22 21:13:14 UTC (rev 4226) @@ -103,6 +103,8 @@ suite.addTestSuite(TestMultiGraphs.class); + suite.addTestSuite(TestInlineValues.class); + // The Sesame TCK, including the SPARQL test suite. { Deleted: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuadsWithoutInlining.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuadsWithoutInlining.java 2011-02-22 20:57:55 UTC (rev 4225) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuadsWithoutInlining.java 2011-02-22 21:13:14 UTC (rev 4226) @@ -1,188 +0,0 @@ -/** -Copyright (C) SYSTAP, LLC 2006-2007. All rights reserved. - -Contact: - SYSTAP, LLC - 4501 Tower Road - Greensboro, NC 27410 - lic...@bi... - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ -/* - * Created on Sep 4, 2008 - */ - -package com.bigdata.rdf.sail; - -import java.util.Properties; - -import junit.extensions.proxy.ProxyTestSuite; -import junit.framework.Test; -import junit.framework.TestSuite; - -import com.bigdata.rdf.axioms.NoAxioms; -import com.bigdata.rdf.sail.BigdataSail.Options; -import com.bigdata.rdf.sail.tck.BigdataConnectionTest; -import com.bigdata.rdf.sail.tck.BigdataSparqlTest; -import com.bigdata.rdf.sail.tck.BigdataStoreTest; -import com.bigdata.relation.AbstractResource; - -/** - * Test suite for the {@link BigdataSail} with quads enabled. The provenance - * mode is disabled. Inference is disabled. This version of the test suite uses - * the pipeline join algorithm. - * - * @author <a href="mailto:tho...@us...">Bryan Thompson</a> - * @version $Id$ - */ -public class TestBigdataSailWithQuadsWithoutInlining extends AbstractBigdataSailTestCase { - - /** - * - */ - public TestBigdataSailWithQuadsWithoutInlining() { - } - - public TestBigdataSailWithQuadsWithoutInlining(String name) { - super(name); - } - - public static Test suite() { - - final TestBigdataSailWithQuadsWithoutInlining delegate = new TestBigdataSailWithQuadsWithoutInlining(); // !!!! THIS CLASS !!!! - - /* - * Use a proxy test suite and specify the delegate. - */ - - final ProxyTestSuite suite = new ProxyTestSuite(delegate, "SAIL with Quads (pipeline joins, no inlining)"); - - // test pruning of variables not required for downstream processing. - suite.addTestSuite(TestPruneBindingSets.class); - - // misc named graph API stuff. - suite.addTestSuite(TestQuadsAPI.class); - - // SPARQL named graphs tests. - suite.addTestSuite(TestNamedGraphs.class); - - // test suite for optionals handling (left joins). - suite.addTestSuite(TestOptionals.class); - - suite.addTestSuite(TestNestedOptionals.class); - - suite.addTestSuite(TestNestedUnions.class); - - // test of the search magic predicate - suite.addTestSuite(TestSearchQuery.class); - - // high-level query tests. - suite.addTestSuite(TestQuery.class); - - // test of high-level query on a graph with statements about statements. - suite.addTestSuite(TestProvenanceQuery.class); - - // unit tests for custom evaluation of high-level query - suite.addTestSuite(TestBigdataSailEvaluationStrategyImpl.class); - - suite.addTestSuite(TestUnions.class); - - suite.addTestSuite(TestDescribe.class); - - // The Sesame TCK, including the SPARQL test suite. - { - - final TestSuite tckSuite = new TestSuite("Sesame 2.x TCK"); - - tckSuite.addTestSuite(BigdataStoreTest.LTSWithPipelineJoins.class); - - tckSuite.addTestSuite(BigdataConnectionTest.LTSWithPipelineJoins.class); - - try { - - /* - * suite() will call suiteLTSWithPipelineJoins() and then - * filter out the dataset tests, which we don't need right now - */ -// tckSuite.addTest(BigdataSparqlTest.suiteLTSWithPipelineJoins()); - tckSuite.addTest(BigdataSparqlTest.suite()); - - } catch (Exception ex) { - - throw new RuntimeException(ex); - - } - - suite.addTest(tckSuite); - - } - - return suite; - - } - - @Override - protected BigdataSail getSail(final Properties properties) { - - return new BigdataSail(properties); - - } - - public Properties getProperties() { - - final Properties properties = new Properties(super.getProperties()); -/* - properties.setProperty(Options.STATEMENT_IDENTIFIERS, "false"); - - properties.setProperty(Options.QUADS, "true"); - - properties.setProperty(Options.AXIOMS_CLASS, NoAxioms.class.getName()); -*/ - properties.setProperty(Options.QUADS_MODE, "true"); - - properties.setProperty(Options.TRUTH_MAINTENANCE, "false"); - -// properties.setProperty(AbstractResource.Options.NESTED_SUBQUERY, "false"); - - properties.setProperty(Options.INLINE_LITERALS, "false"); - - return properties; - - } - - @Override - protected BigdataSail reopenSail(BigdataSail sail) { - - final Properties properties = sail.database.getProperties(); - - if (sail.isOpen()) { - - try { - - sail.shutDown(); - - } catch (Exception ex) { - - throw new RuntimeException(ex); - - } - - } - - return getSail(properties); - - } - -} Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithSids.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithSids.java 2011-02-22 20:57:55 UTC (rev 4225) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithSids.java 2011-02-22 21:13:14 UTC (rev 4226) @@ -83,6 +83,8 @@ suite.addTestSuite(TestDescribe.class); + suite.addTestSuite(TestInlineValues.class); + return suite; } Deleted: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithSidsWithoutInlining.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithSidsWithoutInlining.java 2011-02-22 20:57:55 UTC (rev 4225) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithSidsWithoutInlining.java 2011-02-22 21:13:14 UTC (rev 4226) @@ -1,136 +0,0 @@ -/** -Copyright (C) SYSTAP, LLC 2006-2007. All rights reserved. - -Contact: - SYSTAP, LLC - 4501 Tower Road - Greensboro, NC 27410 - lic...@bi... - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ -/* - * Created on Sep 4, 2008 - */ - -package com.bigdata.rdf.sail; - -import java.util.Properties; - -import junit.extensions.proxy.ProxyTestSuite; -import junit.framework.Test; - -import com.bigdata.rdf.sail.BigdataSail.Options; - -/** - * Test suite for the {@link BigdataSail} with statement identifiers enabled. - * - * @author <a href="mailto:tho...@us...">Bryan Thompson</a> - * @version $Id$ - */ -public class TestBigdataSailWithSidsWithoutInlining extends AbstractBigdataSailTestCase { - - /** - * - */ - public TestBigdataSailWithSidsWithoutInlining() { - } - - public TestBigdataSailWithSidsWithoutInlining(String name) { - super(name); - } - - public static Test suite() { - - final TestBigdataSailWithSidsWithoutInlining delegate = new TestBigdataSailWithSidsWithoutInlining(); // !!!! THIS CLASS !!!! - - /* - * Use a proxy test suite and specify the delegate. - */ - - final ProxyTestSuite suite = new ProxyTestSuite(delegate, "SAIL with Triples (with SIDs, no inlining)"); - - // test pruning of variables not required for downstream processing. - suite.addTestSuite(TestPruneBindingSets.class); - - // test of the search magic predicate - suite.addTestSuite(TestSearchQuery.class); - - // high-level query tests. - suite.addTestSuite(TestQuery.class); - - // test of high-level query on a graph with statements about statements. - suite.addTestSuite(TestProvenanceQuery.class); - - suite.addTestSuite(TestBigdataSailEvaluationStrategyImpl.class); - - suite.addTestSuite(TestReadWriteTransactions.class); - - suite.addTestSuite(TestOrderBy.class); - - suite.addTestSuite(TestUnions.class); - - suite.addTestSuite(TestDescribe.class); - - return suite; - - } - - @Override - protected BigdataSail getSail(Properties properties) { - - return new BigdataSail(properties); - - } - - public Properties getProperties() { - - final Properties properties = new Properties(super.getProperties()); -/* - properties.setProperty(Options.STATEMENT_IDENTIFIERS, "true"); - - properties.setProperty(Options.QUADS, "false"); -*/ - properties.setProperty(Options.TRIPLES_MODE_WITH_PROVENANCE, "true"); - - properties.setProperty(Options.INLINE_LITERALS, "false"); - - return properties; - - } - - @Override - protected BigdataSail reopenSail(BigdataSail sail) { - - final Properties properties = sail.database.getProperties(); - - if (sail.isOpen()) { - - try { - - sail.shutDown(); - - } catch (Exception ex) { - - throw new RuntimeException(ex); - - } - - } - - return getSail(properties); - - } - -} Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithoutSids.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithoutSids.java 2011-02-22 20:57:55 UTC (rev 4225) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithoutSids.java 2011-02-22 21:13:14 UTC (rev 4226) @@ -79,6 +79,8 @@ suite.addTestSuite(TestDescribe.class); + suite.addTestSuite(TestInlineValues.class); + return suite; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |