Skip to content

Commit

Permalink
FMWK-451 Find by "not equals" doesn't return entities with nonexisten…
Browse files Browse the repository at this point in the history
…t path (#749)
  • Loading branch information
agrgr authored May 29, 2024
1 parent 19692d2 commit 3ff86af
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public QueryEngine queryEngine(IAerospikeClient aerospikeClient,
long queryMaxRecords = settings.getDataSettings().getQueryMaxRecords();
log.debug("AerospikeDataSettings.queryMaxRecords: {}", queryMaxRecords);
queryEngine.setQueryMaxRecords(queryMaxRecords);
if (!settings.getDataSettings().isWriteSortedMaps()) {
log.info("AerospikeDataSettings.writeSortedMaps is set to false, " +
"Maps and POJOs will be written as unsorted Maps (degrades performance of Map-related operations ," +
" does not allow comparing Maps)");
}
return queryEngine;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,34 +223,27 @@ public Filter sIndexFilter(Map<QualifierKey, Object> qualifierMap) {
public Exp filterExp(Map<QualifierKey, Object> qualifierMap) {
return getMetadataExp(qualifierMap).orElseGet(() -> {
Value value = getValue(qualifierMap);
return switch (value.getType()) {
Exp ne = switch (value.getType()) {
// FMWK-175: Exp.ne() does not return null bins, so Exp.not(Exp.binExists()) is added
case INTEGER -> {
Exp ne = Exp.ne(Exp.intBin(getBinName(qualifierMap)), Exp.val(value.toLong()));
yield Exp.or(Exp.not(Exp.binExists(getBinName(qualifierMap))), ne);
}
case INTEGER -> Exp.ne(Exp.intBin(getBinName(qualifierMap)), Exp.val(value.toLong()));
case STRING -> {
if (ignoreCase(qualifierMap)) {
String equalsRegexp = getStringEquals(value.toString());
Exp regexCompare = Exp.not(Exp.regexCompare(equalsRegexp, RegexFlag.ICASE,
yield Exp.not(Exp.regexCompare(equalsRegexp, RegexFlag.ICASE,
Exp.stringBin(getBinName(qualifierMap))));
yield Exp.or(Exp.not(Exp.binExists(getBinName(qualifierMap))), regexCompare);
} else {
Exp ne = Exp.ne(Exp.stringBin(getBinName(qualifierMap)), Exp.val(value.toString()));
yield Exp.or(Exp.not(Exp.binExists(getBinName(qualifierMap))), ne);
yield Exp.ne(Exp.stringBin(getBinName(qualifierMap)), Exp.val(value.toString()));
}
}
case BOOL -> {
Exp ne = Exp.ne(Exp.boolBin(getBinName(qualifierMap)), Exp.val((Boolean) value.getObject()));
yield Exp.or(Exp.not(Exp.binExists(getBinName(qualifierMap))), ne);
}
case BOOL -> Exp.ne(Exp.boolBin(getBinName(qualifierMap)), Exp.val((Boolean) value.getObject()));
case MAP -> getFilterExp(Exp.val((Map<?, ?>) value.getObject()), getBinName(qualifierMap), Exp::ne,
Exp::mapBin);
case LIST -> getFilterExp(Exp.val((List<?>) value.getObject()), getBinName(qualifierMap), Exp::ne,
Exp::listBin);
default -> throw new IllegalArgumentException("NOTEQ FilterExpression unsupported particle type: " +
value.getClass().getSimpleName());
};
return Exp.or(Exp.not(Exp.binExists(getBinName(qualifierMap))), ne);
});
}

Expand Down Expand Up @@ -550,7 +543,8 @@ public Filter sIndexFilter(Map<QualifierKey, Object> qualifierMap) {
MAP_VAL_NOTEQ_BY_KEY {
@Override
public Exp filterExp(Map<QualifierKey, Object> qualifierMap) {
return getFilterExpMapValNotEqOrFail(qualifierMap, Exp::ne);
Exp binIsNull = Exp.not(Exp.binExists(getBinName(qualifierMap)));
return Exp.or(binIsNull, getFilterExpMapValNotEqOrFail(qualifierMap, Exp::ne));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,17 @@ void findBySimplePropertyNotEqual_String() {

@Test
void findByNestedSimplePropertyNotEqual() {
String zipCode = "C0123456789";
assertThat(carter.getAddress().getZipCode()).isNotEqualTo(zipCode);
assertThat(repository.findByAddressZipCodeIsNot(zipCode)).contains(carter);

oliver.setFriend(alicia);
repository.save(oliver);
dave.setFriend(oliver);
repository.save(dave);
carter.setFriend(dave);
repository.save(carter);
assertThat(carter.getFriend().getAge()).isEqualTo(42);

// find all records where friend's age is not 42 and all without friend.age
List<Person> result = repository.findByFriendAgeIsNot(42);

assertThat(result)
.hasSize(2)
.containsExactlyInAnyOrder(dave, oliver);
assertThat(result).doesNotContain(carter);

TestUtils.setFriendsToNull(repository, oliver, dave, carter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ void findBySimplePropertyNotIn_String() {
void findByNestedSimplePropertyNotIn_String() {
assertThat(carter.getAddress().getZipCode()).isEqualTo("C0124");
assertThat(dave.getAddress().getZipCode()).isEqualTo("C0123");
assertThat(repository.findByAddressZipCodeNotIn(List.of("C0123", "C0125"))).containsOnly(carter);
// find all records where address' zipCode is not C0123 or C0125, and all without address.zipCode
assertThat(repository.findByAddressZipCodeNotIn(List.of("C0123", "C0125"))).doesNotContain(dave);
}

@Test
Expand Down

0 comments on commit 3ff86af

Please sign in to comment.