Skip to content

Commit

Permalink
fix(ecl): case when AND expression constraint has a single ID only
Browse files Browse the repository at this point in the history
  • Loading branch information
cmark committed Mar 29, 2022
1 parent f4cfb60 commit 50e943d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;

/**
* @since 8.2.0
Expand Down Expand Up @@ -238,8 +239,14 @@ protected Promise<Expression> eval(C context, final AndExpressionConstraint and)
break;
}
}
if (!CompareUtils.isEmpty(ids)) {
if (ids.size() == 1) {
// if only a single ID is part of the AND expression, then match that
return Promise.immediate(id(Iterables.getOnlyElement(ids)));
} else if (ids.size() > 1) {
// if 2 or more the nothing can match the query
return Promise.immediate(Expressions.matchNone());
} else {
// otherwise nothing to do
}
}
return Promise.all(evaluate(context, and.getLeft()), evaluate(context, and.getRight()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import static com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument.Expressions.statedAncestors;
import static com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument.Expressions.statedParents;
import static com.b2international.snowowl.test.commons.snomed.DocumentBuilders.*;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;

import java.math.BigDecimal;
Expand All @@ -43,6 +45,7 @@
import com.b2international.index.query.Expression;
import com.b2international.index.query.Expressions;
import com.b2international.index.query.MatchNone;
import com.b2international.index.revision.Revision;
import com.b2international.index.revision.StagingArea;
import com.b2international.snowowl.core.api.SnowowlRuntimeException;
import com.b2international.snowowl.core.domain.IComponent;
Expand Down Expand Up @@ -393,6 +396,13 @@ public void ancestorOrSelfOfAny() throws Exception {
assertEquals(Expressions.matchAll(), actual);
}

@Test
public void selfAndSelf() throws Exception {
final Expression actual = eval(ROOT_ID + " AND " + ROOT_ID);
final Expression expected = Expressions.exactMatch(Revision.Fields.ID, ROOT_ID);
assertEquals(expected, actual);
}

@Test
public void selfAndOther() throws Exception {
final Expression actual = eval(ROOT_ID + " AND " + OTHER_ID);
Expand Down

0 comments on commit 50e943d

Please sign in to comment.