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. |