Skip to content
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

FMWK-451 Find by "not equals" doesn't return entities with nonexistent path #749

Merged
merged 4 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
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
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
Loading