diff --git a/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java b/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java index 7f5fa167c..d538ebdeb 100644 --- a/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java +++ b/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java @@ -1218,6 +1218,16 @@ public Filter sIndexFilter(Map qualifierMap) { return Filter.range(getField(qualifierMap), IndexCollectionType.LIST, Long.MIN_VALUE, getValue1(qualifierMap).toLong()); } + }, EXISTS { + @Override + public Exp filterExp(Map qualifierMap) { + return Exp.binExists(getField(qualifierMap)); + } + + @Override + public Filter sIndexFilter(Map qualifierMap) { + return null; + } }; private static Exp getConvertedValue1Exp(Map qualifierMap) { diff --git a/src/main/java/org/springframework/data/aerospike/repository/query/AerospikeQueryCreator.java b/src/main/java/org/springframework/data/aerospike/repository/query/AerospikeQueryCreator.java index a57f17ab6..6191c2711 100644 --- a/src/main/java/org/springframework/data/aerospike/repository/query/AerospikeQueryCreator.java +++ b/src/main/java/org/springframework/data/aerospike/repository/query/AerospikeQueryCreator.java @@ -124,6 +124,8 @@ private AerospikeCriteria create(Part part, AerospikePersistentProperty property case NOT_IN -> getCriteria(part, property, v1, null, parameters, FilterOperation.NOT_IN); case TRUE -> getCriteria(part, property, true, null, parameters, FilterOperation.EQ); case FALSE -> getCriteria(part, property, false, null, parameters, FilterOperation.EQ); + case EXISTS -> getCriteria(part, property, false, null, parameters, FilterOperation.EXISTS); + case IS_NOT_NULL -> getCriteria(part, property, false, null, parameters, FilterOperation.EXISTS); default -> throw new IllegalArgumentException("Unsupported keyword '" + part.getType() + "'"); }; } diff --git a/src/test/java/org/springframework/data/aerospike/repository/PersonRepositoryQueryTests.java b/src/test/java/org/springframework/data/aerospike/repository/PersonRepositoryQueryTests.java index a65d0309b..7c563c638 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/PersonRepositoryQueryTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/PersonRepositoryQueryTests.java @@ -555,6 +555,18 @@ void findByMapKeyValueNotEqual() { assertThat(persons).containsOnly(carter); } + @Test + void findByAddressExists() { + assertThat(stefan.getAddress()).isNull(); + + List persons = repository.findByAddressExists(); + assertThat(persons).contains(carter); + List persons2 = repository.findByAddressIsNotNull(); + assertThat(persons2).contains(carter); +// List persons = repository.findByAddressNotExists(); +// assertThat(persons).contains(stefan); + } + @Test void findByMapOfListsKeyValueNotEqual() { Map> mapOfLists1 = Map.of("0", List.of(100), "1", List.of(200)); diff --git a/src/test/java/org/springframework/data/aerospike/sample/PersonRepository.java b/src/test/java/org/springframework/data/aerospike/sample/PersonRepository.java index 9ca35cdb5..35d3c0949 100644 --- a/src/test/java/org/springframework/data/aerospike/sample/PersonRepository.java +++ b/src/test/java/org/springframework/data/aerospike/sample/PersonRepository.java @@ -136,6 +136,14 @@ public interface PersonRepository

extends AerospikeRepository< */ List

findByAddressIsNot(Address address); + List

findByAddressExists(); + + List

findByAddressIsNotNull(); + + List

findByAddressNotExists(); + + List

findByAddressIsNull(); + /** * Find all entities that satisfy the condition "have Address with fewer elements or with a corresponding key-value * lower in ordering than in the given argument" (find by POJO).