Github user meiercaleb commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/153#discussion_r133739286 --- Diff: extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/MongoEntityStorage.java --- @@ -242,4 +281,46 @@ private static Bson makeExplicitTypeFilter(final RyaURI typeId) { return Stream.of(dataTypeFilter, valueFilter); } + + private boolean detectDuplicates(final Entity entity) throws EntityStorageException { + boolean hasDuplicate = false; + if (duplicateDataDetector.isDetectionEnabled()) { + if (mongoTypeStorage == null) { + mongoTypeStorage = new MongoTypeStorage(mongo, ryaInstanceName); + } + final Builder builder = new Builder(); + builder.setSubject(entity.getSubject()); + boolean abort = false; + for (final RyaURI typeRyaUri : entity.getExplicitTypeIds()) { + Optional<Type> type; + try { + type = mongoTypeStorage.get(typeRyaUri); + } catch (final TypeStorageException e) { + throw new EntityStorageException("Unable to get entity type: " + typeRyaUri, e); + } + if (type.isPresent()) { + final ConvertingCursor<TypedEntity> cursor = search(Optional.empty(), type.get(), Collections.emptySet()); + while (cursor.hasNext()) { + final TypedEntity typedEntity = cursor.next(); --- End diff -- Why doesn't TypedEntity extend Entity? Also, I noticed that your compareEntities method for the DuplicateDataDetector applies to Entities but then immediately checks for Type. Obviously you want to return false if two Entities don't have the same Type, but maybe it would be useful to have a compareTypedEntities method? Then your compareEntities method could effectively delegate to that (check for Type and if the Types are the same, convert the Entities to TypedEntities and call the compareTypedEntities method). It seems like a compareTypedEntities method would align with the use case better -- there would be no need to convert all of the TypedEntities returned in this loop to an Entity. You could convert the given Entity to a TypedEntity if it has a Type, and do a direct comparison to each TypedEntity in this loop.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---