From: <tho...@us...> - 2011-06-20 12:42:20
|
Revision: 4739 http://bigdata.svn.sourceforge.net/bigdata/?rev=4739&view=rev Author: thompsonbry Date: 2011-06-20 12:42:13 +0000 (Mon, 20 Jun 2011) Log Message: ----------- Factored out the query hints parser into a utility class and wrote a unit test to verify its behavior for a few simple queries. See https://sourceforge.net/apps/trac/bigdata/ticket/336 Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepositoryConnection.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestAll.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestDescribe.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/QueryHintsUtility.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestQueryHintsUtility.java Removed Paths: ------------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestQueryHints.java Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepositoryConnection.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepositoryConnection.java 2011-06-18 21:21:54 UTC (rev 4738) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailRepositoryConnection.java 2011-06-20 12:42:13 UTC (rev 4739) @@ -1,8 +1,6 @@ package com.bigdata.rdf.sail; -import java.util.Map; import java.util.Properties; -import java.util.StringTokenizer; import org.openrdf.query.MalformedQueryException; import org.openrdf.query.QueryLanguage; @@ -11,9 +9,6 @@ import org.openrdf.query.parser.ParsedQuery; import org.openrdf.query.parser.ParsedTupleQuery; import org.openrdf.query.parser.QueryParserUtil; -import org.openrdf.query.parser.sparql.ast.ASTQueryContainer; -import org.openrdf.query.parser.sparql.ast.ParseException; -import org.openrdf.query.parser.sparql.ast.SyntaxTreeBuilder; import org.openrdf.repository.RepositoryException; import org.openrdf.repository.sail.SailQuery; import org.openrdf.repository.sail.SailRepositoryConnection; @@ -26,9 +21,6 @@ import com.bigdata.rdf.sail.BigdataSail.BigdataSailConnection; import com.bigdata.rdf.sail.bench.NanoSparqlClient; import com.bigdata.rdf.sail.bench.NanoSparqlClient.QueryType; -import com.bigdata.rdf.sail.sparql.BaseDeclProcessor; -import com.bigdata.rdf.sail.sparql.PrefixDeclProcessor; -import com.bigdata.rdf.sail.sparql.StringEscapesProcessor; import com.bigdata.rdf.store.AbstractTripleStore; /** @@ -85,7 +77,8 @@ final ParsedGraphQuery parsedQuery = QueryParserUtil.parseGraphQuery( ql, qs, baseURI); - final Properties queryHints = parseQueryHints(ql, qs, baseURI); + final Properties queryHints = QueryHintsUtility.parseQueryHints(ql, qs, + baseURI); final boolean describe = ql == QueryLanguage.SPARQL && NanoSparqlClient.QueryType.fromQuery(qs) == QueryType.DESCRIBE; @@ -110,7 +103,8 @@ final ParsedTupleQuery parsedQuery = QueryParserUtil.parseTupleQuery( ql, queryString, baseURI); - final Properties queryHints = parseQueryHints(ql, queryString, baseURI); + final Properties queryHints = QueryHintsUtility.parseQueryHints(ql, + queryString, baseURI); return new BigdataSailTupleQuery(parsedQuery, this, queryHints); @@ -131,7 +125,8 @@ final ParsedBooleanQuery parsedQuery = QueryParserUtil .parseBooleanQuery(ql, queryString, baseURI); - final Properties queryHints = parseQueryHints(ql, queryString, baseURI); + final Properties queryHints = QueryHintsUtility.parseQueryHints(ql, + queryString, baseURI); return new BigdataSailBooleanQuery(parsedQuery, this, queryHints); @@ -151,7 +146,8 @@ final ParsedQuery parsedQuery = QueryParserUtil.parseQuery(ql, qs, baseURI); - final Properties queryHints = parseQueryHints(ql, qs, baseURI); + final Properties queryHints = QueryHintsUtility.parseQueryHints(ql, qs, + baseURI); if (parsedQuery instanceof ParsedTupleQuery) { @@ -322,60 +318,8 @@ } } - + /** - * Parse query hints from a query string. Query hints are embedded in the - * query string via special namespaces. - * See {@link QueryHints#PREFIX} for more information. - */ - private Properties parseQueryHints(final QueryLanguage ql, - final String queryString, final String baseURI) - throws MalformedQueryException { - try { - final Properties queryHints = new Properties(); - // currently only supporting SPARQL - if (ql == QueryLanguage.SPARQL) { - // the next four lines were taken directly from - // org.openrdf.query.parser.sparql.SPARQLParser.parseQuery(String queryStr, String baseURI) - final ASTQueryContainer qc = SyntaxTreeBuilder.parseQuery(queryString); - StringEscapesProcessor.process(qc); - BaseDeclProcessor.process(qc, baseURI); - final Map<String, String> prefixes = PrefixDeclProcessor - .process(qc); - // iterate the namespaces - for (Map.Entry<String, String> prefix : prefixes.entrySet()) { - // if we see one that matches the magic namespace, try - // to parse it - if (prefix.getKey().equalsIgnoreCase(QueryHints.PREFIX)) { - String hints = prefix.getValue(); - // has to have a # and it can't be at the end - int i = hints.indexOf('#'); - if (i < 0 || i == hints.length()-1) { - throw new MalformedQueryException("bad query hints: " + hints); - } - hints = hints.substring(i+1); - // properties are separated by & - final StringTokenizer st = new StringTokenizer(hints, "&"); - while (st.hasMoreTokens()) { - String hint = st.nextToken(); - i = hint.indexOf('='); - if (i < 0 || i == hint.length()-1) { - throw new MalformedQueryException("bad query hint: " + hint); - } - final String key = hint.substring(0, i); - final String val = hint.substring(i+1); - queryHints.put(key, val); - } - } - } - } - return queryHints; - } catch (ParseException e) { - throw new MalformedQueryException(e.getMessage(), e); - } - } - - /** * Set the change log on the SAIL connection. See {@link IChangeLog} and * {@link IChangeRecord}. * Added: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/QueryHintsUtility.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/QueryHintsUtility.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/QueryHintsUtility.java 2011-06-20 12:42:13 UTC (rev 4739) @@ -0,0 +1,143 @@ +/** + +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 +*/ +/* +Portions of this code are: + +Copyright Aduna (http://www.aduna-software.com/) � 2001-2007 + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ +/* + * Created on Jun 20, 2011 + */ + +package com.bigdata.rdf.sail; + +import java.util.Map; +import java.util.Properties; +import java.util.StringTokenizer; + +import org.openrdf.query.MalformedQueryException; +import org.openrdf.query.QueryLanguage; +import org.openrdf.query.parser.sparql.ast.ASTQueryContainer; +import org.openrdf.query.parser.sparql.ast.ParseException; +import org.openrdf.query.parser.sparql.ast.SyntaxTreeBuilder; + +import com.bigdata.rdf.sail.sparql.BaseDeclProcessor; +import com.bigdata.rdf.sail.sparql.PrefixDeclProcessor; +import com.bigdata.rdf.sail.sparql.StringEscapesProcessor; + +/** + * A utility class for parsing {@link QueryHints}. + * + * @author <a href="mailto:mrp...@us...">Mike Personick</a> + * @version $Id$ + */ +public class QueryHintsUtility { + + /** + * Parse query hints from a query string. Query hints are embedded in the + * query string via special namespaces. + * <p> + * Note: The Sesame operator tree does not include the original query hints, + * which is why this method is not written against the operator tree. + * + * See {@link QueryHints#PREFIX} for more information. + */ + public static Properties parseQueryHints(final QueryLanguage ql, + final String queryString, final String baseURI) + throws MalformedQueryException { + try { + final Properties queryHints = new Properties(); + // currently only supporting SPARQL + if (ql == QueryLanguage.SPARQL) { + // the next four lines were taken directly from + // org.openrdf.query.parser.sparql.SPARQLParser.parseQuery(String queryStr, String baseURI) + final ASTQueryContainer qc = SyntaxTreeBuilder + .parseQuery(queryString); + StringEscapesProcessor.process(qc); + BaseDeclProcessor.process(qc, baseURI); + final Map<String, String> prefixes = PrefixDeclProcessor + .process(qc); + // iterate the namespaces + for (Map.Entry<String, String> prefix : prefixes.entrySet()) { + // if we see one that matches the magic namespace, try + // to parse it + if (prefix.getKey().equalsIgnoreCase(QueryHints.PREFIX)) { + String hints = prefix.getValue(); + // has to have a # and it can't be at the end + int i = hints.indexOf('#'); + if (i < 0 || i == hints.length() - 1) { + throw new MalformedQueryException( + "bad query hints: " + hints); + } + hints = hints.substring(i + 1); + // properties are separated by & + final StringTokenizer st = new StringTokenizer(hints, + "&"); + while (st.hasMoreTokens()) { + final String hint = st.nextToken(); + i = hint.indexOf('='); + if (i < 0 || i == hint.length() - 1) { + throw new MalformedQueryException( + "bad query hint: " + hint); + } + final String key = hint.substring(0, i); + final String val = hint.substring(i+1); + queryHints.put(key, val); + } + } + } + } + return queryHints; + } catch (ParseException e) { + throw new MalformedQueryException(e.getMessage(), e); + } + } + +} Property changes on: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/QueryHintsUtility.java ___________________________________________________________________ Added: svn:keywords + Id Date Revision Author HeadURL Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestAll.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestAll.java 2011-06-18 21:21:54 UTC (rev 4738) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestAll.java 2011-06-20 12:42:13 UTC (rev 4739) @@ -80,7 +80,10 @@ } final TestSuite suite = new TestSuite("Sesame 2.x integration"); - + + // unit tests for extracting query hints from a SPARQL query. + suite.addTestSuite(TestQueryHintsUtility.class); + // bootstrap tests for the BigdataSail suite.addTestSuite(TestBootstrapBigdataSail.class); Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestDescribe.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestDescribe.java 2011-06-18 21:21:54 UTC (rev 4738) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestDescribe.java 2011-06-20 12:42:13 UTC (rev 4739) @@ -49,12 +49,12 @@ */ public class TestDescribe extends ProxyBigdataSailTestCase { - protected static Logger log = Logger.getLogger(TestDescribe.class); + private static Logger log = Logger.getLogger(TestDescribe.class); @Override public Properties getProperties() { - Properties props = super.getProperties(); + final Properties props = super.getProperties(); props.setProperty(BigdataSail.Options.TRUTH_MAINTENANCE, "false"); props.setProperty(BigdataSail.Options.AXIOMS_CLASS, NoAxioms.class.getName()); @@ -82,6 +82,7 @@ public void testSingleDescribe() throws Exception { final BigdataSail sail = getSail(); + try { sail.initialize(); final BigdataSailRepository repo = new BigdataSailRepository(sail); final BigdataSailRepositoryConnection cxn = @@ -90,14 +91,14 @@ try { - URI mike = new URIImpl(BD.NAMESPACE+"Mike"); - URI bryan = new URIImpl(BD.NAMESPACE+"Bryan"); - URI person = new URIImpl(BD.NAMESPACE+"Person"); - URI likes = new URIImpl(BD.NAMESPACE+"likes"); - URI rdf = new URIImpl(BD.NAMESPACE+"RDF"); - URI rdfs = new URIImpl(BD.NAMESPACE+"RDFS"); - Literal label1 = new LiteralImpl("Mike"); - Literal label2 = new LiteralImpl("Bryan"); + final URI mike = new URIImpl(BD.NAMESPACE+"Mike"); + final URI bryan = new URIImpl(BD.NAMESPACE+"Bryan"); + final URI person = new URIImpl(BD.NAMESPACE+"Person"); + final URI likes = new URIImpl(BD.NAMESPACE+"likes"); + final URI rdf = new URIImpl(BD.NAMESPACE+"RDF"); + final URI rdfs = new URIImpl(BD.NAMESPACE+"RDFS"); + final Literal label1 = new LiteralImpl("Mike"); + final Literal label2 = new LiteralImpl("Bryan"); /**/ cxn.add(mike, RDF.TYPE, person); cxn.add(mike, likes, rdf); @@ -121,7 +122,7 @@ { - String query = + final String query = "prefix bd: <"+BD.NAMESPACE+"> " + "prefix rdf: <"+RDF.NAMESPACE+"> " + "prefix rdfs: <"+RDFS.NAMESPACE+"> " + @@ -171,20 +172,22 @@ */ final BigdataSailGraphQuery graphQuery = (BigdataSailGraphQuery) cxn.prepareGraphQuery(QueryLanguage.SPARQL, query); - GraphQueryResult result = graphQuery.evaluate(); + final GraphQueryResult result = graphQuery.evaluate(); final TupleExpr tupleExpr = graphQuery.getTupleExpr(); - log.info(tupleExpr); + if(log.isInfoEnabled()) + log.info(tupleExpr); while(result.hasNext()) { - Statement s = result.next(); - log.info(s); + final Statement s = result.next(); + if(log.isInfoEnabled()) + log.info(s); } } { - String query = + final String query = "construct { " + " ?x ?p1 ?o . " + " ?s ?p2 ?x . " + @@ -220,20 +223,26 @@ */ final BigdataSailGraphQuery graphQuery = (BigdataSailGraphQuery) cxn.prepareGraphQuery(QueryLanguage.SPARQL, query); - GraphQueryResult result = graphQuery.evaluate(); + final GraphQueryResult result = graphQuery.evaluate(); final TupleExpr tupleExpr = graphQuery.getTupleExpr(); - log.info(tupleExpr); + if(log.isInfoEnabled()) + log.info(tupleExpr); while(result.hasNext()) { - Statement s = result.next(); - log.info(s); + final Statement s = result.next(); + if(log.isInfoEnabled()) + log.info(s); } } } finally { + cxn.close(); + + } + } finally { sail.__tearDownUnitTest(); } @@ -242,6 +251,7 @@ public void testMultiDescribe() throws Exception { final BigdataSail sail = getSail(); + try { sail.initialize(); final BigdataSailRepository repo = new BigdataSailRepository(sail); final BigdataSailRepositoryConnection cxn = @@ -250,13 +260,13 @@ try { - URI mike = new URIImpl("_:Mike"); - URI person = new URIImpl("_:Person"); - URI likes = new URIImpl("_:likes"); - URI rdf = new URIImpl("_:RDF"); - URI thing = new URIImpl("_:Thing"); - Literal l1 = new LiteralImpl("Mike"); - Literal l2 = new LiteralImpl("RDF"); + final URI mike = new URIImpl("_:Mike"); + final URI person = new URIImpl("_:Person"); + final URI likes = new URIImpl("_:likes"); + final URI rdf = new URIImpl("_:RDF"); + final URI thing = new URIImpl("_:Thing"); + final Literal l1 = new LiteralImpl("Mike"); + final Literal l2 = new LiteralImpl("RDF"); /**/ cxn.add(mike, RDF.TYPE, person); cxn.add(mike, RDFS.LABEL, l1); @@ -279,7 +289,7 @@ { - String query = + final String query = "describe ?x ?y " + "WHERE { " + " ?x <"+likes+"> ?y . " + @@ -311,20 +321,23 @@ */ final BigdataSailGraphQuery graphQuery = (BigdataSailGraphQuery) cxn.prepareGraphQuery(QueryLanguage.SPARQL, query); - GraphQueryResult result = graphQuery.evaluate(); + final GraphQueryResult result = graphQuery.evaluate(); final TupleExpr tupleExpr = graphQuery.getTupleExpr(); - log.info(tupleExpr); + if(log.isInfoEnabled()) + log.info(tupleExpr); while(result.hasNext()) { - Statement s = result.next(); - log.info(s); + final Statement s = result.next(); + if(log.isInfoEnabled()) + log.info(s); } } - } finally { cxn.close(); + } + } finally { sail.__tearDownUnitTest(); } Deleted: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestQueryHints.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestQueryHints.java 2011-06-18 21:21:54 UTC (rev 4738) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestQueryHints.java 2011-06-20 12:42:13 UTC (rev 4739) @@ -1,136 +0,0 @@ -/** -Copyright (C) SYSTAP, LLC 2006-2007. All rights reserved. - -Contact: - SYSTAP, LLC - 4501 Tower Road - Greensboro, NC 27410 - lic...@bi... - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ -/* - * Created on Sep 16, 2009 - */ - -package com.bigdata.rdf.sail; - -import java.util.Collection; -import java.util.LinkedList; - -import org.openrdf.model.URI; -import org.openrdf.model.impl.URIImpl; -import org.openrdf.query.BindingSet; -import org.openrdf.query.QueryLanguage; -import org.openrdf.query.TupleQuery; -import org.openrdf.query.TupleQueryResult; -import org.openrdf.query.impl.BindingImpl; - -import com.bigdata.bop.PipelineOp; - -/** - * Unit tests the query hints aspect of the {@link BigdataSail} implementation. - * - * @author <a href="mailto:mrp...@us...">Mike Personick</a> - * @version $Id$ - */ -public class TestQueryHints extends QuadsTestCase { - - /** - * - */ - public TestQueryHints() { - } - - /** - * @param arg0 - */ - public TestQueryHints(String arg0) { - super(arg0); - } - - /** - * Tests adding query hints in SPARQL. - * - * @throws Exception - * - * @todo Unfortunately, this does not really _test_ anything since the query - * should be answered correctly regardless of the query hint(s) - * specified. - */ - public void testQueryHints() throws Exception { - - final BigdataSail sail = getSail(); - sail.initialize(); - final BigdataSailRepository repo = new BigdataSailRepository(sail); - final BigdataSailRepositoryConnection cxn = - (BigdataSailRepositoryConnection) repo.getConnection(); - cxn.setAutoCommit(false); - - try { - - URI a = new URIImpl("_:A"); - URI b = new URIImpl("_:B"); - URI c = new URIImpl("_:C"); -/**/ - cxn.add(a, b, c); -/**/ - - /* - * 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.flush();//commit(); - -/**/ - if (log.isInfoEnabled()) { - log.info("\n" + sail.getDatabase().dumpStore()); - } - - { - - final String query = "PREFIX " + QueryHints.PREFIX - + ": " + "<http://www.bigdata.com/queryOption#" + // - PipelineOp.Annotations.MAX_PARALLEL + "=-5" // - + "&" + "com.bigdata.fullScanTreshold=1000" // - + ">\n"// - + "SELECT * " + // - "WHERE { " + // - " <" + a + "> ?p ?o " + // - "}"; - - final TupleQuery tupleQuery = - cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); - tupleQuery.setIncludeInferred(true /* includeInferred */); - final TupleQueryResult result = tupleQuery.evaluate(); - - final Collection<BindingSet> answer = new LinkedList<BindingSet>(); - answer.add(createBindingSet( - new BindingImpl("p", b), - new BindingImpl("o", c) - )); - - compare(result, answer); - - } - - } finally { - cxn.close(); - sail.__tearDownUnitTest(); - } - - } - -} Added: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestQueryHintsUtility.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestQueryHintsUtility.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestQueryHintsUtility.java 2011-06-20 12:42:13 UTC (rev 4739) @@ -0,0 +1,155 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + * Created on Jun 20, 2011 + */ + +package com.bigdata.rdf.sail; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Properties; + +import junit.framework.TestCase2; + +import org.openrdf.model.URI; +import org.openrdf.model.impl.URIImpl; +import org.openrdf.model.vocabulary.RDF; +import org.openrdf.model.vocabulary.RDFS; +import org.openrdf.query.MalformedQueryException; +import org.openrdf.query.QueryLanguage; + +import com.bigdata.bop.PipelineOp; +import com.bigdata.rdf.store.BD; + +/** + * Unit test for {@link QueryHintsUtility}. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + */ +public class TestQueryHintsUtility extends TestCase2 { + + /** + * + */ + public TestQueryHintsUtility() { + } + + /** + * @param name + */ + public TestQueryHintsUtility(String name) { + super(name); + } + + public void test_selectQuery() throws MalformedQueryException { + + final Map<String,String> expected = new LinkedHashMap<String, String>(); + { + + expected.put(PipelineOp.Annotations.MAX_PARALLEL,"-5"); + + expected.put("com.bigdata.fullScanTreshold","1000"); + + } + + final QueryLanguage ql = QueryLanguage.SPARQL; + + final String baseURI = "http://www.bigdata.com/sparql"; + + final URI a = new URIImpl("_:A"); + + final String qs = // + "PREFIX " + QueryHints.PREFIX + ": " + // + "<http://www.bigdata.com/queryOption" + // + "#" + PipelineOp.Annotations.MAX_PARALLEL + "=-5" + // + "&" + "com.bigdata.fullScanTreshold=1000" // + + ">\n"// + + "SELECT * " + "WHERE { " + " <" + a + "> ?p ?o " + "}"; + + final Properties actual = QueryHintsUtility.parseQueryHints(ql, qs, + baseURI); + + assertSameProperties(expected, actual); + + } + + public void test_describeQuery() throws MalformedQueryException { + + final Map<String,String> expected = new LinkedHashMap<String, String>(); + { + + expected.put(PipelineOp.Annotations.MAX_PARALLEL,"-5"); + + expected.put("com.bigdata.fullScanTreshold","1000"); + + } + + final QueryLanguage ql = QueryLanguage.SPARQL; + + final String baseURI = "http://www.bigdata.com/sparql"; + + final String qs = + "prefix bd: <"+BD.NAMESPACE+"> " + + "prefix rdf: <"+RDF.NAMESPACE+"> " + + "prefix rdfs: <"+RDFS.NAMESPACE+"> " + + "PREFIX " + QueryHints.PREFIX + ": " + // + "<http://www.bigdata.com/queryOption" + // + "#" + PipelineOp.Annotations.MAX_PARALLEL + "=-5" + // + "&" + "com.bigdata.fullScanTreshold=1000" // + + ">\n"+// + "describe ?x " +// + "WHERE { " +// + " ?x rdf:type bd:Person . " +// + " ?x bd:likes bd:RDF " +// + "}"; + + final Properties actual = QueryHintsUtility.parseQueryHints(ql, qs, + baseURI); + + assertSameProperties(expected, actual); + + } + + private static void assertSameProperties( + final Map<String, String> expected, final Properties actual) { + + assertEquals("size", expected.size(), actual.size()); + + for (Map.Entry<String, String> e : expected.entrySet()) { + + final String name = e.getKey(); + + final String expectedValue = e.getValue(); + + final String actualValue = actual.getProperty(name); + + assertEquals(name, expectedValue, actualValue); + + } + + } + +} Property changes on: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestQueryHintsUtility.java ___________________________________________________________________ Added: svn:keywords + Id Date Revision Author HeadURL This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |