From b70f01788003aeb7aea4a7dc72b7d83567f74dd4 Mon Sep 17 00:00:00 2001 From: agrgr Date: Thu, 26 Dec 2024 13:32:40 +0200 Subject: [PATCH 1/3] support sIndex byte[] equality --- pom.xml | 2 +- .../data/aerospike/query/FilterOperation.java | 8 ++++++++ .../query/AerospikeQueryCreator.java | 1 + .../query/CollectionQueryCreator.java | 5 +++++ .../AerospikeTemplateFindByQueryTests.java | 18 ++++++++++++++++-- .../blocking/PersonRepositoryQueryTests.java | 3 ++- .../query/blocking/find/EqualsTests.java | 6 ++++++ .../data/aerospike/sample/Person.java | 1 + .../aerospike/sample/PersonRepository.java | 4 ++++ src/test/resources/bootstrap.properties | 2 +- 10 files changed, 45 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 4577ac912..9ef6e6420 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.aerospike spring-data-aerospike - 4.8.0 + 4.8.0-local-554_latest Spring Data Aerospike Aerospike Inc. 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 26d1d1d0d..65eeb1dac 100644 --- a/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java +++ b/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java @@ -41,6 +41,7 @@ import java.util.function.BinaryOperator; import java.util.function.Function; +import static com.aerospike.client.command.ParticleType.BLOB; import static com.aerospike.client.command.ParticleType.BOOL; import static com.aerospike.client.command.ParticleType.INTEGER; import static com.aerospike.client.command.ParticleType.LIST; @@ -192,6 +193,7 @@ public Exp filterExp(Map qualifierMap) { Exp::mapBin); case LIST -> getFilterExp(Exp.val((List) value.getObject()), getBinName(qualifierMap), Exp::eq, Exp::listBin); + case BLOB -> Exp.eq(Exp.blobBin(getBinName(qualifierMap)), Exp.val((byte[]) value.getObject())); default -> throw new IllegalArgumentException("EQ FilterExpression unsupported particle type: " + value.getClass().getSimpleName()); }; @@ -211,6 +213,12 @@ public Filter sIndexFilter(Map qualifierMap) { } yield Filter.equal(getBinName(qualifierMap), value.toString()); } + case BLOB -> { + if (!FilterOperation.getServerVersionSupport(qualifierMap).isServerVersionGtOrEq7()) { + yield null; + } + yield Filter.equal(getBinName(qualifierMap), (byte[]) value.getObject()); + } default -> null; }; } 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 d14eb5723..c5eea0c70 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 @@ -108,6 +108,7 @@ protected CriteriaDefinition create(Part part, Iterator iterator) { private CriteriaDefinition create(Part part, AerospikePersistentProperty property, Iterator parameters) { FilterOperation filterOperation = getFilterOperation(part.getType()); List queryParameters = getQueryParameters(parameters, filterOperation); + // In case of byte[] it does not get converted to an ArrayList, so queryParameters contain byte array IAerospikeQueryCreator queryCreator = getQueryCreator(part, property, queryParameters, filterOperation); queryCreator.validate(); diff --git a/src/main/java/org/springframework/data/aerospike/repository/query/CollectionQueryCreator.java b/src/main/java/org/springframework/data/aerospike/repository/query/CollectionQueryCreator.java index 49d79f2af..cc5a8d7f1 100644 --- a/src/main/java/org/springframework/data/aerospike/repository/query/CollectionQueryCreator.java +++ b/src/main/java/org/springframework/data/aerospike/repository/query/CollectionQueryCreator.java @@ -85,6 +85,11 @@ private void validateCollectionQueryComparison(List queryParameters, Str throw new IllegalArgumentException(queryPartDescription + ": invalid number of arguments, expecting one"); } + // In case of byte[] it does not get converted to an ArrayList, so queryParameters contain byte array + if (queryParameters.get(0) instanceof byte[]) { + return; + } + if (queryParameters.get(0) instanceof Collection) { validateTypes(converter, Collection.class, queryParameters, this.filterOperation, queryPartDescription); } else { diff --git a/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByQueryTests.java b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByQueryTests.java index 2b404d3b1..3d134a3b0 100644 --- a/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByQueryTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/sync/AerospikeTemplateFindByQueryTests.java @@ -53,7 +53,9 @@ public class AerospikeTemplateFindByQueryTests extends BaseBlockingIntegrationTe .strings(Collections.singletonList("str1")).friend(new Person("id21", "TestPerson21", 50)).build(); final Person ashley = Person.builder().id(nextId()).firstName("Ashley").lastName("Matthews") .ints(Collections.singletonList(22)) - .strings(Collections.singletonList("str2")).age(22).friend(new Person("id22", "TestPerson22", 50)).build(); + .byteArray(new byte[]{1, 0, 1, 1, 0, 0, 0, 1}) + .strings(Collections.singletonList("str2")).age(22).friend(new Person("id22", "TestPerson22", 50)) + .build(); final Person beatrice = Person.builder().id(nextId()).firstName("Beatrice").lastName("Matthews").age(23) .ints(Collections.singletonList(23)) .friend(new Person("id23", "TestPerson23", 42)).build(); @@ -86,6 +88,8 @@ public void beforeAllSetUp() { additionalAerospikeTestOperations.createIndex(Person.class, "person_first_name_index", "firstName", IndexType.STRING); + additionalAerospikeTestOperations.createIndex(Person.class, "person_byte_array_index", "byteArray", + IndexType.BLOB); } @Override @@ -102,12 +106,22 @@ public void afterAll() { } @Test - public void findWithFilterEqual() { + public void findWithFilterEqual_String() { Query query = QueryUtils.createQueryForMethodWithArgs(serverVersionSupport, "findByFirstName", "Dave"); Stream result = template.find(query, Person.class); assertThat(result).containsOnly(dave); } + @Test + public void findWithFilterEqual_ByteArray() { + if (serverVersionSupport.isServerVersionGtOrEq7()) { + byte[] byteArray = new byte[]{1, 0, 1, 1, 0, 0, 0, 1}; + Query query = QueryUtils.createQueryForMethodWithArgs(serverVersionSupport, "findByByteArray", new Object[]{byteArray}); + Stream result = template.find(query, Person.class); + assertThat(result).containsOnly(ashley); + } + } + @Test public void findWithFilterEqualWithSetName() { Query query = QueryUtils.createQueryForMethodWithArgs(serverVersionSupport, "findByFirstName", "Dave"); diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/PersonRepositoryQueryTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/PersonRepositoryQueryTests.java index 3c855cc7f..360f20f40 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/PersonRepositoryQueryTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/PersonRepositoryQueryTests.java @@ -70,6 +70,7 @@ public class PersonRepositoryQueryTests extends BaseBlockingIntegrationTests { .firstName("Stefan") .lastName("Lessard") .age(34) + .byteArray(new byte[]{1, 0, 1, 1, 0, 0, 0, 1}) .build(); protected static final Person leroi = Person.builder() .id(nextId()) @@ -89,7 +90,7 @@ public class PersonRepositoryQueryTests extends BaseBlockingIntegrationTests { .firstName("Matias") .lastName("Craft") .age(24) - .intArray(new int[]{1, 2, 3, 4, 5}) + .intArray(new int[]{0, 1, 2, 3, 4, 5}) .build(); protected static final Person douglas = Person.builder() .id(nextId()) diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/EqualsTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/EqualsTests.java index f58503698..46d863d59 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/EqualsTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/EqualsTests.java @@ -408,6 +408,12 @@ void findByCollectionEquals() { // another way to call the method List persons2 = repository.findByStrings(listToCompareWith); assertThat(persons2).contains(dave); + + List persons3 = repository.findByIntArray(new int[]{0, 1, 2, 3, 4, 5}); + assertThat(persons3).containsOnly(matias); + + List persons4 = repository.findByByteArray(new byte[]{1, 0, 1, 1, 0, 0, 0, 1}); + assertThat(persons4).containsOnly(stefan); } } diff --git a/src/test/java/org/springframework/data/aerospike/sample/Person.java b/src/test/java/org/springframework/data/aerospike/sample/Person.java index 506fec27f..c4f0f776d 100644 --- a/src/test/java/org/springframework/data/aerospike/sample/Person.java +++ b/src/test/java/org/springframework/data/aerospike/sample/Person.java @@ -66,6 +66,7 @@ public class Person { private List strings; private List ints; private int[] intArray; + private byte[] byteArray; private List> listOfIntLists; private List> listOfIntMaps; private Set intSet; 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 e3d0efb9a..93ce5bdcb 100644 --- a/src/test/java/org/springframework/data/aerospike/sample/PersonRepository.java +++ b/src/test/java/org/springframework/data/aerospike/sample/PersonRepository.java @@ -1577,6 +1577,10 @@ List

findByFriendStringMapNotContaining(AerospikeQueryCriterion criterion, List

findByGenderIn(List list); + List

findByByteArray(byte[] byteArray); + + List

findByIntArray(int[] intArray); + List

findByFirstNameIs(String name); boolean existsByFirstNameIs(String name); diff --git a/src/test/resources/bootstrap.properties b/src/test/resources/bootstrap.properties index 0a9afb9df..6758afe33 100644 --- a/src/test/resources/bootstrap.properties +++ b/src/test/resources/bootstrap.properties @@ -1,2 +1,2 @@ -embedded.aerospike.dockerImage=aerospike/aerospike-server:6.4.0.10 +embedded.aerospike.dockerImage=aerospike/aerospike-server:7.1.0.0 embedded.aerospike.enabled=true From 42b007a3fec7546d34c3d00c3dae89cfb006c6d0 Mon Sep 17 00:00:00 2001 From: agrgr Date: Thu, 26 Dec 2024 13:33:10 +0200 Subject: [PATCH 2/3] support sIndex byte[] equality --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9ef6e6420..4577ac912 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.aerospike spring-data-aerospike - 4.8.0-local-554_latest + 4.8.0 Spring Data Aerospike Aerospike Inc. From c83da2db290721faf9c92225d1557aa253605ac4 Mon Sep 17 00:00:00 2001 From: agrgr Date: Thu, 26 Dec 2024 15:07:21 +0200 Subject: [PATCH 3/3] update version of Server used for testing --- src/test/resources/bootstrap.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/bootstrap.properties b/src/test/resources/bootstrap.properties index 6758afe33..81800a526 100644 --- a/src/test/resources/bootstrap.properties +++ b/src/test/resources/bootstrap.properties @@ -1,2 +1,2 @@ -embedded.aerospike.dockerImage=aerospike/aerospike-server:7.1.0.0 +embedded.aerospike.dockerImage=aerospike/aerospike-server:7.1.0.7 embedded.aerospike.enabled=true