RYA-144: Mongo Entity Centric Indexer; Closes #135 Added optimizer for indexer as well as tests. The mvm package structure still existed here, so that was cleaned up. Added tests for the new optmizer.
Project: http://git-wip-us.apache.org/repos/asf/incubator-rya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-rya/commit/4ac4e867 Tree: http://git-wip-us.apache.org/repos/asf/incubator-rya/tree/4ac4e867 Diff: http://git-wip-us.apache.org/repos/asf/incubator-rya/diff/4ac4e867 Branch: refs/heads/master Commit: 4ac4e8674e25136c431b632384503f32cbdfbe6f Parents: 07643eb Author: isper3at <smith...@gmail.com> Authored: Wed Nov 2 11:36:51 2016 -0400 Committer: pujav65 <puja...@gmail.com> Committed: Mon Mar 27 12:22:39 2017 -0400 ---------------------------------------------------------------------- .../rya/mongodb/MongoConnectorFactory.java | 18 +- .../rya/indexing/accumulo/ConfigUtils.java | 37 ++- .../entity/EntityExternalSetMatcherFactory.java | 44 +++ .../indexing/entity/EntityIndexOptimizer.java | 125 +++++++ .../indexing/entity/EntityIndexSetProvider.java | 157 +++++++++ .../entity/EntityToSegmentConverter.java | 51 +++ .../rya/indexing/entity/model/Entity.java | 33 +- .../rya/indexing/entity/model/Property.java | 11 +- .../apache/rya/indexing/entity/model/Type.java | 10 +- .../rya/indexing/entity/model/TypedEntity.java | 29 +- .../indexing/entity/query/EntityQueryNode.java | 200 ++++++++++-- .../entity/storage/CloseableIterator.java | 29 -- .../indexing/entity/storage/EntityStorage.java | 25 +- .../indexing/entity/storage/TypeStorage.java | 17 +- .../entity/storage/mongo/ConvertingCursor.java | 7 +- .../entity/storage/mongo/DocumentConverter.java | 11 +- .../storage/mongo/EntityDocumentConverter.java | 14 +- .../storage/mongo/MongoEntityStorage.java | 29 +- .../entity/storage/mongo/MongoTypeStorage.java | 24 +- .../storage/mongo/RyaTypeDocumentConverter.java | 12 +- .../storage/mongo/TypeDocumentConverter.java | 8 +- .../entity/update/BaseEntityIndexer.java | 50 +-- .../indexing/entity/update/EntityIndexer.java | 22 +- .../indexing/entity/update/EntityUpdater.java | 12 +- .../entity/update/mongo/MongoEntityIndexer.java | 48 ++- .../matching/AbstractExternalSetMatcher.java | 32 +- .../AbstractExternalSetMatcherFactory.java | 24 +- .../indexing/external/matching/BasicRater.java | 18 + .../external/matching/ExternalSetConverter.java | 22 +- .../external/matching/ExternalSetProvider.java | 26 +- .../external/matching/MatcherUtilities.java | 20 +- .../external/matching/QueryNodeListRater.java | 24 +- .../external/matching/QuerySegment.java | 6 +- .../external/matching/QuerySegmentFactory.java | 28 +- .../pcj/matching/AccumuloIndexSetProvider.java | 66 ++-- .../matching/PCJExternalSetMatcherFactory.java | 22 +- .../pcj/matching/PCJToSegmentConverter.java | 34 +- .../apache/rya/sail/config/RyaSailFactory.java | 18 +- .../entity/query/EntityQueryNodeTest.java | 144 ++++++-- .../mongo/EntityDocumentConverterTest.java | 6 +- .../storage/mongo/MongoEntityStorageIT.java | 11 +- .../entity/storage/mongo/MongoITBase.java | 19 +- .../storage/mongo/MongoTypeStorageIT.java | 9 +- .../mongo/RyaTypeDocumentConverterTest.java | 6 +- .../mongo/TypeDocumentConverterTest.java | 4 +- .../update/mongo/MongoEntityIndexerIT.java | 45 +-- .../rya/indexing/mongo/MongoEntityIndexIT.java | 326 +++++++++++++++++++ .../indexing/mongo/MongoEntityIndexTest.java | 260 +++++++++++++++ 48 files changed, 1786 insertions(+), 407 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoConnectorFactory.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoConnectorFactory.java b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoConnectorFactory.java index df62a87..50c3a52 100644 --- a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoConnectorFactory.java +++ b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoConnectorFactory.java @@ -6,9 +6,9 @@ * 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 @@ -57,7 +57,11 @@ public class MongoConnectorFactory { public static synchronized MongoClient getMongoClient(final Configuration conf) throws ConfigurationRuntimeException, MongoException { if (mongoClient == null) { - createMongoClientForServer(conf); + if(conf instanceof MongoDBRdfConfiguration && ((MongoDBRdfConfiguration) conf).getMongoClient() != null) { + mongoClient = ((MongoDBRdfConfiguration) conf).getMongoClient(); + } else { + createMongoClientForServer(conf); + } } return mongoClient; } @@ -71,7 +75,7 @@ public class MongoConnectorFactory { } /** - * Create a MongoDB client object and assign it to this class's static mongoClient + * Create a MongoDB client object and assign it to this class's static mongoClient * @param conf configuration containing connection parameters * @throws ConfigurationRuntimeException - Thrown if the configured server, port, user, or others are missing. * @throws MongoException if can't connect despite conf parameters are given @@ -81,7 +85,7 @@ public class MongoConnectorFactory { // Connect to a running Mongo server final String host = requireNonNull(conf.get(MongoDBRdfConfiguration.MONGO_INSTANCE), MSG_INTRO+"host name is required"); final int port = requireNonNullInt(conf.get(MongoDBRdfConfiguration.MONGO_INSTANCE_PORT), MSG_INTRO+"Port number is required."); - ServerAddress server = new ServerAddress(host, port); + final ServerAddress server = new ServerAddress(host, port); // check for authentication credentials if (conf.get(MongoDBRdfConfiguration.MONGO_USER) != null) { final String username = conf.get(MongoDBRdfConfiguration.MONGO_USER); @@ -101,7 +105,7 @@ public class MongoConnectorFactory { /** * Throw exception for un-configured required values. - * + * * @param required String to check * @param message throw configuration exception with this description * @return unaltered required string @@ -123,7 +127,7 @@ public class MongoConnectorFactory { } try { return Integer.parseInt(required); - } catch (NumberFormatException e) { + } catch (final NumberFormatException e) { throw new ConfigurationRuntimeException(message); } } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/ConfigUtils.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/ConfigUtils.java b/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/ConfigUtils.java index 88e9667..7f10629 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/ConfigUtils.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/ConfigUtils.java @@ -43,12 +43,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.mapreduce.JobContext; import org.apache.hadoop.util.ReflectionUtils; import org.apache.log4j.Logger; -import org.openrdf.model.URI; -import org.openrdf.model.impl.URIImpl; - -import com.google.common.base.Optional; -import com.google.common.collect.Lists; - import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.instance.RyaDetails; @@ -59,16 +53,23 @@ import org.apache.rya.indexing.accumulo.freetext.AccumuloFreeTextIndexer; import org.apache.rya.indexing.accumulo.freetext.LuceneTokenizer; import org.apache.rya.indexing.accumulo.freetext.Tokenizer; import org.apache.rya.indexing.accumulo.temporal.AccumuloTemporalIndexer; +import org.apache.rya.indexing.entity.EntityIndexOptimizer; +import org.apache.rya.indexing.entity.update.mongo.MongoEntityIndexer; import org.apache.rya.indexing.external.PrecomputedJoinIndexer; import org.apache.rya.indexing.mongodb.freetext.MongoFreeTextIndexer; import org.apache.rya.indexing.pcj.matching.PCJOptimizer; import org.apache.rya.indexing.statement.metadata.matching.StatementMetadataOptimizer; +import org.openrdf.model.URI; +import org.openrdf.model.impl.URIImpl; + +import com.google.common.base.Optional; +import com.google.common.collect.Lists; /** * A set of configuration utils to read a Hadoop {@link Configuration} object and create Cloudbase/Accumulo objects. - * Soon will deprecate this class. Use installer for the set methods, use {@link RyaDetails} for the get methods. + * Soon will deprecate this class. Use installer for the set methods, use {@link RyaDetails} for the get methods. * New code must separate parameters that are set at Rya install time from that which is specific to the client. - * Also Accumulo index tables are pushed down to the implementation and not configured in conf. + * Also Accumulo index tables are pushed down to the implementation and not configured in conf. */ public class ConfigUtils { private static final Logger logger = Logger.getLogger(ConfigUtils.class); @@ -343,7 +344,7 @@ public class ConfigUtils { public static boolean getUseOptimalPCJ(final Configuration conf) { return conf.getBoolean(USE_OPTIMAL_PCJ, false); } - + public static boolean getUsePcjUpdaterIndex(final Configuration conf) { return conf.getBoolean(USE_PCJ_UPDATER_INDEX, false); } @@ -354,7 +355,7 @@ public class ConfigUtils { * using to incrementally update PCJs. */ //TODO delete this eventually and use Details table - public Optional<String> getFluoAppName(Configuration conf) { + public Optional<String> getFluoAppName(final Configuration conf) { return Optional.fromNullable(conf.get(FLUO_APP_NAME)); } @@ -376,12 +377,17 @@ public class ConfigUtils { indexList.add(MongoFreeTextIndexer.class.getName()); useFilterIndex = true; } + + if (getUseEntity(conf)) { + indexList.add(MongoEntityIndexer.class.getName()); + optimizers.add(EntityIndexOptimizer.class.getName()); + } } else { if (getUsePCJ(conf) || getUseOptimalPCJ(conf)) { conf.setPcjOptimizer(PCJOptimizer.class); } - + if(getUsePcjUpdaterIndex(conf)) { indexList.add(PrecomputedJoinIndexer.class.getName()); } @@ -397,17 +403,16 @@ public class ConfigUtils { useFilterIndex = true; } + if (getUseEntity(conf)) { + indexList.add(EntityCentricIndex.class.getName()); + optimizers.add(EntityOptimizer.class.getName()); + } } if (useFilterIndex) { optimizers.add(FilterFunctionOptimizer.class.getName()); } - if (getUseEntity(conf)) { - indexList.add(EntityCentricIndex.class.getName()); - optimizers.add(EntityOptimizer.class.getName()); - } - if(conf.getUseStatementMetadata()) { optimizers.add(StatementMetadataOptimizer.class.getName()); } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/EntityExternalSetMatcherFactory.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/EntityExternalSetMatcherFactory.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/EntityExternalSetMatcherFactory.java new file mode 100644 index 0000000..12fd471 --- /dev/null +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/EntityExternalSetMatcherFactory.java @@ -0,0 +1,44 @@ +/** + * 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. + */ +package org.apache.rya.indexing.entity; + +import org.apache.rya.indexing.entity.query.EntityQueryNode; +import org.apache.rya.indexing.external.matching.AbstractExternalSetMatcherFactory; +import org.apache.rya.indexing.external.matching.ExternalSetMatcher; +import org.apache.rya.indexing.external.matching.JoinSegment; +import org.apache.rya.indexing.external.matching.JoinSegmentMatcher; +import org.apache.rya.indexing.external.matching.OptionalJoinSegment; +import org.apache.rya.indexing.external.matching.OptionalJoinSegmentMatcher; + +/** + * Factory used to build {@link EntityQueryNodeMatcher}s for the {@link EntityIndexOptimizer}. + * + */ +public class EntityExternalSetMatcherFactory extends AbstractExternalSetMatcherFactory<EntityQueryNode> { + + @Override + protected ExternalSetMatcher<EntityQueryNode> getJoinSegmentMatcher(final JoinSegment<EntityQueryNode> segment) { + return new JoinSegmentMatcher<EntityQueryNode>(segment, new EntityToSegmentConverter()); + } + + @Override + protected ExternalSetMatcher<EntityQueryNode> getOptionalJoinSegmentMatcher(final OptionalJoinSegment<EntityQueryNode> segment) { + return new OptionalJoinSegmentMatcher<EntityQueryNode>(segment, new EntityToSegmentConverter()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/EntityIndexOptimizer.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/EntityIndexOptimizer.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/EntityIndexOptimizer.java new file mode 100644 index 0000000..5a45dc8 --- /dev/null +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/EntityIndexOptimizer.java @@ -0,0 +1,125 @@ +/** + * 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. + */ +package org.apache.rya.indexing.entity; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.apache.hadoop.conf.Configurable; +import org.apache.hadoop.conf.Configuration; +import org.apache.log4j.Logger; +import org.apache.rya.indexing.entity.model.Entity; +import org.apache.rya.indexing.entity.query.EntityQueryNode; +import org.apache.rya.indexing.entity.storage.EntityStorage; +import org.apache.rya.indexing.entity.storage.TypeStorage; +import org.apache.rya.indexing.entity.update.mongo.MongoEntityIndexer; +import org.apache.rya.indexing.external.matching.AbstractExternalSetOptimizer; +import org.apache.rya.indexing.external.matching.ExternalSetMatcher; +import org.apache.rya.indexing.external.matching.ExternalSetProvider; +import org.apache.rya.indexing.external.matching.QueryNodeListRater; +import org.apache.rya.indexing.external.matching.QuerySegment; +import org.apache.rya.indexing.external.matching.TopOfQueryFilterRelocator; +import org.openrdf.query.BindingSet; +import org.openrdf.query.Dataset; +import org.openrdf.query.algebra.TupleExpr; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Optional; + +/** + * Optimizes a query over {@link Entity}s. + */ +public class EntityIndexOptimizer extends AbstractExternalSetOptimizer<EntityQueryNode> implements Configurable { + private static final Logger log = Logger.getLogger(EntityIndexOptimizer.class); + private static final EntityExternalSetMatcherFactory MATCHER_FACTORY = new EntityExternalSetMatcherFactory(); + + private final MongoEntityIndexer indexer; + private EntityIndexSetProvider provider; + private Configuration conf; + + private EntityStorage entityStorage; + private TypeStorage typeStorage; + + /** + * Creates a new {@link EntityIndexOptimizer}. + */ + public EntityIndexOptimizer() { + indexer = new MongoEntityIndexer(); + + //There is no rater for entity query nodes. + useOptimal = false; + } + + @Override + public void setConf(final Configuration conf) { + this.conf = conf; + indexer.setConf(conf); + + typeStorage = indexer.getTypeStorage(conf); + entityStorage = indexer.getEntityStorage(conf); + + provider = new EntityIndexSetProvider(typeStorage, entityStorage); + } + + @Override + public Configuration getConf() { + return conf; + } + + @Override + public void optimize(TupleExpr tupleExpr, final Dataset dataset, final BindingSet bindings) { + checkNotNull(tupleExpr); + checkNotNull(indexer); + + // first standardize query by pulling all filters to top of query if + // they exist using TopOfQueryFilterRelocator + tupleExpr = TopOfQueryFilterRelocator.moveFiltersToTop(tupleExpr); + super.optimize(tupleExpr, null, null); + } + + @VisibleForTesting + public EntityStorage getEntityStorage() { + return entityStorage; + } + + @VisibleForTesting + public TypeStorage getTypeStorage() { + return typeStorage; + } + + /** + * Visits a node of the query tree. Checks to see if the node belongs + * or is of an {@link Entity}. If it is, prepares it, so after the query + * is checked, the nodes can be replaced with {@link EntityQueryNode}s. + */ + + @Override + protected ExternalSetMatcher<EntityQueryNode> getMatcher(final QuerySegment<EntityQueryNode> segment) { + return MATCHER_FACTORY.getMatcher(segment); + } + + @Override + protected ExternalSetProvider<EntityQueryNode> getProvider() { + return provider; + } + + @Override + protected Optional<QueryNodeListRater> getNodeListRater(final QuerySegment<EntityQueryNode> segment) { + return Optional.absent(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/EntityIndexSetProvider.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/EntityIndexSetProvider.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/EntityIndexSetProvider.java new file mode 100644 index 0000000..1052b38 --- /dev/null +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/EntityIndexSetProvider.java @@ -0,0 +1,157 @@ +/** + * 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. + */ +package org.apache.rya.indexing.entity; + +import static java.util.Objects.requireNonNull; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.apache.rya.api.domain.RyaURI; +import org.apache.rya.indexing.entity.model.Entity; +import org.apache.rya.indexing.entity.model.Type; +import org.apache.rya.indexing.entity.query.EntityQueryNode; +import org.apache.rya.indexing.entity.storage.EntityStorage; +import org.apache.rya.indexing.entity.storage.TypeStorage; +import org.apache.rya.indexing.entity.storage.TypeStorage.TypeStorageException; +import org.apache.rya.indexing.external.matching.ExternalSetProvider; +import org.apache.rya.indexing.external.matching.QuerySegment; +import org.openrdf.model.impl.URIImpl; +import org.openrdf.model.vocabulary.RDF; +import org.openrdf.query.algebra.QueryModelNode; +import org.openrdf.query.algebra.StatementPattern; +import org.openrdf.query.algebra.Var; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; + +/** + * Provides {@link EntityQueryNodes}s. + */ +public class EntityIndexSetProvider implements ExternalSetProvider<EntityQueryNode> { + private Multimap<Type, StatementPattern> typeMap; + private Map<String, Type> subjectTypeMap; + private final TypeStorage typeStorage; + private final EntityStorage entityStorage; + + /** + * Creates a new {@link EntityIndexSetProvider}. + * @param typeStorage - The mechanism for access the various {@link Type}s. (not null) + * @param entityStorage - The mechanism for access to the various {@link Entity}s. (not null) + */ + public EntityIndexSetProvider(final TypeStorage typeStorage, final EntityStorage entityStorage) { + this.typeStorage = requireNonNull(typeStorage); + this.entityStorage = requireNonNull(entityStorage); + } + + private Var getTypeSubject(final Type type) { + //we just need the first pattern since all the patterns in this type map are the same subject + final StatementPattern pattern = typeMap.get(type).iterator().next(); + return pattern.getSubjectVar(); + } + + private RyaURI getPredURI(final StatementPattern pattern) { + final Var pred = pattern.getPredicateVar(); + return new RyaURI(pred.getValue().stringValue()); + } + + @Override + public List<EntityQueryNode> getExternalSets(final QuerySegment<EntityQueryNode> node) { + typeMap = HashMultimap.create(); + subjectTypeMap = new HashMap<>(); + + //discover entities + final List<StatementPattern> unused = new ArrayList<>(); + for (final QueryModelNode pattern : node.getOrderedNodes()) { + if(pattern instanceof StatementPattern) { + discoverEntities((StatementPattern) pattern, unused); + } + } + + final List<EntityQueryNode> nodes = new ArrayList<>(); + for(final Type type : typeMap.keySet()) { + //replace all nodes in the tupleExpr of the collection of statement patterns with this node. + final EntityQueryNode entity = new EntityQueryNode(type, typeMap.get(type), entityStorage); + nodes.add(entity); + } + return nodes; + } + + private void discoverEntities(final StatementPattern pattern, final List<StatementPattern> unmatched) { + final Var subj = pattern.getSubjectVar(); + final String subjStr = subj.getName(); + final RyaURI predURI = getPredURI(pattern); + //check to see if current node is type + if(new URIImpl(predURI.getData()).equals(RDF.TYPE)) { + final Var obj = pattern.getObjectVar(); + final RyaURI objURI = new RyaURI(obj.getValue().stringValue()); + try { + final Optional<Type> optType = typeStorage.get(objURI); + //if is type, fetch type add to subject -> type map + if(optType.isPresent()) { + final Type type = optType.get(); + typeMap.put(type, pattern); + subjectTypeMap.put(subjStr, type); + //check unmatched properties, add matches + for(final StatementPattern propertyPattern : unmatched) { + //store sps into the type -> property map + final RyaURI property = getPredURI(propertyPattern); + final Var typeSubVar = getTypeSubject(type); + final Var patternSubVar = propertyPattern.getSubjectVar(); + if (type.getPropertyNames().contains(property) && typeSubVar.equals(patternSubVar)) { + typeMap.put(type, propertyPattern); + } + } + } + } catch (final TypeStorageException e) { + e.printStackTrace(); + } + } else { + //if not type, check to see if subject is in type map + if(subjectTypeMap.containsKey(subjStr)) { + //if is, check to see if pred is a property of type + final Type type = subjectTypeMap.get(subjStr); + if(type.getPropertyNames().contains(predURI)) { + //if is, add sp to type -> sp map + if(!typeMap.containsKey(type)) { + //each variable can only contain 1 type for now @see:Rya-235? + typeMap.put(type, pattern); + } + } else { + //if not, add to unmatched type + unmatched.add(pattern); + } + } else { + //if not, add to unmatched + unmatched.add(pattern); + } + } + } + + @Override + public Iterator<List<EntityQueryNode>> getExternalSetCombos(final QuerySegment<EntityQueryNode> segment) { + final List<List<EntityQueryNode>> comboList = new ArrayList<>(); + comboList.add(getExternalSets(segment)); + return comboList.iterator(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/EntityToSegmentConverter.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/EntityToSegmentConverter.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/EntityToSegmentConverter.java new file mode 100644 index 0000000..c76a3ab --- /dev/null +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/EntityToSegmentConverter.java @@ -0,0 +1,51 @@ +/** + * 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. + */ +package org.apache.rya.indexing.entity; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.rya.indexing.entity.query.EntityQueryNode; +import org.apache.rya.indexing.external.matching.ExternalSetConverter; +import org.apache.rya.indexing.external.matching.JoinSegment; +import org.apache.rya.indexing.external.matching.QuerySegment; +import org.openrdf.query.algebra.Filter; +import org.openrdf.query.algebra.QueryModelNode; +import org.openrdf.query.algebra.ValueExpr; + +import com.google.common.base.Preconditions; + +/** + * Implementation of {@link ExternalSetConverter} to convert {@link EntityQueryNode}s + * to {@link QuerySegment}s. + * + */ +public class EntityToSegmentConverter implements ExternalSetConverter<EntityQueryNode> { + + @Override + public QuerySegment<EntityQueryNode> setToSegment(final EntityQueryNode set) { + Preconditions.checkNotNull(set); + final Set<QueryModelNode> matched = new HashSet<>(set.getPatterns()); + final List<QueryModelNode> unmatched = new ArrayList<>(set.getPatterns()); + return new JoinSegment<EntityQueryNode>(matched, unmatched, new HashMap<ValueExpr, Filter>()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Entity.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Entity.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Entity.java index c37eed3..3eb4c39 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Entity.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Entity.java @@ -18,6 +18,8 @@ */ package org.apache.rya.indexing.entity.model; +import static java.util.Objects.requireNonNull; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -26,6 +28,7 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.Optional; +import org.apache.http.annotation.Immutable; import org.apache.rya.api.domain.RyaURI; import org.apache.rya.indexing.entity.storage.EntityStorage; @@ -33,6 +36,10 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; + /** * An {@link Entity} is a named concept that has at least one defined structure * and a bunch of values that fit within each of those structures. A structure is @@ -64,7 +71,7 @@ import com.google.common.collect.Maps; * Once something has done so, it is an explicitly typed Entity. */ @Immutable - +@DefaultAnnotation(NonNull.class) public class Entity { private final RyaURI subject; @@ -84,11 +91,11 @@ public class Entity { final RyaURI subject, final ImmutableList<RyaURI> explicitTypeIds, final ImmutableMap<RyaURI, ImmutableMap<RyaURI, Property>> typeProperties, - int version) { - subject = requireNonNull(subject); - explicitTypeIds = requireNonNull(explicitTypeIds); + final int version) { + this.subject = requireNonNull(subject); + this.explicitTypeIds = requireNonNull(explicitTypeIds); properties = requireNonNull(typeProperties); - version = version; + this.version = version; } /** @@ -126,7 +133,7 @@ public class Entity { } @Override - public boolean equals(Object o) { + public boolean equals(final Object o) { if(this == o) { return true; } @@ -147,7 +154,7 @@ public class Entity { * @return A TypedEntity using this object's values if any properties for the Type * are present or if the Type was explicitly set. Otherwise an empty {@link Optional}. */ - public Optional<TypedEntity> makeTypedEntity(RyaURI typeId) { + public Optional<TypedEntity> makeTypedEntity(final RyaURI typeId) { requireNonNull(typeId); final boolean explicitlyHasType = explicitTypeIds.contains(typeId); @@ -186,14 +193,14 @@ public class Entity { * @param entity - The Entity the builder will be based on. (not null) * @return A {@link Builder} loaded with {@code entity}'s values. */ - public static Builder builder(Entity entity) { + public static Builder builder(final Entity entity) { return new Builder(entity); } /** * Builds instances of {@link Entity}. */ - @ParametersAreNonnullByDefault + @DefaultAnnotation(NonNull.class) public static class Builder { private RyaURI subject = null; @@ -212,7 +219,7 @@ public class Entity { * * @param entity - The Entity the builder will be based on. (not null) */ - public Builder(Entity entity) { + public Builder(final Entity entity) { requireNonNull(entity); subject = entity.getSubject(); @@ -230,7 +237,7 @@ public class Entity { * @return This {@link Builder} so that method invocations may be chained. */ public Builder setSubject(@Nullable final RyaURI subject) { - subject = subject; + this.subject = subject; return this; } @@ -300,8 +307,8 @@ public class Entity { * {@link EntityStorage} to prevent stale updates. * @return This {@link Builder} so that method invocations may be chained. */ - public Builder setVersion(int version) { - version = version; + public Builder setVersion(final int version) { + this.version = version; return this; } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Property.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Property.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Property.java index 4388024..53b141e 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Property.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Property.java @@ -22,17 +22,18 @@ import static java.util.Objects.requireNonNull; import java.util.Objects; -import javax.annotation.ParametersAreNonnullByDefault; -import javax.annotation.concurrent.Immutable; +import org.apache.http.annotation.Immutable; +import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaURI; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; /** * A value that has been set for an {@link TypedEntity}. */ @Immutable -@ParametersAreNonnullByDefault +@DefaultAnnotation(NonNull.class) public class Property { private final RyaURI name; http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Type.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Type.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Type.java index 7d8e0ee..f539e7c 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Type.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/Type.java @@ -22,14 +22,14 @@ import static java.util.Objects.requireNonNull; import java.util.Objects; -import javax.annotation.ParametersAreNonnullByDefault; -import javax.annotation.concurrent.Immutable; - +import org.apache.http.annotation.Immutable; +import org.apache.rya.api.domain.RyaURI; import org.apache.rya.indexing.entity.storage.TypeStorage; import com.google.common.collect.ImmutableSet; -import mvm.rya.api.domain.RyaURI; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; /** * Defines the structure of an {@link TypedEntity}. @@ -45,7 +45,7 @@ import mvm.rya.api.domain.RyaURI; * </pre> */ @Immutable -@ParametersAreNonnullByDefault +@DefaultAnnotation(NonNull.class) public class Type { /** http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/TypedEntity.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/TypedEntity.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/TypedEntity.java index a49c8d2..0d019c2 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/TypedEntity.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/model/TypedEntity.java @@ -23,24 +23,25 @@ import static java.util.Objects.requireNonNull; import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.Optional; -import javax.annotation.Nullable; -import javax.annotation.ParametersAreNonnullByDefault; -import javax.annotation.concurrent.Immutable; +import org.apache.http.annotation.Immutable; +import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaURI; -import com.google.common.base.Optional; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableMap; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; /** * A {@link TypedEntity} is a view of an {@link Entity} that has had a specific * {@link Type} applied to it. */ @Immutable -@ParametersAreNonnullByDefault +@DefaultAnnotation(NonNull.class) public class TypedEntity { /** @@ -79,10 +80,10 @@ public class TypedEntity { */ private TypedEntity(final RyaURI subject, final RyaURI dataTypeId, - boolean explicitlyTyped, + final boolean explicitlyTyped, final ImmutableMap<RyaURI, Property> optionalFields) { this.subject = requireNonNull(subject); - this.typeId = requireNonNull(dataTypeId); + typeId = requireNonNull(dataTypeId); this.optionalFields = requireNonNull(optionalFields); this.explicitlyTyped = explicitlyTyped; } @@ -129,7 +130,7 @@ public class TypedEntity { final Property field = optionalFields.get(propertyName); return field == null ? - Optional.absent() : + Optional.empty() : Optional.of( field.getValue() ); } @@ -139,7 +140,7 @@ public class TypedEntity { } @Override - public boolean equals(Object o) { + public boolean equals(final Object o) { if(this == o) { return true; } @@ -165,7 +166,7 @@ public class TypedEntity { * @param entity - The initial values of the builder. (not null) * @return An instance of {@link Builder} loaded with {@code entity}'s values. */ - public static Builder builder(TypedEntity entity) { + public static Builder builder(final TypedEntity entity) { requireNonNull(entity); final Builder builder = builder() @@ -180,7 +181,7 @@ public class TypedEntity { /** * Builds instances of {@link TypedEntity}. */ - @ParametersAreNonnullByDefault + @DefaultAnnotation(NonNull.class) public static class Builder { private RyaURI subject; @@ -212,7 +213,7 @@ public class TypedEntity { * only exists because it has properties that happen to match that type's properties). * @return This {@link Builder} so that method invocations may be chained. */ - public Builder setExplicitelyTyped(boolean explicitlyTyped) { + public Builder setExplicitelyTyped(final boolean explicitlyTyped) { this.explicitlyTyped = explicitlyTyped; return this; } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/query/EntityQueryNode.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/query/EntityQueryNode.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/query/EntityQueryNode.java index bb14922..1174b21 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/query/EntityQueryNode.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/query/EntityQueryNode.java @@ -20,31 +20,53 @@ package org.apache.rya.indexing.entity.query; import static java.util.Objects.requireNonNull; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.Iterator; +import java.util.List; +import java.util.Objects; import java.util.Optional; - -import javax.annotation.ParametersAreNonnullByDefault; - +import java.util.Set; +import java.util.function.Consumer; + +import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaURI; +import org.apache.rya.api.resolver.RdfToRyaConversions; +import org.apache.rya.indexing.entity.model.Entity; +import org.apache.rya.indexing.entity.model.Property; import org.apache.rya.indexing.entity.model.Type; +import org.apache.rya.indexing.entity.model.TypedEntity; import org.apache.rya.indexing.entity.storage.EntityStorage; +import org.apache.rya.indexing.entity.storage.EntityStorage.EntityStorageException; +import org.apache.rya.indexing.entity.storage.mongo.ConvertingCursor; +import org.apache.rya.indexing.entity.update.EntityIndexer; +import org.apache.rya.rdftriplestore.evaluation.ExternalBatchingIterator; +import org.openrdf.model.impl.ValueFactoryImpl; import org.openrdf.model.vocabulary.RDF; +import org.openrdf.query.Binding; import org.openrdf.query.BindingSet; import org.openrdf.query.QueryEvaluationException; import org.openrdf.query.algebra.StatementPattern; import org.openrdf.query.algebra.Var; import org.openrdf.query.algebra.evaluation.impl.ExternalSet; +import org.openrdf.query.algebra.evaluation.iterator.CollectionIteration; +import org.openrdf.query.impl.MapBindingSet; +import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; import info.aduna.iteration.CloseableIteration; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.rdftriplestore.evaluation.ExternalBatchingIterator; +import jline.internal.Log; /** - * TODO impl, test, doc + * Indexing Node for {@link Entity} expressions to be inserted into execution plan + * to delegate entity portion of query to {@link EntityIndexer}. */ -@ParametersAreNonnullByDefault +@DefaultAnnotation(NonNull.class) public class EntityQueryNode extends ExternalSet implements ExternalBatchingIterator { /** @@ -62,11 +84,14 @@ public class EntityQueryNode extends ExternalSet implements ExternalBatchingIter private final Optional<String> subjectConstant; private final Optional<String> subjectVar; + //since and EntityQueryNode exists in a single segment, all binding names are garunteed to be assured. + private final Set<String> bindingNames; + // Information about the objects of the patterns. + private final ImmutableMap<RyaURI, Var> objectVariables; - // XXX what does this map? property name -> binding variable? - // for any property of the entity that has a variable, have to fill it in? - private final ImmutableMap<RyaURI, String> objectVariables; + // Properties of the Type found in the query + private final Set<Property> properties; /** @@ -83,6 +108,8 @@ public class EntityQueryNode extends ExternalSet implements ExternalBatchingIter this.patterns = requireNonNull(patterns); this.entities = requireNonNull(entities); + bindingNames = new HashSet<>(); + properties = new HashSet<>(); // Subject based preconditions. verifySameSubjects(patterns); @@ -102,11 +129,30 @@ public class EntityQueryNode extends ExternalSet implements ExternalBatchingIter subjectVar = Optional.of( subject.getName() ); } - // TODO Also, map each variable that is in an Object spot each variable can be mapped to a property name as well - // Processing note: // Any constant that appears in the Object portion of the SP will be used to make sure they match. + final Builder<RyaURI, Var> builder = ImmutableMap.<RyaURI, Var>builder(); + for(final StatementPattern sp : patterns) { + final Var object = sp.getObjectVar(); + final Var pred = sp.getPredicateVar(); + final RyaURI predURI = new RyaURI(pred.getValue().stringValue()); + bindingNames.addAll(sp.getBindingNames()); + if(object.isConstant() && !pred.getValue().equals(RDF.TYPE)) { + final RyaType propertyType = RdfToRyaConversions.convertValue(object.getValue()); + properties.add(new Property(predURI, propertyType)); + } + builder.put(predURI, object); + } + objectVariables = builder.build(); + } - objectVariables = null; + @Override + public Set<String> getBindingNames() { + return bindingNames; + } + + @Override + public Set<String> getAssuredBindingNames() { + return bindingNames; } /** @@ -115,7 +161,7 @@ public class EntityQueryNode extends ExternalSet implements ExternalBatchingIter * @param patterns - The patterns to check. * @throws IllegalStateException If all of the Subjects are not the same. */ - private static void verifySameSubjects(Collection<StatementPattern> patterns) throws IllegalStateException { + private static void verifySameSubjects(final Collection<StatementPattern> patterns) throws IllegalStateException { requireNonNull(patterns); final Iterator<StatementPattern> it = patterns.iterator(); @@ -136,7 +182,7 @@ public class EntityQueryNode extends ExternalSet implements ExternalBatchingIter * @param patterns - The patterns to check. (not null) * @throws IllegalStateException A pattern has a variable predicate. */ - private static void verifyAllPredicatesAreConstants(Collection<StatementPattern> patterns) throws IllegalStateException { + private static void verifyAllPredicatesAreConstants(final Collection<StatementPattern> patterns) throws IllegalStateException { requireNonNull(patterns); for(final StatementPattern pattern : patterns) { @@ -153,7 +199,7 @@ public class EntityQueryNode extends ExternalSet implements ExternalBatchingIter * @param patterns - The patterns to check. (not null) * @throws IllegalStateException No Type or the wrong Type is specified by the patterns. */ - private static void verifyHasCorrectTypePattern(Type type, Collection<StatementPattern> patterns) throws IllegalStateException { + private static void verifyHasCorrectTypePattern(final Type type, final Collection<StatementPattern> patterns) throws IllegalStateException { requireNonNull(type); requireNonNull(patterns); @@ -186,7 +232,7 @@ public class EntityQueryNode extends ExternalSet implements ExternalBatchingIter * @throws IllegalStateException If any of the non-type defining Statement Patterns * contain a predicate that does not match one of the Type's property names. */ - private static void verifyAllPredicatesPartOfType(Type type, Collection<StatementPattern> patterns) throws IllegalStateException { + private static void verifyAllPredicatesPartOfType(final Type type, final Collection<StatementPattern> patterns) throws IllegalStateException { requireNonNull(type); requireNonNull(patterns); @@ -204,35 +250,117 @@ public class EntityQueryNode extends ExternalSet implements ExternalBatchingIter } } - - - - - @Override - public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(Collection<BindingSet> bindingSets) throws QueryEvaluationException { - // TODO Auto-generated method stub - return null; + public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final Collection<BindingSet> bindingSets) throws QueryEvaluationException { + requireNonNull(bindingSets); + final List<BindingSet> list = new ArrayList<>(); + bindingSets.forEach(bindingSet -> { + try { + list.addAll(findBindings(bindingSet)); + } catch (final Exception e) { + Log.error("Unable to evaluate bindingset.", e); + } + }); + + return new CollectionIteration<>(list); } @Override - public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(BindingSet bindingSet) throws QueryEvaluationException { + public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final BindingSet bindingSet) throws QueryEvaluationException { requireNonNull(bindingSet); + return new CollectionIteration<>(findBindings(bindingSet)); + } - // ... ok, so if the subject needs to be filled in, then we need to see if the subject variable is in the binding set. - // if it is, fetch that value and then fetch the entity for the subject. - - // if it isn't, fetch the entity for the constant? + private List<BindingSet> findBindings(final BindingSet bindingSet) throws QueryEvaluationException { + final MapBindingSet resultSet = new MapBindingSet(); + try { + final ConvertingCursor<TypedEntity> entitiesCursor; + final String subj; + // If the subject needs to be filled in, check if the subject variable is in the binding set. + if(subjectIsConstant) { + // if it is, fetch that value and then fetch the entity for the subject. + subj = subjectConstant.get(); + entitiesCursor = entities.search(Optional.of(new RyaURI(subj)), type, properties); + } else { + entitiesCursor = entities.search(Optional.empty(), type, properties); + } + while(entitiesCursor.hasNext()) { + final TypedEntity typedEntity = entitiesCursor.next(); + final ImmutableCollection<Property> properties = typedEntity.getProperties(); + //ensure properties match and only add properties that are in the statement patterns to the binding set + for(final RyaURI key : objectVariables.keySet()) { + final Optional<RyaType> prop = typedEntity.getPropertyValue(new RyaURI(key.getData())); + if(prop.isPresent()) { + final RyaType type = prop.get(); + final String bindingName = objectVariables.get(key).getName(); + resultSet.addBinding(bindingName, ValueFactoryImpl.getInstance().createLiteral(type.getData())); + } + } + } + } catch (final EntityStorageException e) { + throw new QueryEvaluationException("Failed to evaluate the binding set", e); + } + bindingSet.forEach(new Consumer<Binding>() { + @Override + public void accept(final Binding binding) { + resultSet.addBinding(binding); + } + }); + final List<BindingSet> list = new ArrayList<>(); + list.add(resultSet); + return list; + } - // RETURN AN EMPTY ITERATION IF IT CAN NOT FILL IT IN! + /** + * @return - The {@link StatementPattern}s that make up this {@link EntityQueryNode} + */ + public Collection<StatementPattern> getPatterns() { + return patterns; + } - // for all variables in the OBJECT portion of the SPs, fill 'em in using the entity that is stored in the index. + @Override + public int hashCode() { + return Objects.hash(subjectIsConstant, + type, + subjectVar, + subjectConstant, + getPatterns()); + } - // x = alice's SSN - // y = blue <-- how do i know this is for urn:eye property? FROM THE STATEMENT PATTERN. look for the ?y in the SP, and that has the property name in it. + @Override + public boolean equals(final Object other) { + if(other instanceof EntityQueryNode) { + final EntityQueryNode otherNode = (EntityQueryNode)other; + + final boolean samePatterns = getPatterns().size() == otherNode.getPatterns().size(); + boolean match = true; + if(samePatterns) { + for(final StatementPattern sp : getPatterns()) { + if(!otherNode.getPatterns().contains(sp)) { + match = false; + break; + } + } + } + return Objects.equals(subjectIsConstant, otherNode.subjectIsConstant) && + Objects.equals(subjectVar, otherNode.subjectVar) && + Objects.equals(type, otherNode.type) && + Objects.equals(subjectConstant, otherNode.subjectConstant) + && samePatterns && match; + } + return false; + } - // TODO Auto-generated method stub - return null; + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("Type: " + type.toString()); + sb.append("Statement Patterns:"); + sb.append("-------------------"); + for(final StatementPattern sp : getPatterns()) { + sb.append(sp.toString()); + } + return sb.toString(); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/CloseableIterator.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/CloseableIterator.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/CloseableIterator.java deleted file mode 100644 index 3b2e10f..0000000 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/CloseableIterator.java +++ /dev/null @@ -1,29 +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. - */ -package org.apache.rya.indexing.entity.storage; - -import java.io.Closeable; -import java.util.Iterator; - -/** - * An {@link Iterator} that is also {@link Closeable}. - * - * @param <T> - The type of object that will be iterated over. - */ -public interface CloseableIterator<T> extends Iterator<T>, Closeable { } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/EntityStorage.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/EntityStorage.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/EntityStorage.java index 44db8e2..34dbf15 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/EntityStorage.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/EntityStorage.java @@ -21,20 +21,22 @@ package org.apache.rya.indexing.entity.storage; import java.util.Optional; import java.util.Set; -import javax.annotation.ParametersAreNonnullByDefault; - +import org.apache.rya.api.domain.RyaURI; import org.apache.rya.indexing.entity.EntityIndexException; import org.apache.rya.indexing.entity.model.Entity; import org.apache.rya.indexing.entity.model.Property; import org.apache.rya.indexing.entity.model.Type; import org.apache.rya.indexing.entity.model.TypedEntity; +import org.apache.rya.indexing.entity.storage.mongo.ConvertingCursor; +import org.calrissian.mango.collect.CloseableIterator; -import mvm.rya.api.domain.RyaURI; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; /** * Stores and provides access to {@link Entity}s. */ -@ParametersAreNonnullByDefault +@DefaultAnnotation(NonNull.class) public interface EntityStorage { /** @@ -69,12 +71,13 @@ public interface EntityStorage { * Search the stored {@link Entity}s that have a specific {@link Type} as * well as the provided {@link Property} values. * + * @param subject - The {@link RyaURI} subject of the Entity. (Optional) * @param type - The {@link Type} of the Entities. (not null) * @param properties - The {@link Property} values that must be set on the Entity. (not null) * @return A {@link CloseableIterator} over the {@link TypedEntity}s that match the search parameters. * @throws EntityStorageException A problem occurred while searching the storage. */ - public CloseableIterator<TypedEntity> search(Type type, Set<Property> properties) throws EntityStorageException; + public ConvertingCursor<TypedEntity> search(final Optional<RyaURI> subject, Type type, Set<Property> properties) throws EntityStorageException; /** * Deletes an {@link Entity} from the storage. @@ -99,7 +102,7 @@ public interface EntityStorage { * @param message the detail message. The detail message is saved for * later retrieval by the {@link #getMessage()} method. */ - public EntityStorageException(String message) { + public EntityStorageException(final String message) { super(message); } @@ -116,7 +119,7 @@ public interface EntityStorage { * permitted, and indicates that the cause is nonexistent or * unknown.) */ - public EntityStorageException(String message, Throwable cause) { + public EntityStorageException(final String message, final Throwable cause) { super(message, cause); } } @@ -127,11 +130,11 @@ public interface EntityStorage { public static class EntityAlreadyExistsException extends EntityStorageException { private static final long serialVersionUID = 1L; - public EntityAlreadyExistsException(String message) { + public EntityAlreadyExistsException(final String message) { super(message); } - public EntityAlreadyExistsException(String message, Throwable cause) { + public EntityAlreadyExistsException(final String message, final Throwable cause) { super(message, cause); } } @@ -143,11 +146,11 @@ public interface EntityStorage { public static class StaleUpdateException extends EntityStorageException { private static final long serialVersionUID = 1L; - public StaleUpdateException(String message) { + public StaleUpdateException(final String message) { super(message); } - public StaleUpdateException(String message, Throwable cause) { + public StaleUpdateException(final String message, final Throwable cause) { super(message, cause); } } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/TypeStorage.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/TypeStorage.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/TypeStorage.java index 2d4622f..31b1790 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/TypeStorage.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/TypeStorage.java @@ -18,19 +18,20 @@ */ package org.apache.rya.indexing.entity.storage; -import javax.annotation.ParametersAreNonnullByDefault; +import java.util.Optional; +import org.apache.rya.api.domain.RyaURI; import org.apache.rya.indexing.entity.EntityIndexException; import org.apache.rya.indexing.entity.model.Type; +import org.apache.rya.indexing.entity.storage.mongo.ConvertingCursor; -import com.google.common.base.Optional; - -import mvm.rya.api.domain.RyaURI; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; /** * Stores and provides access to {@link Type}s. */ -@ParametersAreNonnullByDefault +@DefaultAnnotation(NonNull.class) public interface TypeStorage { /** @@ -58,7 +59,7 @@ public interface TypeStorage { * @throws TypeStorageException A problem occurred while searching for the Types * that have the Property name. */ - public CloseableIterator<Type> search(RyaURI propertyName) throws TypeStorageException; + public ConvertingCursor<Type> search(RyaURI propertyName) throws TypeStorageException; /** * Deletes a {@link Type} from the storage. @@ -83,7 +84,7 @@ public interface TypeStorage { * @param message the detail message. The detail message is saved for * later retrieval by the {@link #getMessage()} method. */ - public TypeStorageException(String message) { + public TypeStorageException(final String message) { super(message); } @@ -100,7 +101,7 @@ public interface TypeStorage { * permitted, and indicates that the cause is nonexistent or * unknown.) */ - public TypeStorageException(String message, Throwable cause) { + public TypeStorageException(final String message, final Throwable cause) { super(message, cause); } } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/ConvertingCursor.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/ConvertingCursor.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/ConvertingCursor.java index 31a9308..df5c3a4 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/ConvertingCursor.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/ConvertingCursor.java @@ -20,10 +20,11 @@ package org.apache.rya.indexing.entity.storage.mongo; import static java.util.Objects.requireNonNull; +import java.io.Closeable; import java.io.IOException; +import java.util.Iterator; import java.util.function.Function; -import org.apache.rya.indexing.entity.storage.CloseableIterator; import org.bson.Document; import com.mongodb.client.MongoCursor; @@ -34,7 +35,7 @@ import com.mongodb.client.MongoCursor; * * @param <T> - The type of object the Documents are converted into. */ -public class ConvertingCursor<T> implements CloseableIterator<T> { +public class ConvertingCursor<T> implements Iterator<T>, Closeable { private final Converter<T> converter; private final MongoCursor<Document> cursor; @@ -45,7 +46,7 @@ public class ConvertingCursor<T> implements CloseableIterator<T> { * @param converter - Converts the {@link Document}s returned by {@code cursor}. (not null) * @param cursor - Retrieves the {@link Document}s from a Mongo DB instance. (not null) */ - public ConvertingCursor(Converter<T> converter, MongoCursor<Document> cursor) { + public ConvertingCursor(final Converter<T> converter, final MongoCursor<Document> cursor) { this.converter = requireNonNull(converter); this.cursor = requireNonNull(cursor); } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/DocumentConverter.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/DocumentConverter.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/DocumentConverter.java index da3e8b6..63d437d 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/DocumentConverter.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/DocumentConverter.java @@ -18,16 +18,17 @@ */ package org.apache.rya.indexing.entity.storage.mongo; -import javax.annotation.ParametersAreNonnullByDefault; - import org.bson.Document; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + /** * Converts an object to/from a {@link Document}. * * @param <T> - The type of object that is converted to/from a {@link Document}. */ -@ParametersAreNonnullByDefault +@DefaultAnnotation(NonNull.class) public interface DocumentConverter<T> { /** @@ -54,11 +55,11 @@ public interface DocumentConverter<T> { public static class DocumentConverterException extends Exception { private static final long serialVersionUID = 1L; - public DocumentConverterException(String message) { + public DocumentConverterException(final String message) { super(message); } - public DocumentConverterException(String message, Throwable cause) { + public DocumentConverterException(final String message, final Throwable cause) { super(message, cause); } } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/EntityDocumentConverter.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/EntityDocumentConverter.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/EntityDocumentConverter.java index 6a2fb74..a46fd5a 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/EntityDocumentConverter.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/EntityDocumentConverter.java @@ -23,19 +23,19 @@ import static java.util.Objects.requireNonNull; import java.util.List; import java.util.stream.Collectors; -import javax.annotation.ParametersAreNonnullByDefault; - +import org.apache.rya.api.domain.RyaType; +import org.apache.rya.api.domain.RyaURI; import org.apache.rya.indexing.entity.model.Entity; import org.apache.rya.indexing.entity.model.Property; import org.bson.Document; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; /** * Converts between {@link Entity} and {@link Document}. */ -@ParametersAreNonnullByDefault +@DefaultAnnotation(NonNull.class) public class EntityDocumentConverter implements DocumentConverter<Entity> { public static final String SUBJECT = "_id"; @@ -46,7 +46,7 @@ public class EntityDocumentConverter implements DocumentConverter<Entity> { private final RyaTypeDocumentConverter ryaTypeConverter = new RyaTypeDocumentConverter(); @Override - public Document toDocument(Entity entity) { + public Document toDocument(final Entity entity) { requireNonNull(entity); final Document doc = new Document(); @@ -75,7 +75,7 @@ public class EntityDocumentConverter implements DocumentConverter<Entity> { } @Override - public Entity fromDocument(Document document) throws DocumentConverterException { + public Entity fromDocument(final Document document) throws DocumentConverterException { requireNonNull(document); // Preconditions. http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/MongoEntityStorage.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/MongoEntityStorage.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/MongoEntityStorage.java index 8a5f6da..3fc817b 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/MongoEntityStorage.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/MongoEntityStorage.java @@ -26,13 +26,11 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import javax.annotation.ParametersAreNonnullByDefault; - +import org.apache.rya.api.domain.RyaURI; import org.apache.rya.indexing.entity.model.Entity; import org.apache.rya.indexing.entity.model.Property; import org.apache.rya.indexing.entity.model.Type; import org.apache.rya.indexing.entity.model.TypedEntity; -import org.apache.rya.indexing.entity.storage.CloseableIterator; import org.apache.rya.indexing.entity.storage.EntityStorage; import org.apache.rya.indexing.entity.storage.mongo.ConvertingCursor.Converter; import org.apache.rya.indexing.entity.storage.mongo.DocumentConverter.DocumentConverterException; @@ -47,12 +45,13 @@ import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoCursor; import com.mongodb.client.model.Filters; -import mvm.rya.api.domain.RyaURI; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; /** * A Mongo DB implementation of {@link EntityStorage}. */ -@ParametersAreNonnullByDefault +@DefaultAnnotation(NonNull.class) public class MongoEntityStorage implements EntityStorage { private static final String COLLECTION_NAME = "entity-entities"; @@ -75,13 +74,13 @@ public class MongoEntityStorage implements EntityStorage { * @param mongo - A client connected to the Mongo instance that hosts the Rya instance. (not null) * @param ryaInstanceName - The name of the Rya instance the {@link TypedEntity}s are for. (not null) */ - public MongoEntityStorage(MongoClient mongo, String ryaInstanceName) { + public MongoEntityStorage(final MongoClient mongo, final String ryaInstanceName) { this.mongo = requireNonNull(mongo); this.ryaInstanceName = requireNonNull(ryaInstanceName); } @Override - public void create(Entity entity) throws EntityStorageException { + public void create(final Entity entity) throws EntityStorageException { requireNonNull(entity); try { @@ -99,7 +98,7 @@ public class MongoEntityStorage implements EntityStorage { } @Override - public void update(Entity old, Entity updated) throws StaleUpdateException, EntityStorageException { + public void update(final Entity old, final Entity updated) throws StaleUpdateException, EntityStorageException { requireNonNull(old); requireNonNull(updated); @@ -134,7 +133,7 @@ public class MongoEntityStorage implements EntityStorage { } @Override - public Optional<Entity> get(RyaURI subject) throws EntityStorageException { + public Optional<Entity> get(final RyaURI subject) throws EntityStorageException { requireNonNull(subject); try { @@ -153,7 +152,7 @@ public class MongoEntityStorage implements EntityStorage { } @Override - public CloseableIterator<TypedEntity> search(final Type type, final Set<Property> properties) throws EntityStorageException { + public ConvertingCursor<TypedEntity> search(final Optional<RyaURI> subject, final Type type, final Set<Property> properties) throws EntityStorageException { requireNonNull(type); requireNonNull(properties); @@ -197,7 +196,7 @@ public class MongoEntityStorage implements EntityStorage { } @Override - public boolean delete(RyaURI subject) throws EntityStorageException { + public boolean delete(final RyaURI subject) throws EntityStorageException { requireNonNull(subject); try { @@ -212,19 +211,19 @@ public class MongoEntityStorage implements EntityStorage { } } - private static Bson makeSubjectFilter(RyaURI subject) { + private static Bson makeSubjectFilter(final RyaURI subject) { return Filters.eq(EntityDocumentConverter.SUBJECT, subject.getData()); } - private static Bson makeVersionFilter(int version) { + private static Bson makeVersionFilter(final int version) { return Filters.eq(EntityDocumentConverter.VERSION, version); } - private static Bson makeExplicitTypeFilter(RyaURI typeId) { + private static Bson makeExplicitTypeFilter(final RyaURI typeId) { return Filters.eq(EntityDocumentConverter.EXPLICIT_TYPE_IDS, typeId.getData()); } - private static Stream<Bson> makePropertyFilters(RyaURI typeId, Property property) { + private static Stream<Bson> makePropertyFilters(final RyaURI typeId, final Property property) { final String propertyName = property.getName().getData(); // Must match the property's data type. http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/MongoTypeStorage.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/MongoTypeStorage.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/MongoTypeStorage.java index 88a0aa1..0083671 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/MongoTypeStorage.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/MongoTypeStorage.java @@ -20,27 +20,27 @@ package org.apache.rya.indexing.entity.storage.mongo; import static java.util.Objects.requireNonNull; -import javax.annotation.ParametersAreNonnullByDefault; +import java.util.Optional; +import org.apache.rya.api.domain.RyaURI; import org.apache.rya.indexing.entity.model.Type; -import org.apache.rya.indexing.entity.storage.CloseableIterator; import org.apache.rya.indexing.entity.storage.TypeStorage; import org.apache.rya.indexing.entity.storage.mongo.DocumentConverter.DocumentConverterException; import org.bson.Document; import org.bson.conversions.Bson; -import com.google.common.base.Optional; import com.mongodb.MongoClient; import com.mongodb.MongoException; import com.mongodb.client.MongoCursor; import com.mongodb.client.model.Filters; -import mvm.rya.api.domain.RyaURI; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; /** * A Mongo DB implementation of {@link TypeStorage}. */ -@ParametersAreNonnullByDefault +@DefaultAnnotation(NonNull.class) public class MongoTypeStorage implements TypeStorage { private static final String COLLECTION_NAME = "entity-types"; @@ -63,13 +63,13 @@ public class MongoTypeStorage implements TypeStorage { * @param mongo - A client connected to the Mongo instance that hosts the Rya instance. (not null) * @param ryaInstanceName - The name of the Rya instance the {@link Type}s are for. (not null) */ - public MongoTypeStorage(MongoClient mongo, String ryaInstanceName) { + public MongoTypeStorage(final MongoClient mongo, final String ryaInstanceName) { this.mongo = requireNonNull(mongo); this.ryaInstanceName = requireNonNull(ryaInstanceName); } @Override - public void create(Type type) throws TypeStorageException { + public void create(final Type type) throws TypeStorageException { requireNonNull(type); try { @@ -83,7 +83,7 @@ public class MongoTypeStorage implements TypeStorage { } @Override - public Optional<Type> get(RyaURI typeId) throws TypeStorageException { + public Optional<Type> get(final RyaURI typeId) throws TypeStorageException { requireNonNull(typeId); try { @@ -93,7 +93,7 @@ public class MongoTypeStorage implements TypeStorage { .first(); return document == null ? - Optional.absent() : + Optional.empty() : Optional.of( TYPE_CONVERTER.fromDocument(document) ); } catch(final MongoException | DocumentConverterException e) { @@ -102,7 +102,7 @@ public class MongoTypeStorage implements TypeStorage { } @Override - public CloseableIterator<Type> search(RyaURI propertyName) throws TypeStorageException { + public ConvertingCursor<Type> search(final RyaURI propertyName) throws TypeStorageException { requireNonNull(propertyName); try { @@ -128,7 +128,7 @@ public class MongoTypeStorage implements TypeStorage { } @Override - public boolean delete(RyaURI typeId) throws TypeStorageException { + public boolean delete(final RyaURI typeId) throws TypeStorageException { requireNonNull(typeId); try { @@ -143,7 +143,7 @@ public class MongoTypeStorage implements TypeStorage { } } - private static Bson makeIdFilter(RyaURI typeId) { + private static Bson makeIdFilter(final RyaURI typeId) { return Filters.eq(TypeDocumentConverter.ID, typeId.getData()); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/RyaTypeDocumentConverter.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/RyaTypeDocumentConverter.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/RyaTypeDocumentConverter.java index f7fd4ac..c0afd73 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/RyaTypeDocumentConverter.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/RyaTypeDocumentConverter.java @@ -20,18 +20,18 @@ package org.apache.rya.indexing.entity.storage.mongo; import static java.util.Objects.requireNonNull; -import javax.annotation.ParametersAreNonnullByDefault; - +import org.apache.rya.api.domain.RyaType; import org.bson.Document; import org.openrdf.model.ValueFactory; import org.openrdf.model.impl.ValueFactoryImpl; -import mvm.rya.api.domain.RyaType; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; /** * Converts between {@link RyaType} and {@link Document}. */ -@ParametersAreNonnullByDefault +@DefaultAnnotation(NonNull.class) public class RyaTypeDocumentConverter implements DocumentConverter<RyaType> { private static final ValueFactory VF = new ValueFactoryImpl(); @@ -40,7 +40,7 @@ public class RyaTypeDocumentConverter implements DocumentConverter<RyaType> { public static final String VALUE = "value"; @Override - public Document toDocument(RyaType ryaType) { + public Document toDocument(final RyaType ryaType) { requireNonNull(ryaType); return new Document() @@ -49,7 +49,7 @@ public class RyaTypeDocumentConverter implements DocumentConverter<RyaType> { } @Override - public RyaType fromDocument(Document document) throws DocumentConverterException { + public RyaType fromDocument(final Document document) throws DocumentConverterException { requireNonNull(document); if(!document.containsKey(DATA_TYPE)) { http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4ac4e867/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/TypeDocumentConverter.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/TypeDocumentConverter.java b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/TypeDocumentConverter.java index 104fbad..37c65bb 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/TypeDocumentConverter.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/TypeDocumentConverter.java @@ -23,19 +23,19 @@ import static java.util.Objects.requireNonNull; import java.util.ArrayList; import java.util.List; -import javax.annotation.ParametersAreNonnullByDefault; - +import org.apache.rya.api.domain.RyaURI; import org.apache.rya.indexing.entity.model.Type; import org.bson.Document; import com.google.common.collect.ImmutableSet; -import mvm.rya.api.domain.RyaURI; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; /** * Converts between {@link Type} and {@link Document}. */ -@ParametersAreNonnullByDefault +@DefaultAnnotation(NonNull.class) public class TypeDocumentConverter implements DocumentConverter<Type> { public static final String ID = "_id";