From: <mrp...@us...> - 2011-02-24 23:10:49
|
Revision: 4247 http://bigdata.svn.sourceforge.net/bigdata/?rev=4247&view=rev Author: mrpersonick Date: 2011-02-24 23:10:42 +0000 (Thu, 24 Feb 2011) Log Message: ----------- changed how describe is optimized Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailGraphQuery.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestDescribe.java Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailGraphQuery.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailGraphQuery.java 2011-02-24 20:33:29 UTC (rev 4246) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataSailGraphQuery.java 2011-02-24 23:10:42 UTC (rev 4247) @@ -10,6 +10,8 @@ import java.util.LinkedList; import java.util.Properties; import java.util.Set; + +import org.apache.log4j.Logger; import org.openrdf.model.Resource; import org.openrdf.model.Statement; import org.openrdf.model.URI; @@ -46,6 +48,8 @@ public class BigdataSailGraphQuery extends SailGraphQuery implements BigdataSailQuery { + protected static Logger log = Logger.getLogger(BigdataSailGraphQuery.class); + /** * Query hints are embedded in query strings as namespaces. * See {@link QueryHints#NAMESPACE} for more information. @@ -74,8 +78,10 @@ protected void optimizeDescribe() { try { - ParsedQuery parsedQuery = getParsedQuery(); + ParsedQuery parsedQuery = getParsedQuery(); TupleExpr node = parsedQuery.getTupleExpr(); + if (log.isInfoEnabled()) + log.info(node); node = ((Reduced) node).getArg(); node = ((Projection) node).getArg(); ValueExpr ve = ((Filter) node).getCondition(); @@ -90,7 +96,7 @@ vars.add(var); } }); - Collection<Join> joins = new LinkedList<Join>(); + Collection<StatementPattern> sps = new LinkedList<StatementPattern>(); Collection<ProjectionElemList> projElemLists = new LinkedList<ProjectionElemList>(); for (Var v : vars) { @@ -98,7 +104,7 @@ Var p = createAnonVar("-p" + v.getName() + "-1"); Var o = createAnonVar("-o" + v.getName()); StatementPattern sp = new StatementPattern(v, p, o); - joins.add(new Join(node, sp)); + sps.add(sp); ProjectionElemList projElemList = new ProjectionElemList(); projElemList.addElement(new ProjectionElem(v.getName(), "subject")); projElemList.addElement(new ProjectionElem(p.getName(), "predicate")); @@ -109,7 +115,7 @@ Var s = createAnonVar("-s" + v.getName()); Var p = createAnonVar("-p" + v.getName() + "-2"); StatementPattern sp = new StatementPattern(s, p, v); - joins.add(new Join(node, sp)); + sps.add(sp); ProjectionElemList projElemList = new ProjectionElemList(); projElemList.addElement(new ProjectionElem(s.getName(), "subject")); projElemList.addElement(new ProjectionElem(p.getName(), "predicate")); @@ -117,12 +123,12 @@ projElemLists.add(projElemList); } } - Iterator<Join> it = joins.iterator(); - node = it.next(); + Iterator<StatementPattern> it = sps.iterator(); + Union union = new Union(it.next(), it.next()); while (it.hasNext()) { - Join j = it.next(); - node = new Union(j, node); + union = new Union(union, it.next()); } + node = new Join(node, union); node = new MultiProjection(node, projElemLists); node = new Reduced(node); parsedQuery.setTupleExpr(node); 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-02-24 20:33:29 UTC (rev 4246) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestDescribe.java 2011-02-24 23:10:42 UTC (rev 4247) @@ -23,9 +23,9 @@ package com.bigdata.rdf.sail; -import java.util.Collection; -import java.util.LinkedList; import java.util.Properties; + +import org.apache.log4j.Logger; import org.openrdf.model.Literal; import org.openrdf.model.Statement; import org.openrdf.model.URI; @@ -33,16 +33,15 @@ import org.openrdf.model.impl.URIImpl; import org.openrdf.model.vocabulary.RDF; import org.openrdf.model.vocabulary.RDFS; -import org.openrdf.query.Binding; import org.openrdf.query.BindingSet; -import org.openrdf.query.GraphQuery; import org.openrdf.query.GraphQueryResult; import org.openrdf.query.QueryLanguage; import org.openrdf.query.TupleQuery; import org.openrdf.query.TupleQueryResult; import org.openrdf.query.algebra.TupleExpr; -import org.openrdf.query.impl.BindingImpl; + import com.bigdata.rdf.axioms.NoAxioms; +import com.bigdata.rdf.store.BD; import com.bigdata.rdf.vocab.NoVocabulary; /** @@ -51,6 +50,8 @@ */ public class TestDescribe extends ProxyBigdataSailTestCase { + protected static Logger log = Logger.getLogger(TestDescribe.class); + @Override public Properties getProperties() { @@ -90,15 +91,21 @@ try { - URI mike = new URIImpl("_:Mike"); - URI person = new URIImpl("_:Person"); - URI likes = new URIImpl("_:likes"); - URI rdf = new URIImpl("_:RDF"); - Literal label = new LiteralImpl("Mike"); + 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"); /**/ cxn.add(mike, RDF.TYPE, person); cxn.add(mike, likes, rdf); - cxn.add(mike, RDFS.LABEL, label); + cxn.add(mike, RDFS.LABEL, label1); + cxn.add(bryan, RDF.TYPE, person); + cxn.add(bryan, likes, rdfs); + cxn.add(bryan, RDFS.LABEL, label2); /**/ /* @@ -116,11 +123,21 @@ { String query = -// "describe ?x " + -// "WHERE { " + -// " ?x <"+RDF.TYPE+"> <"+person+"> . " + -// "}"; - "describe <"+mike+">"; + "prefix bd: <"+BD.NAMESPACE+"> " + + "prefix rdf: <"+RDF.NAMESPACE+"> " + + "prefix rdfs: <"+RDFS.NAMESPACE+"> " + + + "describe ?x " + + "WHERE { " + +// " { " + + " ?x rdf:type bd:Person . " + + " ?x bd:likes bd:RDF " + +// " } union { " + +// " ?x rdf:type bd:Person . " + +// " ?x bd:likes bd:RDFS " + +// " } " + + "}"; +// "describe <"+mike+">"; // "construct { " + // " <"+mike+"> ?p1 ?o . " + // " ?s ?p2 <"+mike+"> . " + @@ -158,25 +175,28 @@ GraphQueryResult result = graphQuery.evaluate(); final TupleExpr tupleExpr = graphQuery.getTupleExpr(); - System.err.println(tupleExpr); + log.info(tupleExpr); while(result.hasNext()) { Statement s = result.next(); - System.err.println(s); + log.info(s); } } { String query = - "construct { " + - " ?x ?px1 ?ox . " + - " ?sx ?px2 ?x . " + + "construct { " + + " ?x ?p1 ?o . " + + " ?s ?p2 ?x . " + "} " + "WHERE { " + " ?x <"+RDF.TYPE+"> <"+person+"> . " + - " OPTIONAL { ?x ?px1 ?ox . } . " + - " OPTIONAL { ?sx ?px2 ?x . } . " + + " {" + + " ?x ?p1 ?ox . " + + " } UNION {" + + " ?sx ?p2 ?x . " + + " } " + "}"; /* @@ -204,11 +224,11 @@ GraphQueryResult result = graphQuery.evaluate(); final TupleExpr tupleExpr = graphQuery.getTupleExpr(); - System.err.println(tupleExpr); + log.info(tupleExpr); while(result.hasNext()) { Statement s = result.next(); - System.err.println(s); + log.info(s); } } @@ -295,148 +315,15 @@ GraphQueryResult result = graphQuery.evaluate(); final TupleExpr tupleExpr = graphQuery.getTupleExpr(); - System.err.println(tupleExpr); + log.info(tupleExpr); while(result.hasNext()) { Statement s = result.next(); - System.err.println(s); + log.info(s); } } - { - - String query = -// "construct {" + -// " ?x ?px1 ?ox . " + -// " ?sx ?px2 ?x . " + -// " ?y ?py1 ?oy . " + -// " ?sy ?py2 ?y . " + -// "} " + - "SELECT * " + - "WHERE { " + - " ?x <"+likes+"> ?y . " + - " OPTIONAL { ?x ?px1 ?ox . } . " + - " OPTIONAL { ?sx ?px2 ?x . } . " + - " OPTIONAL { ?y ?py1 ?oy . } . " + - " OPTIONAL { ?sy ?py2 ?y . } . " + - "}"; - -/* - construct { - ?s ?p ?o . - } - where { - ?x likes ?y . - ?s ?p ?o . - FILTER(?s == ?x || ?o == ?x || ?s == ?y || ?o == ?y) . - } - - construct { - ?x ?px1 ?ox . - ?sx ?px2 ?x . - ?y ?py1 ?oy . - ?sy ?py2 ?y . - } - where { - ?x likes ?y . - OPTIONAL { ?x ?px1 ?ox . } . - OPTIONAL { ?sx ?px2 ?x . } . - OPTIONAL { ?y ?py1 ?oy . } . - OPTIONAL { ?sy ?py2 ?y . } . - } -*/ -/* - final BigdataSailGraphQuery graphQuery = (BigdataSailGraphQuery) - cxn.prepareGraphQuery(QueryLanguage.SPARQL, query); - GraphQueryResult result = graphQuery.evaluate(); - - final TupleExpr tupleExpr = graphQuery.getTupleExpr(); - System.err.println(tupleExpr); - - while(result.hasNext()) { - Statement s = result.next(); - System.err.println(s); - } -*/ - final TupleQuery tupleQuery = - cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); - final TupleQueryResult result = tupleQuery.evaluate(); - - while(result.hasNext()) { - BindingSet bs = result.next(); - System.err.println(bs); - } - - } - { - - String query = -// "construct {" + -// " ?x ?px1 ?ox . " + -// " ?sx ?px2 ?x . " + -// " ?y ?py1 ?oy . " + -// " ?sy ?py2 ?y . " + -// "} " + - "SELECT * " + - "WHERE { " + - " { ?x <"+likes+"> ?y . ?x ?px1 ?ox . } " + - " UNION " + - " { ?x <"+likes+"> ?y . ?sx ?px2 ?x . } " + - " UNION " + - " { ?x <"+likes+"> ?y . ?y ?py1 ?oy . } " + - " UNION " + - " { ?x <"+likes+"> ?y . ?sy ?py2 ?y . } " + - "}"; - -/* - construct { - ?s ?p ?o . - } - where { - ?x likes ?y . - ?s ?p ?o . - FILTER(?s == ?x || ?o == ?x || ?s == ?y || ?o == ?y) . - } - - construct { - ?x ?px1 ?ox . - ?sx ?px2 ?x . - ?y ?py1 ?oy . - ?sy ?py2 ?y . - } - where { - ?x likes ?y . - OPTIONAL { ?x ?px1 ?ox . } . - OPTIONAL { ?sx ?px2 ?x . } . - OPTIONAL { ?y ?py1 ?oy . } . - OPTIONAL { ?sy ?py2 ?y . } . - } -*/ -/* - final BigdataSailGraphQuery graphQuery = (BigdataSailGraphQuery) - cxn.prepareGraphQuery(QueryLanguage.SPARQL, query); - GraphQueryResult result = graphQuery.evaluate(); - - final TupleExpr tupleExpr = graphQuery.getTupleExpr(); - System.err.println(tupleExpr); - - while(result.hasNext()) { - Statement s = result.next(); - System.err.println(s); - } -*/ - final TupleQuery tupleQuery = - cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); - final TupleQueryResult result = tupleQuery.evaluate(); - - while(result.hasNext()) { - BindingSet bs = result.next(); - System.err.println(bs); - } - - } - } finally { cxn.close(); sail.__tearDownUnitTest(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |