From: <mrp...@us...> - 2011-02-22 20:29:57
|
Revision: 4219 http://bigdata.svn.sourceforge.net/bigdata/?rev=4219&view=rev Author: mrpersonick Date: 2011-02-22 20:29:45 +0000 (Tue, 22 Feb 2011) Log Message: ----------- refactor constraints -> value expressions Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/TestDeepCopy.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/constraints/CompareBOp.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/MathBOp.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/SameTermBOp.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-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSail.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailEvaluationStrategyImpl.java Added 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/EBVBOp.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsBoundBOp.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsInlineBOp.java 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/NotBOp.java 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/ValueExpressionBOp.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/ValueExpressionConstraint.java Removed Paths: ------------- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsInline.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsLiteral.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/TestDeepCopy.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/TestDeepCopy.java 2011-02-21 22:01:49 UTC (rev 4218) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/TestDeepCopy.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -45,10 +45,16 @@ import com.bigdata.bop.constraint.NE; import com.bigdata.bop.constraint.NEConstant; import com.bigdata.bop.constraint.OR; +import com.bigdata.rdf.internal.constraints.AndBOp; import com.bigdata.rdf.internal.constraints.CompareBOp; -import com.bigdata.rdf.internal.constraints.IsInline; -import com.bigdata.rdf.internal.constraints.IsLiteral; +import com.bigdata.rdf.internal.constraints.EBVBOp; +import com.bigdata.rdf.internal.constraints.IsBoundBOp; +import com.bigdata.rdf.internal.constraints.IsInlineBOp; +import com.bigdata.rdf.internal.constraints.IsLiteralBOp; 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.rules.RejectAnythingSameAsItself; import com.bigdata.rdf.spo.SPOPredicate; import com.bigdata.rdf.spo.SPOStarJoin; @@ -99,9 +105,15 @@ com.bigdata.rdf.magic.MagicPredicate.class,// // com.bigdata.rdf.internal.constraint CompareBOp.class,// - IsInline.class,// - IsLiteral.class,// + IsInlineBOp.class,// + IsLiteralBOp.class,// MathBOp.class,// + AndBOp.class, + EBVBOp.class, + IsBoundBOp.class, + NotBOp.class, + OrBOp.class, + SameTermBOp.class, // com.bigdata.rdf.inf RejectAnythingSameAsItself.class, 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-21 22:01:49 UTC (rev 4218) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSDBooleanIV.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -39,11 +39,11 @@ */ private static final long serialVersionUID = 1L; - static public transient final XSDBooleanIV<BigdataLiteral> TRUE = new XSDBooleanIV<BigdataLiteral>( - true); + static public transient final XSDBooleanIV<BigdataLiteral> TRUE = + new XSDBooleanIV<BigdataLiteral>(true); - static public transient final XSDBooleanIV<BigdataLiteral> FALSE = new XSDBooleanIV<BigdataLiteral>( - false); + static public transient final XSDBooleanIV<BigdataLiteral> FALSE = + new XSDBooleanIV<BigdataLiteral>(false); private final boolean value; Added: 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 (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/AndBOp.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -0,0 +1,114 @@ +/* + +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.rdf.error.SparqlTypeErrorException; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.XSDBooleanIV; + +/** + * Imposes the constraint <code>x AND y</code>. + */ +public class AndBOp extends ValueExpressionBOp + implements IValueExpression<IV> { + + /** + * + */ + private static final long serialVersionUID = -1217715173822304819L; + + public AndBOp(final IValueExpression<IV> x, final IValueExpression<IV> y) { + + this(new BOp[] { x, y }, null/*annocations*/); + + } + + /** + * Required shallow copy constructor. + */ + public AndBOp(final BOp[] args, final Map<String, Object> anns) { + + super(args, anns); + + if (args.length != 2 || args[0] == null || args[1] == null) + throw new IllegalArgumentException(); + + } + + /** + * Required deep copy constructor. + */ + public AndBOp(final AndBOp op) { + super(op); + } + + /** + * Follows semantics from SPARQL spec - "Testing Values". + * <p> + * see http://www.w3.org/TR/rdf-sparql-query/#tests section 11.2 + */ + public boolean accept(final IBindingSet bs) { + + XSDBooleanIV left, right; + + try { + left = (XSDBooleanIV) get(0).get(bs); + } catch (SparqlTypeErrorException ex) { + left = null; + } + + try { + right = (XSDBooleanIV) get(1).get(bs); + } catch (SparqlTypeErrorException ex) { + right = null; + } + + // special error handling per the SPARQL spec + if (left == null || right == null) { + // if one or the other is false, return false + if (left != null && !left.booleanValue()) + return false; + if (right != null && !right.booleanValue()) + return false; + // all other cases, throw a type error + throw new SparqlTypeErrorException(); + } + + return left.booleanValue() && right.booleanValue(); + + } + + 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/CompareBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/CompareBOp.java 2011-02-21 22:01:49 UTC (rev 4218) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/CompareBOp.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -26,6 +26,7 @@ import java.util.Map; +import org.apache.log4j.Logger; import org.openrdf.query.algebra.Compare.CompareOp; import com.bigdata.bop.BOp; @@ -33,21 +34,26 @@ import com.bigdata.bop.IValueExpression; import com.bigdata.bop.NV; import com.bigdata.bop.PipelineOp; -import com.bigdata.bop.constraint.BOpConstraint; +import com.bigdata.rdf.error.SparqlTypeErrorException; import com.bigdata.rdf.internal.IV; import com.bigdata.rdf.internal.IVUtility; +import com.bigdata.rdf.internal.XSDBooleanIV; /** * Use inline terms to perform numerical comparison operations. * * @see IVUtility#numericalCompare(IV, IV) */ -public class CompareBOp extends BOpConstraint { +public class CompareBOp extends ValueExpressionBOp + implements IValueExpression<IV> { - /** - * - */ - private static final long serialVersionUID = 1L; + /** + * + */ + private static final long serialVersionUID = 5661497748051783499L; + + protected static final Logger log = Logger.getLogger(CompareBOp.class); + public interface Annotations extends PipelineOp.Annotations { @@ -58,12 +64,27 @@ } + public CompareBOp(final IValueExpression<IV> left, + final IValueExpression<IV> right, final CompareOp op) { + + this(new BOp[] { left, right }, NV.asMap(new NV(Annotations.OP, op))); + + } + /** * Required shallow copy constructor. */ - public CompareBOp(final BOp[] values, - final Map<String, Object> annotations) { - super(values, annotations); + public CompareBOp(final BOp[] args, final Map<String, Object> anns) { + + super(args, anns); + + if (args.length != 2 || args[0] == null || args[1] == null + || getProperty(Annotations.OP) == null) { + + throw new IllegalArgumentException(); + + } + } /** @@ -73,32 +94,32 @@ super(op); } - public CompareBOp(final IValueExpression<IV> left, - final IValueExpression<IV> right, final CompareOp op) { - - super(new BOp[] { left, right }, NV.asMap(new NV(Annotations.OP, op))); - - if (left == null || right == null || op == null) - throw new IllegalArgumentException(); - - } - public boolean accept(final IBindingSet s) { - final IV left = ((IValueExpression<IV>) get(0)).get(s); - final IV right = ((IValueExpression<IV>) get(1)).get(s); - + final IV left = get(0).get(s); + final IV right = get(1).get(s); + + // not yet bound if (left == null || right == null) -// return true; // not yet bound. - return false; // no longer allow unbound values + throw new SparqlTypeErrorException(); final CompareOp op = (CompareOp) getProperty(Annotations.OP); - if (left.isTermId() && right.isTermId() && - (op == CompareOp.EQ || op == CompareOp.NE)) { - return _accept(left.compareTo(right)); + if (left.isTermId() && right.isTermId()) { + if (op == CompareOp.EQ || op == CompareOp.NE) { + return _accept(left.compareTo(right)); + } else { + if (log.isInfoEnabled()) + log.info("cannot compare: " + + left + " " + op + " " + right); + + throw new SparqlTypeErrorException(); + } } + /* + * This code is bad. + */ if (!IVUtility.canNumericalCompare(left) || !IVUtility.canNumericalCompare(right)) { if (op == CompareOp.EQ) { @@ -106,8 +127,11 @@ } else if (op == CompareOp.NE) { return true; } else { - throw new NotNumericalException("cannot numerical compare: " + if (log.isInfoEnabled()) + log.info("cannot numerical compare: " + left + " " + op + " " + right); + + throw new SparqlTypeErrorException(); } } @@ -121,7 +145,7 @@ switch(op) { case EQ: - return compare == 0; + return compare == 0; case NE: return compare != 0; case GT: @@ -137,7 +161,13 @@ } } - + + public IV get(final IBindingSet bs) { + + return accept(bs) ? XSDBooleanIV.TRUE : XSDBooleanIV.FALSE; + + } + public static class NotNumericalException extends RuntimeException { /** Added: 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 (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/EBVBOp.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -0,0 +1,130 @@ +/* + +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 com.bigdata.bop.BOp; +import com.bigdata.bop.IBindingSet; +import com.bigdata.bop.IValueExpression; +import com.bigdata.rdf.error.SparqlTypeErrorException; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.XSDBooleanIV; + +/** + * Calculates the "effective boolean value" of an IValueExpression. See the + * SPARQL spec for details. + */ +public class EBVBOp extends ValueExpressionBOp + implements IValueExpression<IV> { + + /** + * + */ + private static final long serialVersionUID = -5701967329003122236L; + + public EBVBOp(final IValueExpression<IV> x) { + + this(new BOp[] { x }, null/*Annotations*/); + + } + + /** + * Required shallow copy constructor. + */ + public EBVBOp(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 EBVBOp(final EBVBOp op) { + super(op); + } + + /** + * 11.2.2 Effective Boolean Value (EBV) + * + * Effective boolean value is used to calculate the arguments to the logical + * functions logical-and, logical-or, and fn:not, as well as evaluate the + * result of a FILTER expression. + * + * The XQuery Effective Boolean Value rules rely on the definition of + * XPath's fn:boolean. The following rules reflect the rules for fn:boolean + * applied to the argument types present in SPARQL Queries: + * + * The EBV of any literal whose type is xsd:boolean or numeric is false if + * the lexical form is not valid for that datatype (e.g. + * "abc"^^xsd:integer). + * + * If the argument is a typed literal with a datatype of xsd:boolean, the + * EBV is the value of that argument. + * + * If the argument is a plain literal or a typed literal with a datatype of + * xsd:string, the EBV is false if the operand value has zero length; + * otherwise the EBV is true. + * + * If the argument is a numeric type or a typed literal with a datatype + * derived from a numeric type, the EBV is false if the operand value is NaN + * or is numerically equal to zero; otherwise the EBV is true. + * + * All other arguments, including unbound arguments, produce a type error. + * + * An EBV of true is represented as a typed literal with a datatype of + * xsd:boolean and a lexical value of "true"; an EBV of false is represented + * as a typed literal with a datatype of xsd:boolean and a lexical value of + * "false". + */ + public boolean accept(final IBindingSet bs) { + + final IV iv = get(0).get(bs); + + if (iv instanceof XSDBooleanIV) { + return ((XSDBooleanIV) iv).booleanValue(); + } + + throw new SparqlTypeErrorException(); + + } + + /** + * We know we can strengthen the return type on this one since its whole + * purpose is to evaluate the effective boolean value of a wrapped + * expression. + */ + @Override + public XSDBooleanIV 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/IsBoundBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsBoundBOp.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsBoundBOp.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -0,0 +1,84 @@ +/* + +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 com.bigdata.bop.BOp; +import com.bigdata.bop.IBindingSet; +import com.bigdata.bop.IValueExpression; +import com.bigdata.bop.IVariable; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.XSDBooleanIV; + +/** + * Imposes the constraint <code>bound(x)</code> for the variable x. + */ +public class IsBoundBOp extends ValueExpressionBOp + implements IValueExpression<IV> { + + /** + * + */ + private static final long serialVersionUID = -7408654639183330874L; + + public IsBoundBOp(final IVariable<IV> x) { + + this(new BOp[] { x }, null/*annocations*/); + + } + + /** + * Required shallow copy constructor. + */ + public IsBoundBOp(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 IsBoundBOp(final IsBoundBOp op) { + super(op); + } + + public boolean accept(final IBindingSet s) { + + return get(0).get(s) != null; + + } + + public IV get(final IBindingSet bs) { + + return accept(bs) ? XSDBooleanIV.TRUE : XSDBooleanIV.FALSE; + + } + +} Deleted: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsInline.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsInline.java 2011-02-21 22:01:49 UTC (rev 4218) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsInline.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -1,102 +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 - -*/ -package com.bigdata.rdf.internal.constraints; - -import java.util.Map; - -import com.bigdata.bop.BOp; -import com.bigdata.bop.IBindingSet; -import com.bigdata.bop.IConstant; -import com.bigdata.bop.IVariable; -import com.bigdata.bop.NV; -import com.bigdata.bop.PipelineOp; -import com.bigdata.bop.constraint.BOpConstraint; -import com.bigdata.rdf.internal.IV; - -/** - * Imposes the constraint <code>isInline(x)</code>. - */ -public class IsInline extends BOpConstraint { - - /** - * - */ - private static final long serialVersionUID = 3125106876006900339L; - - public interface Annotations extends PipelineOp.Annotations { - - /** - * If true, only accept variable bindings for {@link #x} that have an - * inline internal value {@link IV}. Otherwise only accept variable bindings - * that are not inline in the statement indices. - * <p> - * @see IV#isInline() - */ - String INLINE = IsInline.class.getName() + ".inline"; - - } - - /** - * Required shallow copy constructor. - */ - public IsInline(final BOp[] values, - final Map<String, Object> annotations) { - super(values, annotations); - } - - /** - * Required deep copy constructor. - */ - public IsInline(final IsInline op) { - super(op); - } - - public IsInline(final IVariable<IV> x, final boolean inline) { - - super(new BOp[] { x }, NV.asMap(new NV(Annotations.INLINE, inline))); - - if (x == null) - throw new IllegalArgumentException(); - - } - - public boolean accept(IBindingSet s) { - - // get binding for "x". - final IConstant<IV> x = s.get((IVariable<IV>) get(0)/*x*/); - - if (x == null) - return true; // not yet bound. - - final IV iv = x.get(); - - final boolean inline = - (Boolean) getRequiredProperty(Annotations.INLINE); - - return iv.isInline() == inline; - - } - -} Copied: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsInlineBOp.java (from rev 4196, branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsInline.java) =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsInlineBOp.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsInlineBOp.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -0,0 +1,109 @@ +/* + +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.bop.NV; +import com.bigdata.bop.PipelineOp; +import com.bigdata.rdf.error.SparqlTypeErrorException; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.XSDBooleanIV; + +/** + * Imposes the constraint <code>isInline(x)</code>. + */ +public class IsInlineBOp extends ValueExpressionBOp + implements IValueExpression<IV> { + + /** + * + */ + private static final long serialVersionUID = 3125106876006900339L; + + public interface Annotations extends PipelineOp.Annotations { + + /** + * If true, only accept variable bindings for {@link #x} that have an + * inline internal value {@link IV}. Otherwise only accept variable bindings + * that are not inline in the statement indices. + * <p> + * @see IV#isInline() + */ + String INLINE = IsInlineBOp.class.getName() + ".inline"; + + } + + public IsInlineBOp(final IVariable<IV> x, final boolean inline) { + + this(new BOp[] { x }, NV.asMap(new NV(Annotations.INLINE, inline))); + + } + + /** + * Required shallow copy constructor. + */ + public IsInlineBOp(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 IsInlineBOp(final IsInlineBOp op) { + super(op); + } + + public boolean accept(final IBindingSet bs) { + + final boolean inline = + (Boolean) getRequiredProperty(Annotations.INLINE); + + final IV iv = get(0).get(bs); + + // not yet bound + if (iv == null) + throw new SparqlTypeErrorException(); + + return iv.isInline() == inline; + + } + + public IV get(final IBindingSet bs) { + + return accept(bs) ? XSDBooleanIV.TRUE : XSDBooleanIV.FALSE; + + } + +} Deleted: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsLiteral.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsLiteral.java 2011-02-21 22:01:49 UTC (rev 4218) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsLiteral.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -1,85 +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 - -*/ -package com.bigdata.rdf.internal.constraints; - -import java.util.Map; - -import com.bigdata.bop.BOp; -import com.bigdata.bop.IBindingSet; -import com.bigdata.bop.IConstant; -import com.bigdata.bop.IVariable; -import com.bigdata.bop.NV; -import com.bigdata.bop.constraint.BOpConstraint; -import com.bigdata.rdf.internal.IV; - -/** - * Imposes the constraint <code>isLiteral(x)</code>. - */ -public class IsLiteral extends BOpConstraint { - - /** - * - */ - private static final long serialVersionUID = 3125106876006900339L; - - /** - * Required shallow copy constructor. - */ - public IsLiteral(final BOp[] values, - final Map<String, Object> annotations) { - super(values, annotations); - } - - /** - * Required deep copy constructor. - */ - public IsLiteral(final IsLiteral op) { - super(op); - } - - public IsLiteral(final IVariable<IV> x) { - - super(new BOp[] { x }, null/*annocations*/); - - if (x == null) - throw new IllegalArgumentException(); - - } - - public boolean accept(IBindingSet s) { - - // get binding for "x". - final IConstant<IV> x = s.get((IVariable<IV>) get(0)/*x*/); - - if (x == null) - return true; // not yet bound. - - final IV iv = x.get(); - - return iv.isLiteral(); - - } - -} Copied: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsLiteralBOp.java (from rev 4196, branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsLiteral.java) =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsLiteralBOp.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/IsLiteralBOp.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -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>isLiteral(x)</code>. + */ +public class IsLiteralBOp extends ValueExpressionBOp + implements IValueExpression<IV> { + + /** + * + */ + private static final long serialVersionUID = 3125106876006900339L; + + public IsLiteralBOp(final IVariable<IV> x) { + + this(new BOp[] { x }, null/*annocations*/); + + } + + /** + * Required shallow copy constructor. + */ + public IsLiteralBOp(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 IsLiteralBOp(final IsLiteralBOp op) { + super(op); + } + + public boolean accept(IBindingSet bs) { + + final IV iv = get(0).get(bs); + + // not yet bound + if (iv == null) + throw new SparqlTypeErrorException(); + + return iv.isLiteral(); + + } + + 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/MathBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/MathBOp.java 2011-02-21 22:01:49 UTC (rev 4218) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/MathBOp.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -32,6 +32,7 @@ import com.bigdata.bop.IValueExpression; import com.bigdata.bop.ImmutableBOp; import com.bigdata.bop.NV; +import com.bigdata.rdf.error.SparqlTypeErrorException; import com.bigdata.rdf.internal.IV; import com.bigdata.rdf.internal.IVUtility; @@ -40,7 +41,7 @@ * operation to be applied to the operands is specified by the * {@link Annotations#OP} annotation. */ -final public class MathBOp extends ImmutableBOp +final public class MathBOp extends ValueExpressionBOp implements IValueExpression<IV> { /** @@ -62,14 +63,20 @@ } /** - * Required deep copy constructor. * + * @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 MathBOp op) { + public MathBOp(final IValueExpression<IV> left, + final IValueExpression<IV> right, final MathOp op) { - super(op); - + this(new BOp[] { left, right }, NV.asMap(new NV(Annotations.OP, op))); + } /** @@ -94,37 +101,35 @@ } /** + * Required deep copy constructor. * - * @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<IV> left, - final IValueExpression<IV> right, final MathOp op) { + public MathBOp(final MathBOp op) { - this(new BOp[] { left, right }, NV.asMap(new NV(Annotations.OP, op))); - + super(op); + } -// /** -// * Clone is overridden to reduce heap churn. -// */ -// final public Math clone() { -// -// return this; -// -// } + final public IV get(final IBindingSet bs) { + + final IV left = left().get(bs); + final IV right = right().get(bs); + + // not yet bound + if (left == null || right == null) + throw new SparqlTypeErrorException(); + + return IVUtility.numericalMath(left, right, op()); + } + public IValueExpression<IV> left() { - return (IValueExpression<IV>) get(0); + return get(0); } public IValueExpression<IV> right() { - return (IValueExpression<IV>) get(1); + return get(1); } public MathOp op() { @@ -156,11 +161,10 @@ final public boolean equals(final IValueExpression<IV> o) { - if(!(o instanceof MathBOp)) { + if(!(o instanceof MathBOp)) { // incomparable types. return false; } - return equals((MathBOp) o); } @@ -172,39 +176,18 @@ private int hash = 0; public int hashCode() { - + int h = hash; - if (h == 0) { - final int n = arity(); - for (int i = 0; i < n; i++) { - h = 31 * h + get(i).hashCode(); - } - h = 31 * h + op().hashCode(); - hash = h; - } - return h; - + } - final public IV get(final IBindingSet bindingSet) { - - final IV left = left().get(bindingSet); - final IV right = right().get(bindingSet); - - if (left == null || right == null) - return null; - - return IVUtility.numericalMath(left, right, op()); - - } - } Added: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/NotBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/NotBOp.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/NotBOp.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -0,0 +1,85 @@ +/* + +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 com.bigdata.bop.BOp; +import com.bigdata.bop.IBindingSet; +import com.bigdata.bop.IValueExpression; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.XSDBooleanIV; + +/** + * Imposes the constraint <code>!x</code>. + */ +public class NotBOp extends ValueExpressionBOp + implements IValueExpression<IV> { + + /** + * + */ + private static final long serialVersionUID = -5701967329003122236L; + + public NotBOp(final IValueExpression<IV> x) { + + this(new BOp[] { x }, null/*Annotations*/); + + } + + /** + * Required shallow copy constructor. + */ + public NotBOp(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 NotBOp(final NotBOp op) { + super(op); + } + + public boolean accept(final IBindingSet bs) { + + final XSDBooleanIV iv = (XSDBooleanIV) get(0).get(bs); + + return !iv.booleanValue(); + + } + + 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/OrBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/OrBOp.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/OrBOp.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -0,0 +1,114 @@ +/* + +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.rdf.error.SparqlTypeErrorException; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.XSDBooleanIV; + +/** + * Imposes the constraint <code>x OR y</code>. + */ +public class OrBOp extends ValueExpressionBOp + implements IValueExpression<IV> { + + /** + * + */ + private static final long serialVersionUID = 610253427197564102L; + + public OrBOp(final IValueExpression<IV> x, final IValueExpression<IV> y) { + + this(new BOp[] { x, y }, null/*annocations*/); + + } + + /** + * Required shallow copy constructor. + */ + public OrBOp(final BOp[] args, final Map<String, Object> anns) { + + super(args, anns); + + if (args.length != 2 || args[0] == null || args[1] == null) + throw new IllegalArgumentException(); + + } + + /** + * Required deep copy constructor. + */ + public OrBOp(final OrBOp op) { + super(op); + } + + /** + * Follows semantics from SPARQL spec - "Testing Values". + * <p> + * see http://www.w3.org/TR/rdf-sparql-query/#tests section 11.2 + */ + public boolean accept(final IBindingSet bs) { + + XSDBooleanIV left, right; + + try { + left = (XSDBooleanIV) get(0).get(bs); + } catch (SparqlTypeErrorException ex) { + left = null; + } + + try { + right = (XSDBooleanIV) get(1).get(bs); + } catch (SparqlTypeErrorException ex) { + right = null; + } + + // special error handling per the SPARQL spec + if (left == null || right == null) { + // if one or the other is true, return true + if (left != null && left.booleanValue()) + return true; + if (right != null && right.booleanValue()) + return true; + // all other cases, throw a type error + throw new SparqlTypeErrorException(); + } + + return left.booleanValue() || right.booleanValue(); + + } + + 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/SameTermBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/SameTermBOp.java 2011-02-21 22:01:49 UTC (rev 4218) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/SameTermBOp.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -26,33 +26,41 @@ import java.util.Map; -import org.openrdf.query.algebra.Compare.CompareOp; - import com.bigdata.bop.BOp; import com.bigdata.bop.IBindingSet; import com.bigdata.bop.IValueExpression; -import com.bigdata.bop.NV; -import com.bigdata.bop.PipelineOp; -import com.bigdata.bop.constraint.BOpConstraint; +import com.bigdata.rdf.error.SparqlTypeErrorException; import com.bigdata.rdf.internal.IV; -import com.bigdata.rdf.internal.IVUtility; +import com.bigdata.rdf.internal.XSDBooleanIV; /** * Compare two terms for exact equality. */ -public class SameTermBOp extends BOpConstraint { +public class SameTermBOp extends ValueExpressionBOp + implements IValueExpression<IV> { /** * */ private static final long serialVersionUID = 1L; + public SameTermBOp(final IValueExpression<IV> left, + final IValueExpression<IV> right) { + + this(new BOp[] { left, right }, null); + + } + /** * Required shallow copy constructor. */ - public SameTermBOp(final BOp[] values, - final Map<String, Object> annotations) { - super(values, annotations); + public SameTermBOp(final BOp[] args, final Map<String, Object> anns) { + + super(args, anns); + + if (args.length != 2 || args[0] == null || args[1] == null) + throw new IllegalArgumentException(); + } /** @@ -62,26 +70,23 @@ super(op); } - public SameTermBOp(final IValueExpression<IV> left, - final IValueExpression<IV> right) { - - super(new BOp[] { left, right }, null); + public boolean accept(final IBindingSet bs) { - if (left == null || right == null) - throw new IllegalArgumentException(); + final IV left = get(0).get(bs); + final IV right = get(1).get(bs); - } - - public boolean accept(final IBindingSet s) { - - final IV left = ((IValueExpression<IV>) get(0)).get(s); - final IV right = ((IValueExpression<IV>) get(1)).get(s); - + // not yet bound if (left == null || right == null) - return true; // not yet bound. + throw new SparqlTypeErrorException(); return left.equals(right); } + 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/ValueExpressionBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/ValueExpressionBOp.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/ValueExpressionBOp.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -0,0 +1,66 @@ +/* + +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 com.bigdata.bop.BOp; +import com.bigdata.bop.IValueExpression; +import com.bigdata.bop.ImmutableBOp; +import com.bigdata.rdf.internal.IV; + +/** + * Base class for RDF value expression BOps. Value expressions perform some + * evaluation on one or more value expressions as input and produce one + * value expression as output (boolean, numeric value, etc.) + */ +public abstract class ValueExpressionBOp extends ImmutableBOp + implements IValueExpression<IV> { + + /** + * + */ + private static final long serialVersionUID = -7068219781217676085L; + + /** + * Required shallow copy constructor. + */ + public ValueExpressionBOp(final BOp[] args, final Map<String, Object> anns) { + super(args, anns); + } + + /** + * Required deep copy constructor. + */ + public ValueExpressionBOp(final ValueExpressionBOp op) { + super(op); + } + + @Override + public IValueExpression<IV> get(final int i) { + return (IValueExpression<IV>) super.get(i); + } + +} Added: 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 (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/ValueExpressionConstraint.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -0,0 +1,109 @@ +/* + +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/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-21 22:01:49 UTC (rev 4218) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/bop/rdf/joinGraph/TestJoinGraphOnBSBMData.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -12,18 +12,22 @@ import com.bigdata.bop.Constant; import com.bigdata.bop.IConstraint; import com.bigdata.bop.IPredicate; +import com.bigdata.bop.IValueExpression; 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.constraint.NEConstant; import com.bigdata.bop.engine.QueryLog; import com.bigdata.bop.joinGraph.rto.JoinGraph; import com.bigdata.journal.ITx; import com.bigdata.journal.Journal; +import com.bigdata.rdf.internal.IV; import com.bigdata.rdf.internal.XSDIntIV; import com.bigdata.rdf.internal.constraints.CompareBOp; 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.model.BigdataURI; import com.bigdata.rdf.model.BigdataValue; import com.bigdata.rdf.model.BigdataValueFactory; @@ -380,15 +384,14 @@ // the vertices of the join graph (the predicates). preds = new IPredicate[] { p0, p1, p2, p3, p4, p5, p6 }; - // the constraints on the join graph. - constraints = new IConstraint[] { + final IValueExpression[] ves = new IValueExpression[] { /* * FILTER * (<http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances * /dataFromProducer1092/Product53999> != ?product) */ - new NEConstant(product, new Constant(product53999.getIV())), // + new NotBOp(new SameTermBOp(product, new Constant(product53999.getIV()))), // /* * FILTER (?simProperty1 < (?origProperty1 + 120) && @@ -431,6 +434,12 @@ CompareOp.GT) })),// }; + + // 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]); + } } 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-21 22:01:49 UTC (rev 4218) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/constraints/TestInlineConstraints.java 2011-02-22 20:29:45 UTC (rev 4219) @@ -28,23 +28,39 @@ package com.bigdata.rdf.internal.constraints; import java.util.GregorianCalendar; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicInteger; import javax.xml.datatype.XMLGregorianCalendar; +import org.apache.log4j.Logger; import org.openrdf.model.vocabulary.RDF; +import org.openrdf.query.QueryEvaluationException; import org.openrdf.query.algebra.Compare.CompareOp; import org.openrdf.query.algebra.MathExpr.MathOp; +import com.bigdata.bop.BOp; +import com.bigdata.bop.BOpUtility; 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.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.engine.IRunningQuery; +import com.bigdata.bop.engine.QueryEngine; +import com.bigdata.bop.fed.QueryEngineFactory; import com.bigdata.bop.joinGraph.IEvaluationPlan; import com.bigdata.bop.joinGraph.IEvaluationPlanFactory; import com.bigdata.bop.joinGraph.fast.DefaultEvaluationPlanFactory2; +import com.bigdata.btree.IRangeQuery; import com.bigdata.rdf.internal.IV; import com.bigdata.rdf.internal.IVUtility; import com.bigdata.rdf.model.BigdataLiteral; @@ -53,15 +69,23 @@ import com.bigdata.rdf.model.BigdataValueFactory; import com.bigdata.rdf.rio.StatementBuffer; import com.bigdata.rdf.rules.RuleContextEnum; +import com.bigdata.rdf.sail.BigdataSail; +import com.bigdata.rdf.sail.Rule2BOpUtility; +import com.bigdata.rdf.sail.sop.SOp2BOpUtility; +import com.bigdata.rdf.sail.sop.UnsupportedOperatorException; import com.bigdata.rdf.spo.SPOPredicate; import com.bigdata.rdf.store.AbstractTripleStore; import com.bigdata.rdf.store.ProxyTestCase; +import com.bigdata.relation.accesspath.ElementFilter; +import com.bigdata.relation.accesspath.IAsynchronousIterator; import com.bigdata.relation.rule.IRule; import com.bigdata.relation.rule.Rule; import com.bigdata.relation.rule.eval.ActionEnum; import com.bigdata.relation.rule.eval.IJoinNexus; import com.bigdata.relation.rule.eval.IJoinNexusFactory; import com.bigdata.relation.rule.eval.ISolution; +import com.bigdata.striterator.ChunkedWrappedIterator; +import com.bigdata.striterator.Dechunkerator; import com.bigdata.striterator.IChunkedOrderedIterator; import com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl; @@ -71,6 +95,8 @@ */ public class TestInlineConstraints extends ProxyTestCase { + protected static final Logger log = Logger.getLogger(TestInlineConstraints.class); + /** * */ @@ -85,6 +111,13 @@ super(name); } + @Override + public Properties getProperties() { + final Properties props = super.getProperties(); + props.setProperty(BigdataSail.Options.INLINE_DATE_TIMES, "true"); + return props; + } + public void testGT() { // store with no owl:sameAs closure @@ -142,25 +175,27 @@ final IRule rule = new Rule("test_greater_than", null, // head new IPredicate[] { - new SPOPredicate(SPO, s, type, x), - new SPOPredicate(SPO, s, age, a) + toPredicate(db, s, type, x), + toPredicate(db, s, age, a) }, // constraints on the rule. new IConstraint[] { - new CompareBOp(a, new Constant<IV>(_35.getIV()), CompareOp.GT) - }); + ValueExpressionConstraint.wrap(new CompareBOp(a, new Constant<IV>(_35.getIV()), CompareOp.GT)) + } + ); try { int numSolutions = 0; - IChunkedOrderedIterator<ISolution> solutions = runQuery(db, rule); + final IChunkedOrderedIterator<IBindingSet> solutions = runQuery(db, rule); while (solutions.hasNext()) { - ISolution solution = solutions.next(); + final IBindingSet bs = solutions.next(); - IBindingSet bs = solution.getBindingSet(); + ... [truncated message content] |