From: <mrp...@us...> - 2011-06-06 14:11:30
|
Revision: 4630 http://bigdata.svn.sourceforge.net/bigdata/?rev=4630&view=rev Author: mrpersonick Date: 2011-06-06 14:11:22 +0000 (Mon, 06 Jun 2011) Log Message: ----------- lex joins and sesame 1.0 operators Modified Paths: -------------- 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/lexicon/LexiconKeyOrder.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/DatatypeBOp.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/FuncBOp.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/LangBOp.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/LangMatchesBOp.java branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/CacheValueFilter.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestLexJoinOps.java 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 12:36:01 UTC (rev 4629) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/IVUtility.java 2011-06-06 14:11:22 UTC (rev 4630) @@ -215,7 +215,7 @@ // fixed length numerics if (dte1.isFloatingPointNumeric() || dte2.isFloatingPointNumeric()) { // non-BigDecimal floating points - if (dte1 == DTE.XSDFloat && dte2 == DTE.XSDFloat) + if (dte1 == DTE.XSDFloat || dte2 == DTE.XSDFloat) return numericalMath(num1.floatValue(), num2.floatValue(), op); else return numericalMath(num1.doubleValue(), num2.doubleValue(), op); Added: 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 (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/DatatypeBOp.java 2011-06-06 14:11:22 UTC (rev 4630) @@ -0,0 +1,185 @@ +/* + +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.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.log4j.Logger; + +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.rdf.error.SparqlTypeErrorException; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.NotMaterializedException; +import com.bigdata.rdf.internal.TermId; +import com.bigdata.rdf.internal.VTE; +import com.bigdata.rdf.internal.XSD; +import com.bigdata.rdf.model.BigdataLiteral; +import com.bigdata.rdf.model.BigdataURI; +import com.bigdata.rdf.model.BigdataValue; +import com.bigdata.rdf.model.BigdataValueFactory; +import com.bigdata.rdf.model.BigdataValueFactoryImpl; + +/** + * Return the datatype of the literal argument. + */ +public class DatatypeBOp extends IVValueExpression<IV> + implements INeedsMaterialization { + + /** + * + */ + private static final long serialVersionUID = 7391999162162545704L; + + private static final transient Logger log = Logger.getLogger(DatatypeBOp.class); + + + public interface Annotations extends BOp.Annotations { + + String NAMESPACE = (DatatypeBOp.class.getName() + ".namespace").intern(); + + } + + public DatatypeBOp(final IValueExpression<? extends IV> x, final String lex) { + + this(new BOp[] { x }, + NV.asMap(new NV(Annotations.NAMESPACE, lex))); + + } + + /** + * Required shallow copy constructor. + */ + public DatatypeBOp(final BOp[] args, final Map<String, Object> anns) { + + super(args, anns); + + if (args.length != 1 || args[0] == null) + throw new IllegalArgumentException(); + + if (getProperty(Annotations.NAMESPACE) == null) + throw new IllegalArgumentException(); + + } + + /** + * Required deep copy constructor. + */ + public DatatypeBOp(final DatatypeBOp op) { + super(op); + } + + public IV get(final IBindingSet bs) { + + final IV iv = get(0).get(bs); + + if (log.isDebugEnabled()) { + log.debug(iv); + } + + // not yet bound + if (iv == null) + throw new SparqlTypeErrorException(); + + final BigdataValue val = iv.getValue(); + + if (val == null) + throw new NotMaterializedException(); + + if (val instanceof BigdataLiteral) { + + final BigdataLiteral literal = (BigdataLiteral) val; + + final BigdataURI datatype; + + if (literal.getDatatype() != null) { + + // literal with datatype + datatype = literal.getDatatype(); + + } 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 { + + throw new SparqlTypeErrorException(); + + } + + IV datatypeIV = datatype.getIV(); + + if (datatypeIV == null) { + + datatypeIV = new TermId(VTE.valueOf(val), TermId.NULL); + datatype.setIV(datatypeIV); + + } + + // cache the value on the IV + datatypeIV.setValue(datatype); + + return datatypeIV; + + } + + throw new SparqlTypeErrorException(); + + } + + 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/FuncBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/FuncBOp.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/FuncBOp.java 2011-06-06 14:11:22 UTC (rev 4630) @@ -0,0 +1,195 @@ +/* + +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.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.log4j.Logger; +import org.openrdf.model.Value; +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; +import org.openrdf.query.algebra.evaluation.function.Function; +import org.openrdf.query.algebra.evaluation.function.FunctionRegistry; + +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.rdf.error.SparqlTypeErrorException; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.NotMaterializedException; +import com.bigdata.rdf.internal.TermId; +import com.bigdata.rdf.internal.VTE; +import com.bigdata.rdf.model.BigdataValue; +import com.bigdata.rdf.model.BigdataValueFactory; +import com.bigdata.rdf.model.BigdataValueFactoryImpl; + +/** + * Call one of the Sesame casting functions. + */ +public class FuncBOp extends IVValueExpression<IV> + implements INeedsMaterialization { + + /** + * + */ + private static final long serialVersionUID = 2587499644967260639L; + + private static final transient Logger log = Logger.getLogger(FuncBOp.class); + + + public interface Annotations extends BOp.Annotations { + + String NAMESPACE = (FuncBOp.class.getName() + ".namespace").intern(); + + String FUNCTION = (FuncBOp.class.getName() + ".function").intern(); + + } + + public FuncBOp(final IValueExpression<? extends IV>[] args, + final String func, final String lex) { + + this(args, NV.asMap( + new NV(Annotations.NAMESPACE, lex), + new NV(Annotations.FUNCTION, func))); + + } + + /** + * Required shallow copy constructor. + */ + public FuncBOp(final BOp[] args, final Map<String, Object> anns) { + + super(args, anns); + + if (getProperty(Annotations.NAMESPACE) == null) + throw new IllegalArgumentException(); + + if (getProperty(Annotations.FUNCTION) == null) + throw new IllegalArgumentException(); + + } + + /** + * Required deep copy constructor. + */ + public FuncBOp(final FuncBOp op) { + super(op); + } + + public IV get(final IBindingSet bs) { + + final List<BOp> args = args(); + + final Value[] vals = new Value[args.size()]; + + for (int i = 0; i < vals.length; i++) { + + final IV iv = get(i).get(bs); + + if (log.isDebugEnabled()) { + log.debug(iv); + } + + // not yet bound + if (iv == null) + throw new SparqlTypeErrorException(); + + final BigdataValue val = iv.getValue(); + + if (val == null) + throw new NotMaterializedException(); + + vals[i] = val; + + } + + final String funcName = + (String) getRequiredProperty(Annotations.FUNCTION); + + final Function func = FunctionRegistry.getInstance().get(funcName); + + if (func == null) { + throw new RuntimeException("Unknown function '" + funcName + "'"); + } + + final String namespace = (String) + getRequiredProperty(Annotations.NAMESPACE); + + final BigdataValueFactory vf = + BigdataValueFactoryImpl.getInstance(namespace); + + try { + + final BigdataValue val = (BigdataValue) func.evaluate(vf, vals); + + IV iv = val.getIV(); + + if (iv == null) { + + iv = new TermId(VTE.valueOf(val), TermId.NULL); + + val.setIV(iv); + + } + + // cache the value on the IV + iv.setValue(val); + + return iv; + + } catch (ValueExprEvaluationException ex) { + + throw new SparqlTypeErrorException(); + + } + + } + + 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/LangBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/LangBOp.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/LangBOp.java 2011-06-06 14:11:22 UTC (rev 4630) @@ -0,0 +1,174 @@ +/* + +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.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.log4j.Logger; + +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.rdf.error.SparqlTypeErrorException; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.NotMaterializedException; +import com.bigdata.rdf.internal.TermId; +import com.bigdata.rdf.internal.VTE; +import com.bigdata.rdf.internal.XSD; +import com.bigdata.rdf.model.BigdataLiteral; +import com.bigdata.rdf.model.BigdataURI; +import com.bigdata.rdf.model.BigdataValue; +import com.bigdata.rdf.model.BigdataValueFactory; +import com.bigdata.rdf.model.BigdataValueFactoryImpl; + +/** + * Return the language tag of the literal argument. + */ +public class LangBOp extends IVValueExpression<IV> + implements INeedsMaterialization { + + /** + * + */ + private static final long serialVersionUID = 7391999162162545704L; + + private static final transient Logger log = Logger.getLogger(LangBOp.class); + + + public interface Annotations extends BOp.Annotations { + + String NAMESPACE = (LangBOp.class.getName() + ".namespace").intern(); + + } + + public LangBOp(final IValueExpression<? extends IV> x, final String lex) { + + this(new BOp[] { x }, + NV.asMap(new NV(Annotations.NAMESPACE, lex))); + + } + + /** + * Required shallow copy constructor. + */ + public LangBOp(final BOp[] args, final Map<String, Object> anns) { + + super(args, anns); + + if (args.length != 1 || args[0] == null) + throw new IllegalArgumentException(); + + if (getProperty(Annotations.NAMESPACE) == null) + throw new IllegalArgumentException(); + + } + + /** + * Required deep copy constructor. + */ + public LangBOp(final LangBOp op) { + super(op); + } + + public IV get(final IBindingSet bs) { + + final IV iv = get(0).get(bs); + + if (log.isDebugEnabled()) { + log.debug(iv); + } + + // not yet bound + if (iv == null) + throw new SparqlTypeErrorException(); + + final BigdataValue val = iv.getValue(); + + if (val == null) + throw new NotMaterializedException(); + + if (val instanceof BigdataLiteral) { + + final BigdataLiteral literal = (BigdataLiteral) val; + + String langTag = literal.getLanguage(); + if (langTag == null) { + langTag = ""; + } + + final String namespace = (String) + getRequiredProperty(Annotations.NAMESPACE); + + final BigdataValueFactory vf = + BigdataValueFactoryImpl.getInstance(namespace); + + final BigdataValue lang = vf.createLiteral(langTag); + + IV langIV = lang.getIV(); + + if (langIV == null) { + + langIV = new TermId(VTE.LITERAL, TermId.NULL); + lang.setIV(langIV); + + } + + // cache the value on the IV + langIV.setValue(lang); + + return langIV; + + } + + throw new SparqlTypeErrorException(); + + } + + 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/LangMatchesBOp.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/LangMatchesBOp.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/constraints/LangMatchesBOp.java 2011-06-06 14:11:22 UTC (rev 4630) @@ -0,0 +1,152 @@ +/* + +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.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.log4j.Logger; +import org.openrdf.model.Literal; +import org.openrdf.query.algebra.evaluation.util.QueryEvaluationUtil; + +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.NotMaterializedException; +import com.bigdata.rdf.model.BigdataValue; + +/** + * Implements the langMatches SPARQL operator. + */ +public class LangMatchesBOp extends XSDBooleanIVValueExpression + implements INeedsMaterialization { + + /** + * + */ + private static final long serialVersionUID = 5910711647357240974L; + + private static final transient Logger log = Logger.getLogger(LangMatchesBOp.class); + + + public LangMatchesBOp(final IValueExpression<? extends IV> tag, + final IValueExpression<? extends IV> range) { + + this(new BOp[] { tag, range }, null/*annocations*/); + + } + + /** + * Required shallow copy constructor. + */ + public LangMatchesBOp(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 LangMatchesBOp(final LangMatchesBOp op) { + super(op); + } + + protected boolean accept(final IBindingSet bs) { + + final IV tag = get(0).get(bs); + final IV range = get(1).get(bs); + + if (log.isDebugEnabled()) { + log.debug(tag); + log.debug(range); + } + + // not yet bound + if (tag == null || range == null) + throw new SparqlTypeErrorException(); + + final BigdataValue tagVal = tag.getValue(); + final BigdataValue rangeVal = tag.getValue(); + + // not yet materialized + if (tagVal == null || rangeVal == null) + throw new NotMaterializedException(); + + if (QueryEvaluationUtil.isSimpleLiteral(tagVal) + && QueryEvaluationUtil.isSimpleLiteral(rangeVal)) + { + String langTag = ((Literal)tagVal).getLabel(); + String langRange = ((Literal)rangeVal).getLabel(); + + boolean result = false; + if (langRange.equals("*")) { + result = langTag.length() > 0; + } + else if (langTag.length() == langRange.length()) { + result = langTag.equalsIgnoreCase(langRange); + } + else if (langTag.length() > langRange.length()) { + // check if the range is a prefix of the tag + String prefix = langTag.substring(0, langRange.length()); + result = prefix.equalsIgnoreCase(langRange) && langTag.charAt(langRange.length()) == '-'; + } + + return result; + } + + throw new SparqlTypeErrorException(); + + } + + 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/lexicon/CacheValueFilter.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/CacheValueFilter.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/CacheValueFilter.java 2011-06-06 14:11:22 UTC (rev 4630) @@ -0,0 +1,91 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + * Created on Sep 28, 2010 + */ + +package com.bigdata.rdf.lexicon; + +import java.util.Map; + +import com.bigdata.bop.BOp; +import com.bigdata.bop.BOpBase; +import com.bigdata.bop.ap.filter.BOpResolver; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.model.BigdataValue; + +/** + * Cache the {@link BigdataValue} on the {@link IV} (create a cross linkage). + * This is useful for lexicon joins and SPARQL operators that need to use + * materialized RDF values. + */ +public class CacheValueFilter extends BOpResolver { + + /** + * + */ + private static final long serialVersionUID = -7267351719878117114L; + + /** + * A default instance. + */ + public static CacheValueFilter newInstance() { + return new CacheValueFilter(BOpBase.NOARGS, BOpBase.NOANNS); + } + + /** + * @param op + */ + public CacheValueFilter(CacheValueFilter op) { + super(op); + } + + /** + * @param args + * @param annotations + */ + public CacheValueFilter(BOp[] args, Map<String, Object> annotations) { + super(args, annotations); + } + + /** + * Cache the BigdataValue on its IV (cross-link). + */ + @Override + protected Object resolve(final Object obj) { + + final BigdataValue val = (BigdataValue) obj; + + // the link from BigdataValue to IV is pre-existing (set by the + // materialization of the index tuple) + final IV iv = val.getIV(); + + // cache the value on the IV + iv.setValue(val); + + return obj; + + } + +} Modified: branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconKeyOrder.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconKeyOrder.java 2011-06-06 12:36:01 UTC (rev 4629) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconKeyOrder.java 2011-06-06 14:11:22 UTC (rev 4630) @@ -5,10 +5,11 @@ import org.openrdf.model.Value; +import com.bigdata.btree.keys.IKeyBuilder; +import com.bigdata.rdf.internal.TermId; import com.bigdata.rdf.model.BigdataValue; import com.bigdata.rdf.model.BigdataValueIdComparator; import com.bigdata.striterator.AbstractKeyOrder; -import com.bigdata.striterator.IKeyOrder; /** * Natural index orders for the {@link LexiconRelation}. @@ -181,5 +182,26 @@ return LexiconKeyOrder.valueOf(index); } + + protected void appendKeyComponent(final IKeyBuilder keyBuilder, + final int i, final Object keyComponent) { + if (index == _TERM2ID) { + + final BigdataValue term = (BigdataValue) keyComponent; + final LexiconKeyBuilder lexKeyBuilder = + new LexiconKeyBuilder(keyBuilder); + lexKeyBuilder.value2Key(term); + + } else if (index == _ID2TERM) { + + final TermId id = (TermId) keyComponent; + id.encode(keyBuilder); + + } else { + throw new AssertionError(); + } + + } + } 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 12:36:01 UTC (rev 4629) +++ branches/QUADS_QUERY_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java 2011-06-06 14:11:22 UTC (rev 4630) @@ -59,6 +59,8 @@ import com.bigdata.bop.IBindingSet; import com.bigdata.bop.IPredicate; import com.bigdata.bop.IVariableOrConstant; +import com.bigdata.bop.ap.Predicate; +import com.bigdata.bop.ap.filter.BOpResolver; import com.bigdata.btree.BytesUtil; import com.bigdata.btree.IIndex; import com.bigdata.btree.IRangeQuery; @@ -98,9 +100,12 @@ import com.bigdata.rdf.model.BigdataValueFactoryImpl; import com.bigdata.rdf.rio.IStatementBuffer; import com.bigdata.rdf.rio.StatementBuffer; +import com.bigdata.rdf.spo.ISPO; +import com.bigdata.rdf.spo.SPO; import com.bigdata.rdf.store.AbstractTripleStore; import com.bigdata.rdf.store.IRawTripleStore; import com.bigdata.relation.AbstractRelation; +import com.bigdata.relation.accesspath.AccessPath; import com.bigdata.relation.accesspath.ArrayAccessPath; import com.bigdata.relation.accesspath.IAccessPath; import com.bigdata.relation.accesspath.IElementFilter; @@ -2923,18 +2928,39 @@ } final BigdataValue val = term.get(); + + // see if it already has an IV or can be assigned an inline IV + IV iv = val.getIV(); + if (iv == null) { + iv = getInlineIV(val); + } + + if (iv != null) { + + // cache the IV on the value + val.setIV(iv); + + // cache the value on the IV + iv.setValue(val); + + return new ArrayAccessPath<BigdataValue>(new BigdataValue[] { val }, + predicate, keyOrder); + + } + + final CacheValueFilter filter = CacheValueFilter.newInstance(); - final IV iv = getIV(val); + final IPredicate<BigdataValue> tmp = (IPredicate<BigdataValue>) + predicate.setProperty( + Predicate.Annotations.ACCESS_PATH_FILTER, filter + ); - // cache the IV on the value - val.setIV(iv); + AccessPath<BigdataValue> ap = new AccessPath<BigdataValue>( + this, localIndexManager, tmp, keyOrder + ); - // cache the value on the IV - iv.setValue(val); + return ap; - return new ArrayAccessPath<BigdataValue>(new BigdataValue[] { val }, - predicate, keyOrder); - } else if (keyOrder == LexiconKeyOrder.ID2TERM) { final IVariableOrConstant<IV> term = predicate.get(1); @@ -2947,17 +2973,40 @@ final IV iv = term.get(); - final BigdataValue val = getTerm(iv); + final BigdataValue val = termCache.get(iv); - // cache the IV on the value - val.setIV(iv); + if (val != null) { - // cache the value on the IV - iv.setValue(val); + if (log.isDebugEnabled()) + log.debug("found term in the term cache: " + val); + + // cache the IV on the value + val.setIV(iv); + + // cache the value on the IV + iv.setValue(val); + + return new ArrayAccessPath<BigdataValue>(new BigdataValue[] { val }, + predicate, keyOrder); + + } - return new ArrayAccessPath<BigdataValue>(new BigdataValue[] { val }, - predicate, keyOrder); + if (log.isDebugEnabled()) + log.debug("did not find term in the term cache: " + iv); + final CacheValueFilter filter = CacheValueFilter.newInstance(); + + final IPredicate<BigdataValue> tmp = (IPredicate<BigdataValue>) + predicate.setProperty( + Predicate.Annotations.ACCESS_PATH_FILTER, filter + ); + + final AccessPath<BigdataValue> ap = new AccessPath<BigdataValue>( + this, localIndexManager, tmp, keyOrder + ).init(); + + return ap; + } else { throw new IllegalArgumentException(); 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 12:36:01 UTC (rev 4629) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl3.java 2011-06-06 14:11:22 UTC (rev 4630) @@ -30,6 +30,7 @@ import org.openrdf.query.algebra.BNodeGenerator; import org.openrdf.query.algebra.Bound; import org.openrdf.query.algebra.Compare; +import org.openrdf.query.algebra.Compare.CompareOp; import org.openrdf.query.algebra.CompareAll; import org.openrdf.query.algebra.CompareAny; import org.openrdf.query.algebra.Datatype; @@ -63,6 +64,7 @@ import org.openrdf.query.algebra.Regex; import org.openrdf.query.algebra.SameTerm; import org.openrdf.query.algebra.StatementPattern; +import org.openrdf.query.algebra.StatementPattern.Scope; import org.openrdf.query.algebra.Str; import org.openrdf.query.algebra.TupleExpr; import org.openrdf.query.algebra.UnaryTupleOperator; @@ -70,8 +72,6 @@ import org.openrdf.query.algebra.ValueConstant; import org.openrdf.query.algebra.ValueExpr; import org.openrdf.query.algebra.Var; -import org.openrdf.query.algebra.Compare.CompareOp; -import org.openrdf.query.algebra.StatementPattern.Scope; import org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl; import org.openrdf.query.algebra.evaluation.iterator.FilterIterator; import org.openrdf.query.algebra.helpers.QueryModelVisitorBase; @@ -83,12 +83,12 @@ import com.bigdata.bop.IConstant; import com.bigdata.bop.IConstraint; import com.bigdata.bop.IPredicate; +import com.bigdata.bop.IPredicate.Annotations; import com.bigdata.bop.IValueExpression; import com.bigdata.bop.IVariable; import com.bigdata.bop.IVariableOrConstant; import com.bigdata.bop.NV; import com.bigdata.bop.PipelineOp; -import com.bigdata.bop.IPredicate.Annotations; import com.bigdata.bop.ap.Predicate; import com.bigdata.bop.bindingSet.ListBindingSet; import com.bigdata.bop.constraint.INBinarySearch; @@ -103,12 +103,17 @@ import com.bigdata.rdf.internal.VTE; import com.bigdata.rdf.internal.constraints.AndBOp; 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.FuncBOp; import com.bigdata.rdf.internal.constraints.IsBNodeBOp; import com.bigdata.rdf.internal.constraints.IsBoundBOp; import com.bigdata.rdf.internal.constraints.IsLiteralBOp; import com.bigdata.rdf.internal.constraints.IsURIBOp; +import com.bigdata.rdf.internal.constraints.LangBOp; +import com.bigdata.rdf.internal.constraints.LangMatchesBOp; import com.bigdata.rdf.internal.constraints.MathBOp; +import com.bigdata.rdf.internal.constraints.MathBOp.MathOp; import com.bigdata.rdf.internal.constraints.NotBOp; import com.bigdata.rdf.internal.constraints.OrBOp; import com.bigdata.rdf.internal.constraints.RangeBOp; @@ -116,16 +121,15 @@ import com.bigdata.rdf.internal.constraints.SPARQLConstraint; import com.bigdata.rdf.internal.constraints.SameTermBOp; import com.bigdata.rdf.internal.constraints.StrBOp; -import com.bigdata.rdf.internal.constraints.MathBOp.MathOp; import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.rdf.model.BigdataValue; import com.bigdata.rdf.sail.BigdataSail.Options; import com.bigdata.rdf.sail.sop.SOp; import com.bigdata.rdf.sail.sop.SOp2BOpUtility; import com.bigdata.rdf.sail.sop.SOpTree; +import com.bigdata.rdf.sail.sop.SOpTree.SOpGroup; import com.bigdata.rdf.sail.sop.SOpTreeBuilder; import com.bigdata.rdf.sail.sop.UnsupportedOperatorException; -import com.bigdata.rdf.sail.sop.SOpTree.SOpGroup; import com.bigdata.rdf.spo.DefaultGraphSolutionExpander; import com.bigdata.rdf.spo.ExplicitSPOFilter; import com.bigdata.rdf.spo.ISPO; @@ -777,49 +781,37 @@ * UnsupportedOperatorException here must just flow through * to Sesame evaluation of the entire query. */ -// if (op instanceof Regex) { -// final Regex regex = (Regex) op; -// final IPredicate bop = toPredicate(regex); -// sop.setBOp(bop); -// } else { - final ValueExpr ve = (ValueExpr) op; - final IConstraint bop = toConstraint(ve); - sop.setBOp(bop); -// } + final ValueExpr ve = (ValueExpr) op; + final IConstraint bop = toConstraint(ve); + sop.setBOp(bop); } else if (op instanceof Filter) { final Filter filter = (Filter) op; final ValueExpr ve = filter.getCondition(); - try { -// if (ve instanceof Regex) { -// final Regex regex = (Regex) ve; -// final IPredicate bop = toPredicate(regex); -// sop.setBOp(bop); -// } else { - final IConstraint bop = toConstraint(ve); - sop.setBOp(bop); -// } - } catch (UnsupportedOperatorException ex) { - /* - * If we encounter a sesame filter (ValueExpr) that we - * cannot translate, we can safely wrap the entire query - * with a Sesame filter iterator to capture that - * untranslatable value expression. If we are not in the - * root group however, we risk applying the filter to the - * wrong context (for example a filter inside an optional - * join group cannot be applied universally to the entire - * solution). In this case we must punt. - */ - if (sop.getGroup() == SOpTreeBuilder.ROOT_GROUP_ID) { - sopsToPrune.add(sop); - sesameFilters.add(filter); - } else { - /* - * Note: DO NOT wrap with a different exception type - - * the caller is looking for this. - */ - throw new UnsupportedOperatorException(ex); - } - } +// try { + final IConstraint bop = toConstraint(ve); + sop.setBOp(bop); +// } catch (UnsupportedOperatorException ex) { +// /* +// * If we encounter a sesame filter (ValueExpr) that we +// * cannot translate, we can safely wrap the entire query +// * with a Sesame filter iterator to capture that +// * untranslatable value expression. If we are not in the +// * root group however, we risk applying the filter to the +// * wrong context (for example a filter inside an optional +// * join group cannot be applied universally to the entire +// * solution). In this case we must punt. +// */ +// if (sop.getGroup() == SOpTreeBuilder.ROOT_GROUP_ID) { +// sopsToPrune.add(sop); +// sesameFilters.add(filter); +// } else { +// /* +// * Note: DO NOT wrap with a different exception type - +// * the caller is looking for this. +// */ +// throw new UnsupportedOperatorException(ex); +// } +// } } } @@ -1832,11 +1824,11 @@ } else if (ve instanceof Label) { throw new UnsupportedOperatorException(ve); } else if (ve instanceof Lang) { - throw new UnsupportedOperatorException(ve); + return toVE((Lang) ve); } else if (ve instanceof LangMatches) { - throw new UnsupportedOperatorException(ve); + return toVE((LangMatches) ve); } else if (ve instanceof Datatype) { - throw new UnsupportedOperatorException(ve); + return toVE((Datatype) ve); } else if (ve instanceof Namespace) { throw new UnsupportedOperatorException(ve); } else if (ve instanceof LocalName) { @@ -1854,7 +1846,7 @@ } else if (ve instanceof Like) { throw new UnsupportedOperatorException(ve); } else if (ve instanceof FunctionCall) { - throw new UnsupportedOperatorException(ve); + return toVE((FunctionCall) ve); } else if (ve instanceof And) { return toVE((And) ve); } else if (ve instanceof Or) { @@ -2014,6 +2006,36 @@ } } + private IValueExpression<? extends IV> toVE(final FunctionCall fc) { + final String lex = database.getLexiconRelation().getNamespace(); + final String func = fc.getURI(); + final List<ValueExpr> args = fc.getArgs(); + final IValueExpression<? extends IV>[] bops = + new IValueExpression[args.size()]; + for (int i = 0; i < bops.length; i++) { + bops[i] = toVE(args.get(i)); + } + return new FuncBOp(bops, func, lex); + } + + private IValueExpression<? extends IV> toVE(final Datatype dt) { + final String lex = database.getLexiconRelation().getNamespace(); + final IValueExpression<? extends IV> arg = toVE(dt.getArg()); + return new DatatypeBOp(arg, lex); + } + + private IValueExpression<? extends IV> toVE(final Lang lang) { + final String lex = database.getLexiconRelation().getNamespace(); + final IValueExpression<? extends IV> arg = toVE(lang.getArg()); + return new LangBOp(arg, lex); + } + + private IValueExpression<? extends IV> toVE(final LangMatches lm) { + final IValueExpression<? extends IV> tag = toVE(lm.getLeftArg()); + final IValueExpression<? extends IV> range = toVE(lm.getRightArg()); + return new LangMatchesBOp(tag, range); + } + /** * Generate a bigdata term from a Sesame term. * <p> Added: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestLexJoinOps.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestLexJoinOps.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestLexJoinOps.java 2011-06-06 14:11:22 UTC (rev 4630) @@ -0,0 +1,570 @@ +/** +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.sail; + +import java.util.Properties; + +import org.apache.log4j.Logger; +import org.openrdf.model.Literal; +import org.openrdf.model.URI; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.vocabulary.RDF; +import org.openrdf.model.vocabulary.RDFS; +import org.openrdf.query.QueryLanguage; +import org.openrdf.query.TupleQueryResult; +import org.openrdf.repository.Repository; +import org.openrdf.repository.RepositoryConnection; +import org.openrdf.repository.sail.SailRepository; +import org.openrdf.repository.sail.SailTupleQuery; +import org.openrdf.sail.Sail; +import org.openrdf.sail.memory.MemoryStore; + +import com.bigdata.rdf.axioms.NoAxioms; +import com.bigdata.rdf.internal.XSD; +import com.bigdata.rdf.store.BD; +import com.bigdata.rdf.vocab.NoVocabulary; + +public class TestLexJoinOps extends QuadsTestCase { + + protected static final Logger log = Logger.getLogger(TestLexJoinOps.class); + + protected static final boolean INFO = log.isInfoEnabled(); + + @Override + public Properties getProperties() { + + Properties props = super.getProperties(); + + props.setProperty(BigdataSail.Options.AXIOMS_CLASS, NoAxioms.class.getName()); + props.setProperty(BigdataSail.Options.VOCABULARY_CLASS, NoVocabulary.class.getName()); + props.setProperty(BigdataSail.Options.TRUTH_MAINTENANCE, "false"); + props.setProperty(BigdataSail.Options.JUSTIFY, "false"); + props.setProperty(BigdataSail.Options.TEXT_INDEX, "false"); + + return props; + + } + + /** + * + */ + public TestLexJoinOps() { + } + + /** + * @param arg0 + */ + public TestLexJoinOps(String arg0) { + super(arg0); + } + + public void testStr() throws Exception { + +// final Sail sail = new MemoryStore(); +// try { +// sail.initialize(); +// final Repository repo = new SailRepository(sail); + + final BigdataSail sail = getSail(); + try { + sail.initialize(); + final BigdataSailRepository repo = new BigdataSailRepository(sail); + + final RepositoryConnection cxn = repo.getConnection(); + + try { + cxn.setAutoCommit(false); + + final ValueFactory vf = sail.getValueFactory(); + + /* + * Create some terms. + */ + final URI X = vf.createURI(BD.NAMESPACE + "X"); + final URI dt = vf.createURI(BD.NAMESPACE + "myDatatype"); + final Literal _1 = vf.createLiteral("foo"); + final Literal _2 = vf.createLiteral("foo", XSD.STRING); + final Literal _3 = vf.createLiteral("foo", dt); + final Literal _4 = vf.createLiteral("foo", "EN"); + final Literal _5 = vf.createLiteral(true); + final Literal _6 = vf.createLiteral(1000l); + + /* + * Create some statements. + */ + cxn.add(X, RDF.TYPE, RDFS.RESOURCE); +// cxn.add(X, RDFS.LABEL, _1); + cxn.add(X, RDFS.LABEL, _2); + cxn.add(X, RDFS.LABEL, _3); + cxn.add(X, RDFS.LABEL, _4); + cxn.add(X, RDFS.LABEL, _5); + cxn.add(X, RDFS.LABEL, _6); + + /* + * Note: The either flush() or commit() is required to flush the + * statement buffers to the database before executing any operations + * that go around the sail. + */ + cxn.commit(); + + if (log.isInfoEnabled()) { + log.info(sail.getDatabase().dumpStore()); + } + + { + + String query = + QueryOptimizerEnum.queryHint(QueryOptimizerEnum.None) + + "prefix bd: <"+BD.NAMESPACE+"> " + + "prefix rdf: <"+RDF.NAMESPACE+"> " + + "prefix rdfs: <"+RDFS.NAMESPACE+"> " + + + "select ?p ?o " + + "where { " + + " ?s rdf:type rdfs:Resource . " + +// " ?s ?p \"foo\" . " + + " ?s ?p ?o . " + +// " filter(str(?o) = \"foo\" && regex(str(?o),\"foo\",\"i\")) " + +// " filter(?o = \"foo\") " + + " filter(str(?o) = \"foo\") " + + " filter(str(?p) = \""+RDFS.LABEL+"\") " + + "}"; + + final SailTupleQuery tupleQuery = (SailTupleQuery) + cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); + tupleQuery.setIncludeInferred(false /* includeInferred */); + + if (log.isInfoEnabled()) { + + log.info(query); + +// final BigdataSailTupleQuery bdTupleQuery = +// (BigdataSailTupleQuery) tupleQuery; +// final QueryRoot root = (QueryRoot) bdTupleQuery.getTupleExpr(); +// final Projection p = (Projection) root.getArg(); +// final TupleExpr tupleExpr = p.getArg(); +// final SOpTreeBuilder stb = new SOpTreeBuilder(); +// final SOpTree tree = stb.collectSOps(tupleExpr); + +// log.info(tree); +// log.info(query); + + final TupleQueryResult result = tupleQuery.evaluate(); + while (result.hasNext()) { + log.info(result.next()); + } + + } + +// final Collection<BindingSet> answer = new LinkedList<BindingSet>(); +// answer.add(createBindingSet( +// new BindingImpl("a", paul), +// new BindingImpl("b", mary) +// )); +// answer.add(createBindingSet( +// new BindingImpl("a", brad), +// new BindingImpl("b", john) +// )); +// +// final TupleQueryResult result = tupleQuery.evaluate(); +// compare(result, answer); + + } + + } finally { + cxn.close(); + } + } finally { + if (sail instanceof BigdataSail) + ((BigdataSail)sail).__tearDownUnitTest();//shutDown(); + } + + } + + public void testRegex() throws Exception { + +// final Sail sail = new MemoryStore(); +// try { +// sail.initialize(); +// final Repository repo = new SailRepository(sail); + + final BigdataSail sail = getSail(); + try { + sail.initialize(); + final BigdataSailRepository repo = new BigdataSailRepository(sail); + + final RepositoryConnection cxn = repo.getConnection(); + + try { + cxn.setAutoCommit(false); + + final ValueFactory vf = sail.getValueFactory(); + + /* + * Create some terms. + */ + final URI X = vf.createURI(BD.NAMESPACE + "X"); + final URI dt = vf.createURI(BD.NAMESPACE + "myDatatype"); + final Literal _1 = vf.createLiteral("foo"); + final Literal _2 = vf.createLiteral("foo", XSD.STRING); + final Literal _3 = vf.createLiteral("foo", dt); + final Literal _4 = vf.createLiteral("foo", "EN"); + final Literal _5 = vf.createLiteral(true); + final Literal _6 = vf.createLiteral(1000l); + + /* + * Create some statements. + */ + cxn.add(X, RDF.TYPE, RDFS.RESOURCE); +// cxn.add(X, RDFS.LABEL, _1); + cxn.add(X, RDFS.LABEL, _2); + cxn.add(X, RDFS.LABEL, _3); + cxn.add(X, RDFS.LABEL, _4); + cxn.add(X, RDFS.LABEL, _5); + cxn.add(X, RDFS.LABEL, _6); + + /* + * Note: The either flush() or commit() is required to flush the + * statement buffers to the database before executing any operations + * that go around the sail. + */ + cxn.commit(); + + if (log.isInfoEnabled()) { + log.info(sail.getDatabase().dumpStore()); + } + + { + + String query = + QueryOptimizerEnum.queryHint(QueryOptimizerEnum.None) + + "prefix bd: <"+BD.NAMESPACE+"> " + + "prefix rdf: <"+RDF.NAMESPACE+"> " + + "prefix rdfs: <"+RDFS.NAMESPACE+"> " + + + "select ?o " + + "where { " + + " ?s rdf:type rdfs:Resource . " + + " ?s ?p ?o . " + +// " filter(regex(str(?o), \"FOO\")) " + + " filter(regex(str(?o), \"FOO\", \"i\")) " + + "}"; + + final SailTupleQuery tupleQuery = (SailTupleQuery) + cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); + tupleQuery.setIncludeInferred(false /* includeInferred */); + + if (log.isInfoEnabled()) { + + log.info(query); + +// final BigdataSailTupleQuery bdTupleQuery = +// (BigdataSailTupleQuery) tupleQuery; +// final QueryRoot root = (QueryRoot) bdTupleQuery.getTupleExpr(); +// final Projection p = (Projection) root.getArg(); +// final TupleExpr tupleExpr = p.getArg(); +// final SOpTreeBuilder stb = new SOpTreeBuilder(); +// final SOpTree tree = stb.collectSOps(tupleExpr); + +// log.info(tree); +// log.info(query); + + final TupleQueryResult result = tupleQuery.evaluate(); + while (result.hasNext()) { + log.info(result.next()); + } + + } + +// final Collection<BindingSet> answer = new LinkedList<BindingSet>(); +// answer.add(createBindingSet( +// new BindingImpl("a", paul), +// new BindingImpl("b", mary) +// )); +// answer.add(createBindingSet( +// new BindingImpl("a", brad), +// new BindingImpl("b", john) +// )); +// +// final TupleQueryResult result = tupleQuery.evaluate(); +// compare(result, answer); + + } + + } finally { + cxn.close(); + } + } finally { + if (sail instanceof BigdataSail) + ((BigdataSail)sail).__tearDownUnitTest();//shutDown(); + } + + } + + /* + * PREFIX : <http://example.org/> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> +PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> +SELECT ?s WHERE { + ?s :p ?v . + FILTER(datatype(xsd:boolean(?v)) = xsd:boolean) . +} + */ + + public void testCastAndDatatype() throws Exception { + +// final Sail sail = new MemoryStore(); +// try { +// sail.initialize(); +// final Repository repo = new SailRepository(sail); + + final BigdataSail sail = getSail(); + try { + sail.initialize(); + final BigdataSailRepository repo = new BigdataSailRepository(sail); + + final RepositoryConnection cxn = repo.getConnection(); + + try { + cxn.setAutoCommit(false); + + final ValueFactory vf = sail.getValueFactory(); + + /* + * Create some terms. + */ + final URI X = vf.createURI(BD.NAMESPACE + "X"); + final URI dt = vf.createURI(BD.NAMESPACE + "myDatatype"); + final Literal _1 = vf.createLiteral("foo"); + final Literal _2 = vf.createLiteral("foo", XSD.STRING); + final Literal _3 = vf.createLiteral("foo", dt); + final Literal _4 = vf.createLiteral("foo", "EN"); + final Literal _5 = vf.createLiteral(true); + final Literal _6 = vf.createLiteral(1000l); + + /* + * Create some statements. + */ + cxn.add(X, RDF.TYPE, RDFS.RESOURCE); +// cxn.add(X, RDFS.LABEL, _1); + cxn.add(X, RDFS.LABEL, _2); + cxn.add(X, RDFS.LABEL, _3); + cxn.add(X, RDFS.LABEL, _4); + cxn.add(X, RDFS.LABEL, _5); + cxn.add(X, RDFS.LABEL, _6); + + /* + * Note: The either flush() or commit() is required to flush the + * statement buffers to the database before executing any operations + * that go around the sail. + */ + cxn.commit(); + + if (log.isInfoEnabled()) { + log.info(sail.getDatabase().dumpStore()); + } + + { + + String query = + QueryOptimizerEnum.queryHint(QueryOptimizerEnum.None) + + "prefix bd: <"+BD.NAMESPACE+"> " + + "prefix rdf: <"+RDF.NAMESPACE+"> " + + "prefix rdfs: <"+RDFS.NAMESPACE+"> " + + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " + + + "select ?o " + + "where { " + + " ?s rdf:type rdfs:Resource . " + + " ?s ?p ?o . " + + " FILTER(datatype(xsd:boolean(?o)) = xsd:boolean) . " + + "}"; + + final SailTupleQuery tupleQuery = (SailTupleQuery) + cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); + tupleQuery.setIncludeInferred(false /* includeInferred */); + + if (log.isInfoEnabled()) { + + log.info(query); + +// final BigdataSailTupleQuery bdTupleQuery = +// (BigdataSailTupleQuery) tupleQuery; +// final QueryRoot root = (QueryRoot) bdTupleQuery.getTupleExpr(); +// final Projection p = (Projection) root.getArg(); +// final TupleExpr tupleExpr = p.getArg(); +// final SOpTreeBuilder stb = new SOpTreeBuilder(); +// final SOpTree tree = stb.collectSOps(tupleExpr); + +// log.info(tree); +// log.info(query); + + final TupleQueryResult result = tupleQuery.evaluate(); + while (result.hasNext()) { + log.info(result.next()); + } + + } + +// final Collection<BindingSet> answer = new LinkedList<BindingSet>(); +// answer.add(createBindingSet( +// new BindingImpl("a", paul), +// new BindingImpl("b", mary) +// )); +// answer.add(createBindingSet( +// new BindingImpl("a", brad), +// new BindingImpl("b", john) +// )); +// +// final TupleQueryResult result = tupleQuery.evaluate(); +// compare(result, answer); + + } + + } finally { + cxn.close(); + } + } finally { + if (sail instanceof BigdataSail) + ((BigdataSail)sail).__tearDownUnitTest();//shutDown(); + } + + } + + public void testLang() throws Exception { + +// final Sail sail = new MemoryStore(); +// try { +// sail.initialize(); +// final Repository repo = new SailRepository(sail); + + final BigdataSail sail = getSail(); + try { + sail.initialize(); + final BigdataSailRepository repo = new BigdataSailRepository(sail); + + final RepositoryConnection cxn = repo.getConnection(); + + try { + cxn.setAutoCommit(false); + + final ValueFactory vf = sail.getValueFactory(); + + /* + * Create some terms. + */ + final URI X = vf.createURI(BD.NAMESPACE + "X"); + final URI Y = vf.createURI(BD.NAMESPACE + "Y"); + final Literal _1 = vf.createLiteral("That Seventies Show","en"); + final Literal _2 = vf.createLiteral("Cette S\x8Erie des Ann\x8Ees Soixante-dix","fr"); + final Literal _3 = vf.createLiteral("Cette S\x8Erie des Ann\x8Ees Septante","fr-BE"); + final Literal _4 = vf.createLiteral("Il Buono, il Bruto, il Cattivo"); + + /* + * Create some statements. + */ + cxn.add(X, RDFS.LABEL, _1); + cxn.add(X, RDFS.LABEL, _2); + cxn.add(X, RDFS.LABEL, _3); + cxn.add(Y, RDFS.LABEL, _4); + + /* + * Note: The either flush() or commit() is required to flush the + * statement buffers to the database before executing any operations + * that go around the sail. + */ + cxn.commit(); + + if (log.isInfoEnabled()) { + log.info(sail.getDatabase().dumpStore()); + } + + { + + String query = + QueryOptimizerEnum.queryHint(QueryOptimizerEnum.None) + + "prefix bd: <"+BD.NAMESPACE+"> " + + "prefix rdf: <"+RDF.NAMESPACE+"> " + + "prefix rdfs: <"+RDFS.NAMESPACE+"> " + + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " + + + "select ?title " + + "where { " + + " ?s rdfs:label \"That Seventies Show\"@en . " + + " ?s rdfs:label ?title . " ... [truncated message content] |