Skip to content

GDB-8161 MongoDB connector: Multiple index calls in the same query #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/main/java/com/ontotext/trree/plugin/mongodb/MongoDBPlugin.java
Copy link

@NordilJ NordilJ Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I run this branch in order to test the examples from the documentation, the first example was still giving only 1 result (if we swap mongodb:entity ?entity to be in the first sub-query and mongodb:entity ?creativeWork in the second sub-query we get 2 results).

Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public double estimate(long subject, long predicate, long object, long context,
if (predicate == rdf_type) {
if (ctx != null && ctx.iters != null && object != 0 && object != Entities.BOUND) {
String suffix = Utils.matchPrefix(
pluginConnection.getEntities().get(object).stringValue(), NAMESPACE_INST);
pluginConnection.getEntities().get(object).stringValue(), NAMESPACE_INST, NAMESPACE);
if (suffix != null && suffix.length() > 0) {
return 0.3;
}
Expand Down Expand Up @@ -243,7 +243,7 @@ public StatementIterator interpret(long subject, long predicate, long object, lo
if (predicate == rdf_type && context == 0) {
if (object >= 0)
return null;
String suffix = Utils.matchPrefix(Utils.getString(entities, object), NAMESPACE_INST);
String suffix = Utils.matchPrefix(Utils.getString(entities, object), NAMESPACE_INST, NAMESPACE);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not care about this, since context is 0, we never get to here with the specific graph

if (suffix == null)
return null;
if (ctx.iters != null) {
Expand Down Expand Up @@ -421,7 +421,7 @@ public StatementIterator interpret(long subject, long predicate, long object, lo

if (context != 0) {
MongoResultIterator iterator;
String suffix = Utils.matchPrefix(entities.get(context).stringValue(), NAMESPACE_INST);
String suffix = Utils.matchPrefix(entities.get(context).stringValue(), NAMESPACE, NAMESPACE_INST);
if (suffix != null && suffix.length() > 0) {
if (ctx.iters == null) {
// no iterators up until this moment so we probably have model pattern before the actual query definition
Expand Down Expand Up @@ -502,7 +502,7 @@ public boolean interpretUpdate(long subject, long predicate, long object, long c
|| predicate == passwordId || predicate == authDbId) {
// no valid object or subject
// get new instance localname
String suffix = Utils.matchPrefix(Utils.getString(pluginConnection.getEntities(), subject), NAMESPACE_INST);
String suffix = Utils.matchPrefix(Utils.getString(pluginConnection.getEntities(), subject), NAMESPACE_INST, NAMESPACE);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should never get here as well

if (suffix == null) {
getLogger().error("No valid localname for the instance when registering a connection to MongoDB");
return true;
Expand Down Expand Up @@ -541,7 +541,7 @@ public boolean interpretUpdate(long subject, long predicate, long object, long c
return true;
}
if (predicate == dropId) {
String suffix = Utils.matchPrefix(Utils.getString(pluginConnection.getEntities(), subject), NAMESPACE_INST);
String suffix = Utils.matchPrefix(Utils.getString(pluginConnection.getEntities(), subject), NAMESPACE_INST, NAMESPACE);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can lead to lot of thrown exception, don`t need it here as well

if (suffix == null) {
getLogger().error("No valid localname for the instance when registering a connection to MongoDB");
return true;
Expand Down Expand Up @@ -614,7 +614,7 @@ protected MongoResultIterator getIteratorOrNull(long subject, long context, Cont
}

protected MongoResultIterator createMainIterator(long graphId, Entities entities, ContextImpl ctx) {
String suffix = Utils.matchPrefix(entities.get(graphId).stringValue(), NAMESPACE_INST);
String suffix = Utils.matchPrefix(entities.get(graphId).stringValue(), NAMESPACE_INST, NAMESPACE);
if (StringUtils.isBlank(suffix)) {
getLogger().error("Invalid MongoDB inst {}!", suffix);
return null;
Expand Down Expand Up @@ -864,7 +864,10 @@ private boolean isAlreadyDelegateToSomeoneElse(ContextImpl ctx, MongoResultItera

@Override public StatementIterator createEntityIter(long pred) {
// we should have actual iterator instance when entity iterator is requested
return getDelegate().createEntityIter(pred);
MongoResultIterator iterator = getDelegate();
if (iterator == null)
return StatementIterator.EMPTY;
return iterator.createEntityIter(pred);
}

@Override public void setQuery(String query) {
Expand Down