http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/MongoGeoIndexer.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/MongoGeoIndexer.java b/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/MongoGeoIndexer.java deleted file mode 100644 index c36b125..0000000 --- a/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/MongoGeoIndexer.java +++ /dev/null @@ -1,259 +0,0 @@ -package mvm.rya.indexing.mongodb; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -import info.aduna.iteration.CloseableIteration; - -import java.io.IOException; -import java.net.UnknownHostException; -import java.util.Arrays; -import java.util.Set; - -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.resolver.RyaToRdfConversions; -import mvm.rya.indexing.GeoIndexer; -import mvm.rya.indexing.StatementContraints; -import mvm.rya.indexing.accumulo.ConfigUtils; -import mvm.rya.indexing.mongodb.GeoMongoDBStorageStrategy.GeoQueryType; -import mvm.rya.mongodb.MongoDBRdfConfiguration; - -import org.apache.hadoop.conf.Configuration; -import org.apache.log4j.Logger; -import org.openrdf.model.Literal; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.query.QueryEvaluationException; - -import com.mongodb.DB; -import com.mongodb.DBCollection; -import com.mongodb.DBCursor; -import com.mongodb.DBObject; -import com.mongodb.MongoClient; -import com.mongodb.MongoCredential; -import com.mongodb.ServerAddress; -import com.vividsolutions.jts.geom.Geometry; - -public class MongoGeoIndexer extends AbstractMongoIndexer implements GeoIndexer{ - - private static final Logger logger = Logger.getLogger(MongoGeoIndexer.class); - - private GeoMongoDBStorageStrategy storageStrategy; - private MongoClient mongoClient; - private DB db; - private DBCollection coll; - private Set<URI> predicates; - private Configuration conf; - private boolean isInit = false; - private String tableName = ""; - - - - private void init() throws NumberFormatException, UnknownHostException{ - ServerAddress server = new ServerAddress(conf.get(MongoDBRdfConfiguration.MONGO_INSTANCE), - Integer.valueOf(conf.get(MongoDBRdfConfiguration.MONGO_INSTANCE_PORT))); - this.conf = conf; - if (conf.get(MongoDBRdfConfiguration.MONGO_USER) != null){ - MongoCredential cred = MongoCredential.createCredential(conf.get(MongoDBRdfConfiguration.MONGO_USER), conf.get(MongoDBRdfConfiguration.MONGO_USER_PASSWORD), - conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME).toCharArray()); - mongoClient = new MongoClient(server, Arrays.asList(cred)); - } - else { - mongoClient = new MongoClient(server); - } - predicates = ConfigUtils.getGeoPredicates(conf); - tableName = conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME); - db = mongoClient.getDB(tableName); - coll = db.getCollection(conf.get(MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX, "rya") + "_geo"); - storageStrategy = new GeoMongoDBStorageStrategy(Double.valueOf(conf.get(MongoDBRdfConfiguration.MONGO_GEO_MAXDISTANCE, "1e-10"))); - } - - - @Override - public String getTableName() { - return tableName; - } - - @Override - public Configuration getConf() { - return conf; - } - - //setConf initializes because index is created via reflection - @Override - public void setConf(Configuration conf) { - this.conf = conf; - if (!isInit) { - try { - init(); - isInit = true; - } catch (NumberFormatException e) { - logger.warn("Unable to initialize index. Throwing Runtime Exception. ", e); - throw new RuntimeException(e); - } catch (UnknownHostException e) { - logger.warn("Unable to initialize index. Throwing Runtime Exception. ", e); - throw new RuntimeException(e); - } - } - } - - - - private void storeStatement(Statement statement) throws IOException { - // if this is a valid predicate and a valid geometry - boolean isValidPredicate = predicates.isEmpty() || predicates.contains(statement.getPredicate()); - - if (isValidPredicate && (statement.getObject() instanceof Literal)) { - - // add it to the collection - try { - DBObject obj = storageStrategy.serialize(statement); - if (obj != null){ - coll.insert(obj); - } - } - catch (com.mongodb.MongoException.DuplicateKey exception){ - // ignore - } - catch (com.mongodb.DuplicateKeyException exception){ - // ignore - } - catch (Exception ex){ - // ignore single exceptions - ex.printStackTrace(); - } - } - } - - - @Override - public void storeStatement(RyaStatement statement) throws IOException { - storeStatement(RyaToRdfConversions.convertStatement(statement)); - } - - - - - @Override - public CloseableIteration<Statement, QueryEvaluationException> queryEquals( - Geometry query, StatementContraints contraints) { - DBObject queryObj = storageStrategy.getQuery(contraints, query, GeoQueryType.EQUALS); - return getIteratorWrapper(queryObj, coll, storageStrategy); - } - - @Override - public CloseableIteration<Statement, QueryEvaluationException> queryDisjoint( - Geometry query, StatementContraints contraints) { - throw new UnsupportedOperationException("Disjoint queries are not supported in Mongo DB."); - } - - @Override - public CloseableIteration<Statement, QueryEvaluationException> queryIntersects( - Geometry query, StatementContraints contraints) { - DBObject queryObj = storageStrategy.getQuery(contraints, query, GeoQueryType.INTERSECTS); - return getIteratorWrapper(queryObj, coll, storageStrategy); - } - - @Override - public CloseableIteration<Statement, QueryEvaluationException> queryTouches( - Geometry query, StatementContraints contraints) { - throw new UnsupportedOperationException("Touches queries are not supported in Mongo DB."); - } - - @Override - public CloseableIteration<Statement, QueryEvaluationException> queryCrosses( - Geometry query, StatementContraints contraints) { - throw new UnsupportedOperationException("Crosses queries are not supported in Mongo DB."); - } - - @Override - public CloseableIteration<Statement, QueryEvaluationException> queryWithin( - Geometry query, StatementContraints contraints) { - DBObject queryObj = storageStrategy.getQuery(contraints, query, GeoQueryType.WITHIN); - return getIteratorWrapper(queryObj, coll, storageStrategy); - } - - - private CloseableIteration<Statement, QueryEvaluationException> getIteratorWrapper(final DBObject query, final DBCollection coll, final GeoMongoDBStorageStrategy storageStrategy) { - - return new CloseableIteration<Statement, QueryEvaluationException>() { - - private DBCursor cursor = null; - - private DBCursor getIterator() throws QueryEvaluationException { - if (cursor == null){ - cursor = coll.find(query); - } - return cursor; - } - - @Override - public boolean hasNext() throws QueryEvaluationException { - return getIterator().hasNext(); - } - - @Override - public Statement next() throws QueryEvaluationException { - DBObject feature = getIterator().next(); - return storageStrategy.deserializeDBObject(feature); - } - - @Override - public void remove() { - throw new UnsupportedOperationException("Remove not implemented"); - } - - @Override - public void close() throws QueryEvaluationException { - getIterator().close(); - } - }; - } - - @Override - public CloseableIteration<Statement, QueryEvaluationException> queryContains( - Geometry query, StatementContraints contraints) { - throw new UnsupportedOperationException("Contains queries are not supported in Mongo DB."); - } - - @Override - public CloseableIteration<Statement, QueryEvaluationException> queryOverlaps( - Geometry query, StatementContraints contraints) { - throw new UnsupportedOperationException("Overlaps queries are not supported in Mongo DB."); - } - - @Override - public Set<URI> getIndexablePredicates() { - return predicates; - } - - @Override - public void flush() throws IOException { - // TODO Auto-generated method stub - - } - - @Override - public void close() throws IOException { - mongoClient.close(); - } - - -}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/MongoGeoTupleSet.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/MongoGeoTupleSet.java b/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/MongoGeoTupleSet.java deleted file mode 100644 index da49904..0000000 --- a/extras/indexing/src/main/java/mvm/rya/indexing/mongodb/MongoGeoTupleSet.java +++ /dev/null @@ -1,361 +0,0 @@ -package mvm.rya.indexing.mongodb; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -import info.aduna.iteration.CloseableIteration; - -import java.util.Map; -import java.util.Set; - -import mvm.rya.indexing.GeoIndexer; -import mvm.rya.indexing.IndexingExpr; -import mvm.rya.indexing.IteratorFactory; -import mvm.rya.indexing.SearchFunction; -import mvm.rya.indexing.StatementContraints; -import mvm.rya.indexing.accumulo.geo.GeoConstants; -import mvm.rya.indexing.accumulo.geo.GeoTupleSet; -import mvm.rya.indexing.external.tupleSet.ExternalTupleSet; - -import org.apache.hadoop.conf.Configuration; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.query.BindingSet; -import org.openrdf.query.QueryEvaluationException; - -import com.google.common.base.Joiner; -import com.google.common.collect.Maps; -import com.vividsolutions.jts.geom.Geometry; -import com.vividsolutions.jts.io.ParseException; -import com.vividsolutions.jts.io.WKTReader; - -public class MongoGeoTupleSet extends ExternalTupleSet { - - private Configuration conf; - private GeoIndexer geoIndexer; - private IndexingExpr filterInfo; - - - public MongoGeoTupleSet(IndexingExpr filterInfo, GeoIndexer geoIndexer) { - this.filterInfo = filterInfo; - this.geoIndexer = geoIndexer; - this.conf = geoIndexer.getConf(); - } - - @Override - public Set<String> getBindingNames() { - return filterInfo.getBindingNames(); - } - - public GeoTupleSet clone() { - return new GeoTupleSet(filterInfo, geoIndexer); - } - - @Override - public double cardinality() { - return 0.0; // No idea how the estimate cardinality here. - } - - - @Override - public String getSignature() { - return "(GeoTuple Projection) " + "variables: " + Joiner.on(", ").join(this.getBindingNames()).replaceAll("\\s+", " "); - } - - - - @Override - public boolean equals(Object other) { - if (other == this) { - return true; - } - if (!(other instanceof MongoGeoTupleSet)) { - return false; - } - MongoGeoTupleSet arg = (MongoGeoTupleSet) other; - return this.filterInfo.equals(arg.filterInfo); - } - - @Override - public int hashCode() { - int result = 17; - result = 31*result + filterInfo.hashCode(); - - return result; - } - - - - /** - * Returns an iterator over the result set of the contained IndexingExpr. - * <p> - * Should be thread-safe (concurrent invocation {@link OfflineIterable} this - * method can be expected with some query evaluators. - */ - @Override - public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(BindingSet bindings) - throws QueryEvaluationException { - - - URI funcURI = filterInfo.getFunction(); - SearchFunction searchFunction = (new MongoGeoSearchFunctionFactory(conf)).getSearchFunction(funcURI); - if(filterInfo.getArguments().length > 1) { - throw new IllegalArgumentException("Index functions do not support more than two arguments."); - } - - String queryText = filterInfo.getArguments()[0].stringValue(); - - return IteratorFactory.getIterator(filterInfo.getSpConstraint(), bindings, queryText, searchFunction); - } - - - - //returns appropriate search function for a given URI - //search functions used in GeoMesaGeoIndexer to access index - public class MongoGeoSearchFunctionFactory { - - Configuration conf; - - private final Map<URI, SearchFunction> SEARCH_FUNCTION_MAP = Maps.newHashMap(); - - public MongoGeoSearchFunctionFactory(Configuration conf) { - this.conf = conf; - } - - - /** - * Get a {@link GeoSearchFunction} for a given URI. - * - * @param searchFunction - * @return - */ - public SearchFunction getSearchFunction(final URI searchFunction) { - - SearchFunction geoFunc = null; - - try { - geoFunc = getSearchFunctionInternal(searchFunction); - } catch (QueryEvaluationException e) { - e.printStackTrace(); - } - - return geoFunc; - } - - private SearchFunction getSearchFunctionInternal(final URI searchFunction) throws QueryEvaluationException { - SearchFunction sf = SEARCH_FUNCTION_MAP.get(searchFunction); - - if (sf != null) { - return sf; - } else { - throw new QueryEvaluationException("Unknown Search Function: " + searchFunction.stringValue()); - } - } - - private final SearchFunction GEO_EQUALS = new SearchFunction() { - - @Override - public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText, - StatementContraints contraints) throws QueryEvaluationException { - try { - WKTReader reader = new WKTReader(); - Geometry geometry = reader.read(queryText); - CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin( - geometry, contraints); - return statements; - } catch (ParseException e) { - throw new QueryEvaluationException(e); - } - } - - @Override - public String toString() { - return "GEO_EQUALS"; - }; - }; - - private final SearchFunction GEO_DISJOINT = new SearchFunction() { - - @Override - public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText, - StatementContraints contraints) throws QueryEvaluationException { - try { - WKTReader reader = new WKTReader(); - Geometry geometry = reader.read(queryText); - CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin( - geometry, contraints); - return statements; - } catch (ParseException e) { - throw new QueryEvaluationException(e); - } - } - - @Override - public String toString() { - return "GEO_DISJOINT"; - }; - }; - - private final SearchFunction GEO_INTERSECTS = new SearchFunction() { - - @Override - public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText, - StatementContraints contraints) throws QueryEvaluationException { - try { - WKTReader reader = new WKTReader(); - Geometry geometry = reader.read(queryText); - CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin( - geometry, contraints); - return statements; - } catch (ParseException e) { - throw new QueryEvaluationException(e); - } - } - - @Override - public String toString() { - return "GEO_INTERSECTS"; - }; - }; - - private final SearchFunction GEO_TOUCHES = new SearchFunction() { - - @Override - public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText, - StatementContraints contraints) throws QueryEvaluationException { - try { - WKTReader reader = new WKTReader(); - Geometry geometry = reader.read(queryText); - CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin( - geometry, contraints); - return statements; - } catch (ParseException e) { - throw new QueryEvaluationException(e); - } - } - - @Override - public String toString() { - return "GEO_TOUCHES"; - }; - }; - - private final SearchFunction GEO_CONTAINS = new SearchFunction() { - - @Override - public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText, - StatementContraints contraints) throws QueryEvaluationException { - try { - WKTReader reader = new WKTReader(); - Geometry geometry = reader.read(queryText); - CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin( - geometry, contraints); - return statements; - } catch (ParseException e) { - throw new QueryEvaluationException(e); - } - } - - @Override - public String toString() { - return "GEO_CONTAINS"; - }; - }; - - private final SearchFunction GEO_OVERLAPS = new SearchFunction() { - - @Override - public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText, - StatementContraints contraints) throws QueryEvaluationException { - try { - WKTReader reader = new WKTReader(); - Geometry geometry = reader.read(queryText); - CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin( - geometry, contraints); - return statements; - } catch (ParseException e) { - throw new QueryEvaluationException(e); - } - } - - @Override - public String toString() { - return "GEO_OVERLAPS"; - }; - }; - - private final SearchFunction GEO_CROSSES = new SearchFunction() { - - @Override - public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText, - StatementContraints contraints) throws QueryEvaluationException { - try { - WKTReader reader = new WKTReader(); - Geometry geometry = reader.read(queryText); - CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin( - geometry, contraints); - return statements; - } catch (ParseException e) { - throw new QueryEvaluationException(e); - } - } - - @Override - public String toString() { - return "GEO_CROSSES"; - }; - }; - - private final SearchFunction GEO_WITHIN = new SearchFunction() { - - @Override - public CloseableIteration<Statement, QueryEvaluationException> performSearch(String queryText, - StatementContraints contraints) throws QueryEvaluationException { - try { - WKTReader reader = new WKTReader(); - Geometry geometry = reader.read(queryText); - CloseableIteration<Statement, QueryEvaluationException> statements = geoIndexer.queryWithin( - geometry, contraints); - return statements; - } catch (ParseException e) { - throw new QueryEvaluationException(e); - } - } - - @Override - public String toString() { - return "GEO_WITHIN"; - }; - }; - - { - SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_EQUALS, GEO_EQUALS); - SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_DISJOINT, GEO_DISJOINT); - SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_INTERSECTS, GEO_INTERSECTS); - SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_TOUCHES, GEO_TOUCHES); - SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_CONTAINS, GEO_CONTAINS); - SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_OVERLAPS, GEO_OVERLAPS); - SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_CROSSES, GEO_CROSSES); - SEARCH_FUNCTION_MAP.put(GeoConstants.GEO_SF_WITHIN, GEO_WITHIN); - } - - } - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/extras/indexing/src/test/java/ValidIndexCombinationGeneratorTest.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/ValidIndexCombinationGeneratorTest.java b/extras/indexing/src/test/java/ValidIndexCombinationGeneratorTest.java deleted file mode 100644 index 1515118..0000000 --- a/extras/indexing/src/test/java/ValidIndexCombinationGeneratorTest.java +++ /dev/null @@ -1,507 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import junit.framework.Assert; -import mvm.rya.indexing.IndexPlanValidator.IndexedExecutionPlanGenerator; -import mvm.rya.indexing.IndexPlanValidator.ValidIndexCombinationGenerator; -import mvm.rya.indexing.external.tupleSet.ExternalTupleSet; -import mvm.rya.indexing.external.tupleSet.SimpleExternalTupleSet; - -import org.junit.Test; -import org.openrdf.query.MalformedQueryException; -import org.openrdf.query.algebra.Projection; -import org.openrdf.query.algebra.TupleExpr; -import org.openrdf.query.parser.ParsedQuery; -import org.openrdf.query.parser.sparql.SPARQLParser; - -import com.google.common.collect.Lists; - - -public class ValidIndexCombinationGeneratorTest { - - - - - - - @Test - public void singleIndex() { - String q1 = ""// - + "SELECT ?f ?m ?d " // - + "{" // - + " ?f a ?m ."// - + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// - + " ?d <uri:talksTo> ?f . "// - + " ?f <uri:hangOutWith> ?m ." // - + " ?m <uri:hangOutWith> ?d ." // - + " ?f <uri:associatesWith> ?m ." // - + " ?m <uri:associatesWith> ?d ." // - + "}";// - - - - - - - SPARQLParser parser = new SPARQLParser(); - ParsedQuery pq1 = null; - - - SimpleExternalTupleSet extTup1 = null; - - - - - - - try { - pq1 = parser.parseQuery(q1, null); - - - - extTup1 = new SimpleExternalTupleSet((Projection) pq1.getTupleExpr()); - - - } catch (MalformedQueryException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - List<ExternalTupleSet> indexList = Lists.newArrayList(); - indexList.add(extTup1); - - - ValidIndexCombinationGenerator vic = new ValidIndexCombinationGenerator(pq1.getTupleExpr()); - Iterator<List<ExternalTupleSet>> combos = vic.getValidIndexCombos(indexList); - int size = 0; - while(combos.hasNext()) { - combos.hasNext(); - size++; - combos.next(); - combos.hasNext(); - } - - Assert.assertTrue(!combos.hasNext()); - Assert.assertEquals(1,size); - - - } - - - - - - - @Test - public void medQueryEightOverlapIndex() { - String q1 = ""// - + "SELECT ?f ?m ?d " // - + "{" // - + " ?f a ?m ."// - + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// - + " ?d <uri:talksTo> ?f . "// - + " ?f <uri:hangOutWith> ?m ." // - + " ?m <uri:hangOutWith> ?d ." // - + " ?f <uri:associatesWith> ?m ." // - + " ?m <uri:associatesWith> ?d ." // - + "}";// - - - String q2 = ""// - + "SELECT ?t ?s ?u " // - + "{" // - + " ?s a ?t ."// - + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// - + " ?u <uri:talksTo> ?s . "// - + "}";// - - - String q3 = ""// - + "SELECT ?s ?t ?u " // - + "{" // - + " ?s <uri:hangOutWith> ?t ." // - + " ?t <uri:hangOutWith> ?u ." // - + "}";// - - String q4 = ""// - + "SELECT ?s ?t ?u " // - + "{" // - + " ?s <uri:associatesWith> ?t ." // - + " ?t <uri:associatesWith> ?u ." // - + "}";// - - - String q5 = ""// - + "SELECT ?t ?s ?u " // - + "{" // - + " ?s a ?t ."// - + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// - + " ?u <uri:talksTo> ?s . "// - + " ?s <uri:hangOutWith> ?t ." // - + " ?t <uri:hangOutWith> ?u ." // - + "}";// - - String q6 = ""// - + "SELECT ?s ?t ?u " // - + "{" // - + " ?s <uri:associatesWith> ?t ." // - + " ?t <uri:associatesWith> ?u ." // - + " ?s <uri:hangOutWith> ?t ." // - + " ?t <uri:hangOutWith> ?u ." // - + "}";// - - - String q7 = ""// - + "SELECT ?s ?t ?u " // - + "{" // - + " ?s <uri:associatesWith> ?t ." // - + " ?t <uri:associatesWith> ?u ." // - + " ?t <uri:hangOutWith> ?u ." // - + "}";// - - - - String q8 = ""// - + "SELECT ?t ?s ?u " // - + "{" // - + " ?s a ?t ."// - + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// - + " ?u <uri:talksTo> ?s . "// - + " ?s <uri:associatesWith> ?t ." // - + "}";// - - - String q9 = ""// - + "SELECT ?t ?s ?u " // - + "{" // - + " ?s a ?t ."// - + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// - + "}";// - - - - - - - - - - SPARQLParser parser = new SPARQLParser(); - ParsedQuery pq1 = null; - ParsedQuery pq2 = null; - ParsedQuery pq3 = null; - ParsedQuery pq4 = null; - ParsedQuery pq5 = null; - ParsedQuery pq6 = null; - ParsedQuery pq7 = null; - ParsedQuery pq8 = null; - ParsedQuery pq9 = null; - - SimpleExternalTupleSet extTup1 = null; - SimpleExternalTupleSet extTup2 = null; - SimpleExternalTupleSet extTup3 = null; - SimpleExternalTupleSet extTup4 = null; - SimpleExternalTupleSet extTup5 = null; - SimpleExternalTupleSet extTup6 = null; - SimpleExternalTupleSet extTup7 = null; - SimpleExternalTupleSet extTup8 = null; - - - - - - try { - pq1 = parser.parseQuery(q1, null); - pq2 = parser.parseQuery(q2, null); - pq3 = parser.parseQuery(q3, null); - pq4 = parser.parseQuery(q4, null); - pq5 = parser.parseQuery(q5, null); - pq6 = parser.parseQuery(q6, null); - pq7 = parser.parseQuery(q7, null); - pq8 = parser.parseQuery(q8, null); - pq9 = parser.parseQuery(q9, null); - - - extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr()); - extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr()); - extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr()); - extTup4 = new SimpleExternalTupleSet((Projection) pq5.getTupleExpr()); - extTup5 = new SimpleExternalTupleSet((Projection) pq6.getTupleExpr()); - extTup6 = new SimpleExternalTupleSet((Projection) pq7.getTupleExpr()); - extTup7 = new SimpleExternalTupleSet((Projection) pq8.getTupleExpr()); - extTup8 = new SimpleExternalTupleSet((Projection) pq9.getTupleExpr()); - - - } catch (MalformedQueryException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - List<ExternalTupleSet> indexList = Lists.newArrayList(); - indexList.add(extTup1); - indexList.add(extTup2); - indexList.add(extTup3); - indexList.add(extTup4); - indexList.add(extTup5); - indexList.add(extTup6); - indexList.add(extTup7); - indexList.add(extTup8); - - - ValidIndexCombinationGenerator vic = new ValidIndexCombinationGenerator(pq1.getTupleExpr()); - Iterator<List<ExternalTupleSet>> combos = vic.getValidIndexCombos(indexList); - int size = 0; - while(combos.hasNext()) { - combos.hasNext(); - size++; - combos.next(); - combos.hasNext(); - } - - Assert.assertTrue(!combos.hasNext()); - Assert.assertEquals(21,size); - - - } - - - - - - @Test - public void largeQuerySixteenIndexTest() { - - - String q1 = ""// - + "SELECT ?f ?m ?d ?e ?l ?c ?n ?o ?p ?a ?h ?r " // - + "{" // - + " ?f a ?m ."// - + " ?e a ?l ."// - + " ?n a ?o ."// - + " ?a a ?h ."// - + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// - + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."// - + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?p ."// - + " ?h <http://www.w3.org/2000/01/rdf-schema#label> ?r ."// - + " ?d <uri:talksTo> ?f . "// - + " ?c <uri:talksTo> ?e . "// - + " ?p <uri:talksTo> ?n . "// - + " ?r <uri:talksTo> ?a . "// - + "}";// - - - String q2 = ""// - + "SELECT ?s ?t ?u " // - + "{" // - + " ?s a ?t ."// - + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// - + " ?u <uri:talksTo> ?s . "// - + "}";// - - - - String q3 = ""// - + "SELECT ?s ?t ?u ?d ?f ?g " // - + "{" // - + " ?s a ?t ."// - + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// - + " ?u <uri:talksTo> ?s . "// - + " ?d a ?f ."// - + " ?f <http://www.w3.org/2000/01/rdf-schema#label> ?g ."// - + " ?g <uri:talksTo> ?d . "// - + "}";// - - - - - SPARQLParser parser = new SPARQLParser(); - - ParsedQuery pq1 = null; - ParsedQuery pq2 = null; - ParsedQuery pq3 = null; - - - try { - pq1 = parser.parseQuery(q1, null); - pq2 = parser.parseQuery(q2, null); - pq3 = parser.parseQuery(q3, null); - - } catch (Exception e) { - e.printStackTrace(); - } - - SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr()); - SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr()); - - - List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>(); - - list.add(extTup2); - list.add(extTup1); - - - IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list); - List<ExternalTupleSet> indexSet = iep.getNormalizedIndices(); - - - Assert.assertEquals(16, indexSet.size()); - - ValidIndexCombinationGenerator vic = new ValidIndexCombinationGenerator(pq1.getTupleExpr()); - Iterator<List<ExternalTupleSet>> eSet = vic.getValidIndexCombos(Lists.newArrayList(indexSet)); - - int size = 0; - while(eSet.hasNext()) { - size++; - Assert.assertTrue(eSet.hasNext()); - eSet.next(); - } - - - Assert.assertTrue(!eSet.hasNext()); - Assert.assertEquals(75, size); - - } - - - - - - - @Test - public void largeQueryFourtyIndexTest() { - - - String q1 = ""// - + "SELECT ?f ?m ?d ?e ?l ?c ?n ?o ?p ?a ?h ?r " // - + "{" // - + " ?f a ?m ."// - + " ?e a ?l ."// - + " ?n a ?o ."// - + " ?a a ?h ."// - + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// - + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."// - + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?p ."// - + " ?h <http://www.w3.org/2000/01/rdf-schema#label> ?r ."// - + " ?d <uri:talksTo> ?f . "// - + " ?c <uri:talksTo> ?e . "// - + " ?p <uri:talksTo> ?n . "// - + " ?r <uri:talksTo> ?a . "// - + "}";// - - - String q2 = ""// - + "SELECT ?s ?t ?u " // - + "{" // - + " ?s a ?t ."// - + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// - + " ?u <uri:talksTo> ?s . "// - + "}";// - - - - String q3 = ""// - + "SELECT ?s ?t ?u ?d ?f ?g " // - + "{" // - + " ?s a ?t ."// - + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// - + " ?u <uri:talksTo> ?s . "// - + " ?d a ?f ."// - + " ?f <http://www.w3.org/2000/01/rdf-schema#label> ?g ."// - + " ?g <uri:talksTo> ?d . "// - + "}";// - - - - String q4 = ""// - + "SELECT ?s ?t ?u ?d ?f ?g ?a ?b ?c" // - + "{" // - + " ?s a ?t ."// - + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// - + " ?u <uri:talksTo> ?s . "// - + " ?d a ?f ."// - + " ?f <http://www.w3.org/2000/01/rdf-schema#label> ?g ."// - + " ?g <uri:talksTo> ?d . "// - + " ?a a ?b ."// - + " ?b <http://www.w3.org/2000/01/rdf-schema#label> ?c ."// - + " ?c <uri:talksTo> ?a . "// - + "}";// - - - SPARQLParser parser = new SPARQLParser(); - - ParsedQuery pq1 = null; - ParsedQuery pq2 = null; - ParsedQuery pq3 = null; - ParsedQuery pq4 = null; - - - try { - pq1 = parser.parseQuery(q1, null); - pq2 = parser.parseQuery(q2, null); - pq3 = parser.parseQuery(q3, null); - pq4 = parser.parseQuery(q4, null); - - } catch (Exception e) { - e.printStackTrace(); - } - - SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr()); - SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr()); - SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr()); - - List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>(); - - list.add(extTup2); - list.add(extTup1); - list.add(extTup3); - - IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list); - List<ExternalTupleSet> indexSet = iep.getNormalizedIndices(); - Assert.assertEquals(40, indexSet.size()); - - ValidIndexCombinationGenerator vic = new ValidIndexCombinationGenerator(pq1.getTupleExpr()); - Iterator<List<ExternalTupleSet>> eSet = vic.getValidIndexCombos(Lists.newArrayList(indexSet)); - - int size = 0; - while(eSet.hasNext()) { - size++; - Assert.assertTrue(eSet.hasNext()); - eSet.next(); - } - - Assert.assertTrue(!eSet.hasNext()); - Assert.assertEquals(123, size); - } - - - - - - - - - -}
