From: <mrp...@us...> - 2011-06-06 21:27:24
|
Revision: 4635 http://bigdata.svn.sourceforge.net/bigdata/?rev=4635&view=rev Author: mrpersonick Date: 2011-06-06 21:27:16 +0000 (Mon, 06 Jun 2011) Log Message: ----------- working through test failures related to lex joins Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/join/PipelineJoin.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/IVUtility.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/DatatypeBOp.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/lexicon/LexiconRelation.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataURIImpl.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/tck/BigdataSparqlTest.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/FalseBOp.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/TrueBOp.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-06-06 17:37:43 UTC (rev 4634) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/join/PipelineJoin.java 2011-06-06 21:27:16 UTC (rev 4635) @@ -65,6 +65,7 @@ import com.bigdata.relation.IRelation; import com.bigdata.relation.accesspath.AbstractUnsynchronizedArrayBuffer; import com.bigdata.relation.accesspath.AccessPath; +import com.bigdata.relation.accesspath.ArrayAccessPath; import com.bigdata.relation.accesspath.BlockingBuffer; import com.bigdata.relation.accesspath.BufferClosedException; import com.bigdata.relation.accesspath.IAccessPath; @@ -2016,6 +2017,14 @@ */ public int compareTo(final AccessPathTask o) { + /* + * Just go ahead and run the ArrayAccessPaths first. + */ + if (accessPath instanceof ArrayAccessPath) + return -1; + if (o.accessPath instanceof ArrayAccessPath) + return 1; + return BytesUtil.compareBytes(getFromKey(), o.getFromKey()); } Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/IVUtility.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/IVUtility.java 2011-06-06 17:37:43 UTC (rev 4634) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/IVUtility.java 2011-06-06 21:27:16 UTC (rev 4635) @@ -29,14 +29,21 @@ import java.math.BigDecimal; import java.math.BigInteger; +import java.math.RoundingMode; import java.util.ArrayList; import java.util.UUID; import org.apache.log4j.Logger; +import org.openrdf.model.Literal; +import org.openrdf.model.URI; +import org.openrdf.model.datatypes.XMLDatatypeUtil; +import org.openrdf.model.vocabulary.XMLSchema; +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; import com.bigdata.btree.keys.IKeyBuilder; import com.bigdata.btree.keys.KeyBuilder; import com.bigdata.rawstore.Bytes; +import com.bigdata.rdf.error.SparqlTypeErrorException; import com.bigdata.rdf.internal.constraints.MathBOp.MathOp; import com.bigdata.rdf.model.BigdataBNode; import com.bigdata.rdf.model.BigdataLiteral; @@ -169,6 +176,74 @@ } + public static IV literalMath(final Literal l1, final Literal l2, + final MathOp op) + { + final URI dt1 = l1.getDatatype(); + final URI dt2 = l2.getDatatype(); + + // Only numeric value can be used in math expressions + if (dt1 == null || !XMLDatatypeUtil.isNumericDatatype(dt1)) { + throw new IllegalArgumentException("Not a number: " + l1); + } + if (dt2 == null || !XMLDatatypeUtil.isNumericDatatype(dt2)) { + throw new IllegalArgumentException("Not a number: " + l2); + } + + // Determine most specific datatype that the arguments have in common, + // choosing from xsd:integer, xsd:decimal, xsd:float and xsd:double as + // per the SPARQL/XPATH spec + URI commonDatatype; + + if (dt1.equals(XMLSchema.DOUBLE) || dt2.equals(XMLSchema.DOUBLE)) { + commonDatatype = XMLSchema.DOUBLE; + } else if (dt1.equals(XMLSchema.FLOAT) || dt2.equals(XMLSchema.FLOAT)) { + commonDatatype = XMLSchema.FLOAT; + } else if (dt1.equals(XMLSchema.DECIMAL) || dt2.equals(XMLSchema.DECIMAL)) { + commonDatatype = XMLSchema.DECIMAL; + } else if (op == MathOp.DIVIDE) { + // Result of integer divide is decimal and requires the arguments to + // be handled as such, see for details: + // http://www.w3.org/TR/xpath-functions/#func-numeric-divide + commonDatatype = XMLSchema.DECIMAL; + } else { + commonDatatype = XMLSchema.INTEGER; + } + + // Note: Java already handles cases like divide-by-zero appropriately + // for floats and doubles, see: + // http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Tech/ + // Chapter02/floatingPt2.html + + try { + if (commonDatatype.equals(XMLSchema.DOUBLE)) { + double left = l1.doubleValue(); + double right = l2.doubleValue(); + return IVUtility.numericalMath(left, right, op); + } + else if (commonDatatype.equals(XMLSchema.FLOAT)) { + float left = l1.floatValue(); + float right = l2.floatValue(); + return IVUtility.numericalMath(left, right, op); + } + else if (commonDatatype.equals(XMLSchema.DECIMAL)) { + BigDecimal left = l1.decimalValue(); + BigDecimal right = l2.decimalValue(); + return IVUtility.numericalMath(left, right, op); + } + else { // XMLSchema.INTEGER + BigInteger left = l1.integerValue(); + BigInteger right = l2.integerValue(); + return IVUtility.numericalMath(left, right, op); + } + } catch (NumberFormatException e) { + throw new SparqlTypeErrorException(); + } catch (ArithmeticException e) { + throw new SparqlTypeErrorException(); + } + + } + public static final IV numericalMath(final IV iv1, final IV iv2, final MathOp op) { @@ -202,34 +277,53 @@ final AbstractLiteralIV num1 = (AbstractLiteralIV) iv1; final AbstractLiteralIV num2 = (AbstractLiteralIV) iv2; - // if one's a BigDecimal we should use the BigDecimal comparator for both - if (dte1 == DTE.XSDDecimal || dte2 == DTE.XSDDecimal) { - return numericalMath(num1.decimalValue(), num2.decimalValue(), op); - } + // Determine most specific datatype that the arguments have in common, + // choosing from xsd:integer, xsd:decimal, xsd:float and xsd:double as + // per the SPARQL/XPATH spec - // same for BigInteger - if (dte1 == DTE.XSDInteger || dte2 == DTE.XSDInteger) { - return numericalMath(num1.integerValue(), num2.integerValue(), op); - } - - // fixed length numerics - if (dte1.isFloatingPointNumeric() || dte2.isFloatingPointNumeric()) { - // non-BigDecimal floating points - if (dte1 == DTE.XSDFloat || dte2 == DTE.XSDFloat) - return numericalMath(num1.floatValue(), num2.floatValue(), op); - else - return numericalMath(num1.doubleValue(), num2.doubleValue(), op); + if (dte1 == DTE.XSDDouble || dte2 == DTE.XSDDouble) { + return numericalMath(num1.doubleValue(), num2.doubleValue(), op); + } else if (dte1 == DTE.XSDFloat || dte2 == DTE.XSDFloat) { + return numericalMath(num1.floatValue(), num2.floatValue(), op); + } if (dte1 == DTE.XSDDecimal || dte2 == DTE.XSDDecimal) { + return numericalMath(num1.decimalValue(), num2.decimalValue(), op); + } if (op == MathOp.DIVIDE) { + // Result of integer divide is decimal and requires the arguments to + // be handled as such, see for details: + // http://www.w3.org/TR/xpath-functions/#func-numeric-divide + return numericalMath(num1.decimalValue(), num2.decimalValue(), op); } else { - // non-BigInteger integers - if (dte1 == DTE.XSDInt && dte2 == DTE.XSDInt) - return numericalMath(num1.intValue(), num2.intValue(), op); - else - return numericalMath(num1.longValue(), num2.longValue(), op); + return numericalMath(num1.integerValue(), num2.integerValue(), op); } + +// // if one's a BigDecimal we should use the BigDecimal comparator for both +// if (dte1 == DTE.XSDDecimal || dte2 == DTE.XSDDecimal) { +// return numericalMath(num1.decimalValue(), num2.decimalValue(), op); +// } +// +// // same for BigInteger +// if (dte1 == DTE.XSDInteger || dte2 == DTE.XSDInteger) { +// return numericalMath(num1.integerValue(), num2.integerValue(), op); +// } +// +// // fixed length numerics +// if (dte1.isFloatingPointNumeric() || dte2.isFloatingPointNumeric()) { +// // non-BigDecimal floating points +// if (dte1 == DTE.XSDFloat || dte2 == DTE.XSDFloat) +// return numericalMath(num1.floatValue(), num2.floatValue(), op); +// else +// return numericalMath(num1.doubleValue(), num2.doubleValue(), op); +// } else { +// // non-BigInteger integers +// if (dte1 == DTE.XSDInt && dte2 == DTE.XSDInt) +// return numericalMath(num1.intValue(), num2.intValue(), op); +// else +// return numericalMath(num1.longValue(), num2.longValue(), op); +// } } - private static final IV numericalMath(final BigDecimal left, + public static final IV numericalMath(final BigDecimal left, final BigDecimal right, final MathOp op) { switch(op) { @@ -240,7 +334,7 @@ case MULTIPLY: return new XSDDecimalIV(left.multiply(right)); case DIVIDE: - return new XSDDecimalIV(left.divide(right)); + return new XSDDecimalIV(left.divide(right, RoundingMode.HALF_UP)); case MIN: return new XSDDecimalIV(left.compareTo(right) < 0 ? left : right); case MAX: @@ -251,7 +345,7 @@ } - private static final IV numericalMath(final BigInteger left, + public static final IV numericalMath(final BigInteger left, final BigInteger right, final MathOp op) { switch(op) { @@ -273,7 +367,7 @@ } - private static final IV numericalMath(final float left, + public static final IV numericalMath(final float left, final float right, final MathOp op) { switch(op) { @@ -295,7 +389,7 @@ } - private static final IV numericalMath(final double left, + public static final IV numericalMath(final double left, final double right, final MathOp op) { switch(op) { @@ -317,50 +411,50 @@ } - private static final IV numericalMath(final int left, - final int right, final MathOp op) { - - switch(op) { - case PLUS: - return new XSDIntIV(left+right); - case MINUS: - return new XSDIntIV(left-right); - case MULTIPLY: - return new XSDIntIV(left*right); - case DIVIDE: - return new XSDIntIV(left/right); - case MIN: - return new XSDIntIV(Math.min(left,right)); - case MAX: - return new XSDIntIV(Math.max(left,right)); - default: - throw new UnsupportedOperationException(); - } - - } +// private static final IV numericalMath(final int left, +// final int right, final MathOp op) { +// +// switch(op) { +// case PLUS: +// return new XSDIntIV(left+right); +// case MINUS: +// return new XSDIntIV(left-right); +// case MULTIPLY: +// return new XSDIntIV(left*right); +// case DIVIDE: +// return new XSDIntIV(left/right); +// case MIN: +// return new XSDIntIV(Math.min(left,right)); +// case MAX: +// return new XSDIntIV(Math.max(left,right)); +// default: +// throw new UnsupportedOperationException(); +// } +// +// } +// +// private static final IV numericalMath(final long left, +// final long right, final MathOp op) { +// +// switch(op) { +// case PLUS: +// return new XSDLongIV(left+right); +// case MINUS: +// return new XSDLongIV(left-right); +// case MULTIPLY: +// return new XSDLongIV(left*right); +// case DIVIDE: +// return new XSDLongIV(left/right); +// case MIN: +// return new XSDLongIV(Math.min(left,right)); +// case MAX: +// return new XSDLongIV(Math.max(left,right)); +// default: +// throw new UnsupportedOperationException(); +// } +// +// } - private static final IV numericalMath(final long left, - final long right, final MathOp op) { - - switch(op) { - case PLUS: - return new XSDLongIV(left+right); - case MINUS: - return new XSDLongIV(left-right); - case MULTIPLY: - return new XSDLongIV(left*right); - case DIVIDE: - return new XSDLongIV(left/right); - case MIN: - return new XSDLongIV(Math.min(left,right)); - case MAX: - return new XSDLongIV(Math.max(left,right)); - default: - throw new UnsupportedOperationException(); - } - - } - /** * Used to test whether a given value constant can be used in an inline * filter or not. If so, we can use one of the inline constraints 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-06-06 17:37:43 UTC (rev 4634) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/CompareBOp.java 2011-06-06 21:27:16 UTC (rev 4635) @@ -41,6 +41,7 @@ import com.bigdata.rdf.error.SparqlTypeErrorException; import com.bigdata.rdf.internal.IV; import com.bigdata.rdf.internal.IVUtility; +import com.bigdata.rdf.internal.TermId; import com.bigdata.rdf.model.BigdataValue; /** @@ -133,7 +134,10 @@ // probably would never hit this because of SameTermOp if (op == CompareOp.EQ && left.isTermId() && right.isTermId()) { - if (left.getTermId() == right.getTermId()) + final long tid1 = left.getTermId(); + final long tid2 = right.getTermId(); + + if (tid1 == tid2 && tid1 != TermId.NULL && tid2 != TermId.NULL) return true; } Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/DatatypeBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/DatatypeBOp.java 2011-06-06 17:37:43 UTC (rev 4634) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/DatatypeBOp.java 2011-06-06 21:27:16 UTC (rev 4635) @@ -97,7 +97,13 @@ } public IV get(final IBindingSet bs) { - + + final String namespace = (String) + getRequiredProperty(Annotations.NAMESPACE); + + final BigdataValueFactory vf = + BigdataValueFactoryImpl.getInstance(namespace); + final IV iv = get(0).get(bs); if (log.isDebugEnabled()) { @@ -108,6 +114,26 @@ if (iv == null) throw new SparqlTypeErrorException(); + if (iv.isNumeric()) { + + final BigdataURI datatype = vf.createURI(iv.getDTE().getDatatype()); + + IV datatypeIV = datatype.getIV(); + + if (datatypeIV == null) { + + datatypeIV = new TermId(VTE.URI, TermId.NULL); + datatype.setIV(datatypeIV); + + } + + // cache the value on the IV + datatypeIV.setValue(datatype); + + return datatypeIV; + + } + final BigdataValue val = iv.getValue(); if (val == null) @@ -127,12 +153,6 @@ } else if (literal.getLanguage() == null) { // simple literal - final String namespace = (String) - getRequiredProperty(Annotations.NAMESPACE); - - final BigdataValueFactory vf = - BigdataValueFactoryImpl.getInstance(namespace); - datatype = vf.asValue(XSD.STRING); } else { @@ -145,7 +165,7 @@ if (datatypeIV == null) { - datatypeIV = new TermId(VTE.valueOf(val), TermId.NULL); + datatypeIV = new TermId(VTE.URI, TermId.NULL); datatype.setIV(datatypeIV); } Added: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/FalseBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/FalseBOp.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/FalseBOp.java 2011-06-06 21:27:16 UTC (rev 4635) @@ -0,0 +1,72 @@ +/* + +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; + +/** + * Always evaluates to false. + */ +public class FalseBOp extends XSDBooleanIVValueExpression { + + /** + * + */ + private static final long serialVersionUID = 1531344906063447800L; + + public static final FalseBOp INSTANCE = new FalseBOp(); + + private FalseBOp() { + + this(NOARGS, NOANNS); + + } + + /** + * Required shallow copy constructor. + */ + public FalseBOp(final BOp[] args, final Map<String, Object> anns) { + + super(args, anns); + + } + + /** + * Required deep copy constructor. + */ + public FalseBOp(final FalseBOp op) { + super(op); + } + + public boolean accept(final IBindingSet bs) { + + return 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-06-06 17:37:43 UTC (rev 4634) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/MathBOp.java 2011-06-06 21:27:16 UTC (rev 4635) @@ -21,30 +21,50 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/** +Note: Portions of this file are copyright by Aduna. + +Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007. + +Licensed under the Aduna BSD-style license. +*/ + package com.bigdata.rdf.internal.constraints; +import java.util.LinkedHashSet; import java.util.Map; +import java.util.Set; +import org.apache.log4j.Logger; +import org.openrdf.model.Literal; + import com.bigdata.bop.BOp; import com.bigdata.bop.IBindingSet; import com.bigdata.bop.IValueExpression; +import com.bigdata.bop.IVariable; 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; +import com.bigdata.rdf.model.BigdataValue; /** * A math expression involving a left and right IValueExpression operand. The * operation to be applied to the operands is specified by the * {@link Annotations#OP} annotation. */ -final public class MathBOp extends IVValueExpression { +final public class MathBOp extends IVValueExpression + implements INeedsMaterialization { /** * */ private static final long serialVersionUID = 9136864442064392445L; + + private static final transient Logger log = Logger.getLogger(MathBOp.class); + public interface Annotations extends ImmutableBOp.Annotations { @@ -141,7 +161,40 @@ if (right == null) throw new SparqlTypeErrorException.UnboundVarException(); - return IVUtility.numericalMath(left, right, op()); + try { + + if (log.isDebugEnabled()) { + log.debug(toString(left.toString(), right.toString())); + } + + if (left.isInline() && right.isInline()) { + + return IVUtility.numericalMath(left, right, op()); + + } else { + + final BigdataValue val1 = left.getValue(); + + final BigdataValue val2 = right.getValue(); + + if (!(val1 instanceof Literal) || !(val2 instanceof Literal)) { + throw new SparqlTypeErrorException(); + } + + return IVUtility.literalMath((Literal) val1, (Literal) val2, + op()); + + } + + } catch (IllegalArgumentException ex) { + + if (log.isDebugEnabled()) { + log.debug("illegal argument, filtering solution"); + } + + throw new SparqlTypeErrorException(); + + } } @@ -165,6 +218,15 @@ return sb.toString(); } + + private String toString(final String left, final String right) { + + final StringBuilder sb = new StringBuilder(); + sb.append(op()); + sb.append("(").append(left).append(", ").append(right).append(")"); + return sb.toString(); + + } final public boolean equals(final MathBOp m) { @@ -210,5 +272,27 @@ return h; } + + private volatile transient Set<IVariable<IV>> terms; + + public Set<IVariable<IV>> getTermsToMaterialize() { + + if (terms == null) { + + terms = new LinkedHashSet<IVariable<IV>>(); + + for (BOp bop : args()) { + + if (bop instanceof IVariable) + terms.add((IVariable<IV>) bop); + + } + + } + + return terms; + + } + } Added: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/TrueBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/TrueBOp.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/TrueBOp.java 2011-06-06 21:27:16 UTC (rev 4635) @@ -0,0 +1,72 @@ +/* + +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; + +/** + * Always evaluates to true. + */ +public class TrueBOp extends XSDBooleanIVValueExpression { + + /** + * + */ + private static final long serialVersionUID = -6166507977125961015L; + + public static final TrueBOp INSTANCE = new TrueBOp(); + + private TrueBOp() { + + this(NOARGS, NOANNS); + + } + + /** + * Required shallow copy constructor. + */ + public TrueBOp(final BOp[] args, final Map<String, Object> anns) { + + super(args, anns); + + } + + /** + * Required deep copy constructor. + */ + public TrueBOp(final TrueBOp op) { + super(op); + } + + public boolean accept(final IBindingSet bs) { + + return true; + + } + +} 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-06-06 17:37:43 UTC (rev 4634) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java 2011-06-06 21:27:16 UTC (rev 4635) @@ -2455,6 +2455,16 @@ * {@link BigdataValue} for that term identifier in the lexicon. */ final public BigdataValue getTerm(final IV iv) { + + return getTerm(iv, true); + + } + + /** + * When readFromIndex=false, only handles inline, NULL, bnodes, SIDs, and + * the termCache - does not attempt to read from disk. + */ + final private BigdataValue getTerm(final IV iv, final boolean readFromIndex) { // if (false) { // alternative forces the standard code path. // final Collection<IV> ivs = new LinkedList<IV>(); @@ -2471,7 +2481,7 @@ // handle NULL, bnodes, statement identifiers, and the termCache. BigdataValue value = _getTermId(tid); - if (value != null) + if (value != null || !readFromIndex) return value; final IIndex ndx = getId2TermIndex(); @@ -2973,8 +2983,13 @@ final IV iv = term.get(); - final BigdataValue val = termCache.get(iv); + if (log.isDebugEnabled()) + log.debug("materializing: " + iv); + +// final BigdataValue val = termCache.get(iv); + final BigdataValue val = getTerm(iv, false); + if (val != null) { if (log.isDebugEnabled()) Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataURIImpl.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataURIImpl.java 2011-06-06 17:37:43 UTC (rev 4634) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataURIImpl.java 2011-06-06 21:27:16 UTC (rev 4635) @@ -50,6 +50,8 @@ import org.openrdf.model.URI; import org.openrdf.model.util.URIUtil; +import com.bigdata.rdf.internal.TermId; + /** * A URI. Use {@link BigdataValueFactory} to create instances of this class. * @@ -173,6 +175,7 @@ if ((o instanceof BigdataValue) // && getIV() != null// + && getIV().getTermId() != TermId.NULL && ((BigdataValue) o).getIV() != null// && ((BigdataValue) o).getValueFactory() == getValueFactory()) { Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java 2011-06-06 17:37:43 UTC (rev 4634) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java 2011-06-06 21:27:16 UTC (rev 4635) @@ -105,6 +105,7 @@ import com.bigdata.rdf.internal.constraints.CompareBOp; import com.bigdata.rdf.internal.constraints.DatatypeBOp; import com.bigdata.rdf.internal.constraints.EBVBOp; +import com.bigdata.rdf.internal.constraints.FalseBOp; import com.bigdata.rdf.internal.constraints.FuncBOp; import com.bigdata.rdf.internal.constraints.IsBNodeBOp; import com.bigdata.rdf.internal.constraints.IsBoundBOp; @@ -113,6 +114,7 @@ import com.bigdata.rdf.internal.constraints.LangBOp; import com.bigdata.rdf.internal.constraints.LangMatchesBOp; import com.bigdata.rdf.internal.constraints.MathBOp; +import com.bigdata.rdf.internal.constraints.TrueBOp; import com.bigdata.rdf.internal.constraints.MathBOp.MathOp; import com.bigdata.rdf.internal.constraints.NotBOp; import com.bigdata.rdf.internal.constraints.OrBOp; @@ -1924,11 +1926,32 @@ } private IValueExpression<? extends IV> toVE(SameTerm sameTerm) { - final IValueExpression<? extends IV> iv1 = + final IValueExpression<? extends IV> left = toVE(sameTerm.getLeftArg()); - final IValueExpression<? extends IV> iv2 = + final IValueExpression<? extends IV> right = toVE(sameTerm.getRightArg()); - return new SameTermBOp(iv1, iv2); + + /* + * If a constant operand in the SameTerm op uses a value not found + * in the database, we must defer to the CompareBOp, which can perform + * value comparisons. SameTermBOp only works on IVs. + */ + + if (left instanceof Constant) { + final IV iv = ((Constant<? extends IV>) left).get(); + if (iv.isTermId() && iv.getTermId() == TermId.NULL) { + return new CompareBOp(left, right, CompareOp.EQ); + } + } + + if (right instanceof Constant) { + final IV iv = ((Constant<? extends IV>) right).get(); + if (iv.isTermId() && iv.getTermId() == TermId.NULL) { + return new CompareBOp(left, right, CompareOp.EQ); + } + } + + return new SameTermBOp(left, right); } private IValueExpression<? extends IV> toVE(final Compare compare) { @@ -1939,27 +1962,41 @@ /* * If the term is a Constant<URI> and the op is EQ or NE then we can - * do a sameTerm optimization. + * do a sameTerm optimization. The URI constant must be a real term + * in the database. */ final CompareOp op = compare.getOperator(); if (op == CompareOp.EQ || op == CompareOp.NE) { if (left instanceof Constant) { final IV iv = ((Constant<? extends IV>) left).get(); - if (iv.isURI()) { + if (iv.isURI() && iv.getTermId() != TermId.NULL) { return new SameTermBOp(left, right, op); } } if (right instanceof Constant) { final IV iv = ((Constant<? extends IV>) right).get(); - if (iv.isURI()) { + if (iv.isURI() && iv.getTermId() != TermId.NULL) { return new SameTermBOp(left, right, op); } } } + if (log.isDebugEnabled()) { + log.debug(left == right); + log.debug(left.equals(right)); + } + + if (left.equals(right)) { + if (compare.getOperator() == CompareOp.EQ) { + return TrueBOp.INSTANCE; + } else { + return FalseBOp.INSTANCE; + } + } + return new CompareBOp(left, right, compare.getOperator()); } Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/tck/BigdataSparqlTest.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/tck/BigdataSparqlTest.java 2011-06-06 17:37:43 UTC (rev 4634) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/tck/BigdataSparqlTest.java 2011-06-06 21:27:16 UTC (rev 4635) @@ -178,7 +178,54 @@ * run. */ static final Collection<String> testURIs = Arrays.asList(new String[] { - + // 8, 9, 14-19, 23-30 + +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-01", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-02", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-03", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-04", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-05", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-06", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-07", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-08", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-09", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-10", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-11", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-12", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-13", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-14", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-15", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-16", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-17", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-18", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-19", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-20", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-21", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-22", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-23", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-24", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-25", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-26", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-27", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-28", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-29", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest#type-promotion-30", + +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest#sameTerm-eq", + +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/open-world/manifest#open-eq-01", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/open-world/manifest#open-eq-02", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/open-world/manifest#open-eq-03", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/open-world/manifest#open-eq-04", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/open-world/manifest#open-eq-05", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/open-world/manifest#open-eq-06", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/open-world/manifest#open-eq-07", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/open-world/manifest#open-eq-08", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/open-world/manifest#open-eq-09", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/open-world/manifest#open-eq-10", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/open-world/manifest#open-eq-11", +// "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/open-world/manifest#open-eq-12", + /* * working through the new query engine failures: 0 errors, 11 failures */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |