Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr committed Jul 31, 2023
1 parent 66235fe commit 4eda2bb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ public Filter sIndexFilter(Map<String, Object> qualifierMap) {
MAP_VAL_NOT_EXISTS_BY_KEY {
@Override
public Exp filterExp(Map<String, Object> qualifierMap) {
return FilterOperation.findNotExistingByMapKey(qualifierMap);
return findNotExistingByMapKey(qualifierMap);
}

@Override
Expand Down Expand Up @@ -832,7 +832,7 @@ public Exp filterExp(Map<String, Object> qualifierMap) {
case JBLOB -> getConvertedValue1Exp(qualifierMap);
case LIST -> Exp.val((List<?>) getValue1(qualifierMap).getObject());
case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1));
default -> throw new IllegalArgumentException(
default -> throw new UnsupportedOperationException(
"MAP_KEYS_CONTAIN FilterExpression unsupported type: got " +
getValue1(qualifierMap).getClass().getSimpleName());
};
Expand All @@ -857,7 +857,7 @@ public Exp filterExp(Map<String, Object> qualifierMap) {
case JBLOB -> getConvertedValue1Exp(qualifierMap);
case LIST -> Exp.val((List<?>) getValue1(qualifierMap).getObject());
case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1));
default -> throw new IllegalArgumentException(
default -> throw new UnsupportedOperationException(
"MAP_KEYS_CONTAIN FilterExpression unsupported type: got " +
getValue1(qualifierMap).getClass().getSimpleName());
};
Expand All @@ -884,7 +884,7 @@ public Exp filterExp(Map<String, Object> qualifierMap) {
case LIST -> Exp.val((List<?>) getValue1(qualifierMap).getObject());
case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1));
case NULL -> Exp.nil();
default -> throw new IllegalArgumentException(
default -> throw new UnsupportedOperationException(
"MAP_VALUES_CONTAIN FilterExpression unsupported type: got " +
getValue1(qualifierMap).getClass().getSimpleName());
};
Expand All @@ -909,7 +909,7 @@ public Exp filterExp(Map<String, Object> qualifierMap) {
case LIST -> Exp.val((List<?>) getValue1(qualifierMap).getObject());
case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1));
case NULL -> Exp.nil();
default -> throw new IllegalArgumentException(
default -> throw new UnsupportedOperationException(
"MAP_VALUES_CONTAIN FilterExpression unsupported type: got " +
getValue1(qualifierMap).getClass().getSimpleName());
};
Expand Down Expand Up @@ -943,7 +943,7 @@ public Exp filterExp(Map<String, Object> qualifierMap) {
Exp.val((List<?>) getValue2(qualifierMap).getObject()));
case MAP -> Pair.of(Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1)),
Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue2)));
default -> throw new IllegalArgumentException(
default -> throw new UnsupportedOperationException(
"MAP_KEYS_BETWEEN FilterExpression unsupported type: got "
+ getValue1(qualifierMap).getClass().getSimpleName());
};
Expand Down Expand Up @@ -976,7 +976,7 @@ public Exp filterExp(Map<String, Object> qualifierMap) {
Exp.val((List<?>) getValue2(qualifierMap).getObject()));
case MAP -> Pair.of(Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1)),
Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue2)));
default -> throw new IllegalArgumentException(
default -> throw new UnsupportedOperationException(
"MAP_VAL_BETWEEN FilterExpression unsupported type: got "
+ getValue1(qualifierMap).getClass().getSimpleName());
};
Expand Down Expand Up @@ -1023,7 +1023,7 @@ public Exp filterExp(Map<String, Object> qualifierMap) {
case LIST -> Exp.val((List<?>) getValue1(qualifierMap).getObject());
case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1));
case ParticleType.NULL -> Exp.nil();
default -> throw new IllegalArgumentException(
default -> throw new UnsupportedOperationException(
"LIST_VAL_CONTAINING FilterExpression unsupported type: got " +
getValue1(qualifierMap).getClass().getSimpleName());
};
Expand Down Expand Up @@ -1059,7 +1059,7 @@ public Exp filterExp(Map<String, Object> qualifierMap) {
case LIST -> Exp.val((List<?>) getValue1(qualifierMap).getObject());
case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1));
case ParticleType.NULL -> Exp.nil();
default -> throw new IllegalArgumentException(
default -> throw new UnsupportedOperationException(
"LIST_VAL_CONTAINING FilterExpression unsupported type: got " +
getValue1(qualifierMap).getClass().getSimpleName());
};
Expand Down Expand Up @@ -1093,7 +1093,7 @@ public Exp filterExp(Map<String, Object> qualifierMap) {
Exp.val((List<?>) getValue2(qualifierMap).getObject()));
case MAP -> Pair.of(Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1)),
Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue2)));
default -> throw new IllegalArgumentException(
default -> throw new UnsupportedOperationException(
"LIST_VAL_BETWEEN FilterExpression unsupported type: got "
+ getValue1(qualifierMap).getClass().getSimpleName());
};
Expand Down Expand Up @@ -1134,7 +1134,7 @@ public Exp filterExp(Map<String, Object> qualifierMap) {
case JBLOB -> FilterOperation.getConvertedValue1Exp(qualifierMap);
case LIST -> Exp.val((List<?>) getValue1(qualifierMap).getObject());
case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1));
default -> throw new IllegalArgumentException(
default -> throw new UnsupportedOperationException(
"LIST_VAL_GT FilterExpression unsupported type: got "
+ getValue1(qualifierMap).getClass().getSimpleName());
};
Expand Down Expand Up @@ -1166,7 +1166,7 @@ public Exp filterExp(Map<String, Object> qualifierMap) {
case JBLOB -> FilterOperation.getConvertedValue1Exp(qualifierMap);
case LIST -> Exp.val((List<?>) getValue1(qualifierMap).getObject());
case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1));
default -> throw new IllegalArgumentException(
default -> throw new UnsupportedOperationException(
"LIST_VAL_GTEQ FilterExpression unsupported type: got "
+ getValue1(qualifierMap).getClass().getSimpleName());
};
Expand All @@ -1192,7 +1192,7 @@ public Exp filterExp(Map<String, Object> qualifierMap) {
Exp value = switch (getValue1(qualifierMap).getType()) {
case INTEGER -> {
if (getValue1(qualifierMap).toLong() == Long.MIN_VALUE) {
throw new IllegalArgumentException(
throw new UnsupportedOperationException(
"LIST_VAL_LT FilterExpression unsupported value: expected [Long.MIN_VALUE+1.." +
"Long.MAX_VALUE]");
}
Expand All @@ -1203,7 +1203,7 @@ public Exp filterExp(Map<String, Object> qualifierMap) {
case JBLOB -> FilterOperation.getConvertedValue1Exp(qualifierMap);
case LIST -> Exp.val((List<?>) getValue1(qualifierMap).getObject());
case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1));
default -> throw new IllegalArgumentException(
default -> throw new UnsupportedOperationException(
"LIST_VAL_GTEQ FilterExpression unsupported type: got "
+ getValue1(qualifierMap).getClass().getSimpleName());
};
Expand Down Expand Up @@ -1245,7 +1245,7 @@ public Exp filterExp(Map<String, Object> qualifierMap) {
case JBLOB -> FilterOperation.getConvertedValue1Exp(qualifierMap);
case LIST -> Exp.val((List<?>) getValue1(qualifierMap).getObject());
case MAP -> Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1));
default -> throw new IllegalArgumentException(
default -> throw new UnsupportedOperationException(
"LIST_VAL_LTEQ FilterExpression unsupported type: got " +
getValue1(qualifierMap).getClass().getSimpleName());
};
Expand Down Expand Up @@ -1387,7 +1387,7 @@ private static Exp getFilterExpMapValOrFail(Map<String, Object> qualifierMap, Bi
Exp.val((List<?>) getValue1(qualifierMap).getObject()));
case MAP -> operator.apply(getMapExp(qualifierMap, dotPathArr, Exp.Type.MAP),
Exp.val(getConvertedMap(qualifierMap, FilterOperation::getValue1)));
default -> throw new IllegalArgumentException(
default -> throw new UnsupportedOperationException(
opName + " FilterExpression unsupported type: " + getValue1(qualifierMap).getClass().getSimpleName());
};
}
Expand Down Expand Up @@ -1430,7 +1430,7 @@ private static Exp getMapValEqOrFail(Map<String, Object> qualifierMap, BinaryOpe
useCtx);
case STRING -> {
if (ignoreCase(qualifierMap)) {
throw new IllegalArgumentException(
throw new UnsupportedOperationException(
opName + " FilterExpression: case insensitive comparison is not supported");
}
yield getMapValEqExp(qualifierMap, Exp.Type.STRING, value1.toString(), dotPathArr, operator,
Expand All @@ -1452,7 +1452,7 @@ yield getMapValEqExp(qualifierMap, expType, convertedValue, dotPathArr, operator
dotPathArr, operator, useCtx);
case ParticleType.NULL -> getMapValEqExp(qualifierMap, Exp.Type.NIL, value1, dotPathArr, operator,
useCtx);
default -> throw new IllegalArgumentException(
default -> throw new UnsupportedOperationException(
opName + " FilterExpression unsupported type: " + value1.getClass().getSimpleName());
};
}
Expand Down Expand Up @@ -1576,7 +1576,7 @@ private static Exp toExp(Object value) {
} else if (value instanceof Value.NullValue) {
res = Exp.nil();
} else {
throw new IllegalArgumentException("Unsupported type for converting: " + value.getClass()
throw new UnsupportedOperationException("Unsupported type for converting: " + value.getClass()
.getCanonicalName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
import static org.springframework.data.aerospike.query.FilterOperation.MAP_VALUES_NOT_CONTAIN;
import static org.springframework.data.aerospike.query.FilterOperation.MAP_VAL_CONTAINING_BY_KEY;
import static org.springframework.data.aerospike.query.FilterOperation.MAP_VAL_EQ_BY_KEY;
import static org.springframework.data.aerospike.query.FilterOperation.MAP_VAL_EXISTS_BY_KEY;
import static org.springframework.data.aerospike.query.FilterOperation.MAP_VAL_NOT_EXISTS_BY_KEY;

/**
* @author Peter Milne
Expand Down Expand Up @@ -164,10 +162,6 @@ public AerospikeCriteria getCriteria(Part part, AerospikePersistentProperty prop
switch (onMap) {
case KEY -> op = MAP_KEYS_CONTAIN;
case VALUE -> op = MAP_VALUES_CONTAIN;
case VALUE_EXISTS -> {
op = MAP_VAL_EXISTS_BY_KEY;
value2 = value1;
}
}
} else {
op = FilterOperation.MAP_VAL_EQ_BY_KEY;
Expand All @@ -179,10 +173,6 @@ public AerospikeCriteria getCriteria(Part part, AerospikePersistentProperty prop
switch (onMap) {
case KEY -> op = MAP_KEYS_NOT_CONTAIN;
case VALUE -> op = MAP_VALUES_NOT_CONTAIN;
case VALUE_EXISTS -> {
op = MAP_VAL_NOT_EXISTS_BY_KEY;
value2 = value1;
}
}
} else {
op = FilterOperation.MAP_VAL_NOTEQ_BY_KEY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public interface CriteriaDefinition {
String getKey();

enum AerospikeMapCriteria {
KEY, VALUE, VALUE_CONTAINING, VALUE_EXISTS
KEY, VALUE, VALUE_CONTAINING
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeMapCriteria.KEY;
import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeMapCriteria.VALUE;
import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeMapCriteria.VALUE_CONTAINING;
import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeMapCriteria.VALUE_EXISTS;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class PersonRepositoryQueryTests extends BaseBlockingIntegrationTests {
Expand Down Expand Up @@ -580,7 +579,7 @@ void findByExists() {
stringMap.put("key", null);
stefan.setStringMap(stringMap);
repository.save(stefan);
assertThat(repository.findByStringMapContaining("key", VALUE_EXISTS)).contains(stefan);
assertThat(repository.findByStringMapContaining("key", KEY)).contains(stefan);

stefan.setAddress(null); // cleanup
stefan.setStringMap(null);
Expand All @@ -597,7 +596,7 @@ void findByIsNull() {
stefan.setAddress(new Address(null, null, null, null));
repository.save(stefan);
assertThat(repository.findByAddressIsNull()).doesNotContain(stefan);
assertThat(repository.findByAddressZipCodeIsNull()).contains(stefan);
assertThat(repository.findByAddressZipCodeIsNull()).contains(stefan).doesNotContain(carter, dave);
assertThat(repository.findByAddressZipCode(null)).contains(stefan).doesNotContain(carter, dave);

dave.setBestFriend(stefan);
Expand All @@ -615,8 +614,8 @@ void findByIsNull() {
stringMap.put("key", null);
stefan.setStringMap(stringMap);
repository.save(stefan);
// assertThat(repository.findByStringMapContaining("key", (String) null)).contains(stefan); // key-specific
assertThat(repository.findByStringMapContaining(null, VALUE)).contains(stefan); // among all values in map
assertThat(repository.findByStringMapContaining("key", (String) null)).contains(stefan); // key-specific
assertThat(repository.findByStringMapContaining(null, VALUE)).contains(stefan); // among all map values

List<String> strings = new ArrayList<>();
strings.add(null);
Expand Down Expand Up @@ -655,12 +654,12 @@ void findByIsNotNull() {
stringMap.put("key", "str");
stefan.setStringMap(stringMap);
repository.save(stefan);
assertThat(repository.findByStringMapNotContaining(null, VALUE)).contains(stefan); // among all values
assertThat(repository.findByStringMapNotContaining(null, VALUE)).contains(stefan); // looks at all values

// Currently only for a Map "IsNotNull" differs from "Exists" as map values can both exist and store null
// Getting key-specific results requires post-processing:
// firstly getting all entities with existing map key
List<Person> personsWithMapKeyExists = repository.findByStringMapContaining("key", VALUE_EXISTS);
List<Person> personsWithMapKeyExists = repository.findByStringMapContaining("key", KEY);
// and then filtering those that have the key's value equal to null
List<Person> personsWithMapValueNotNull = personsWithMapKeyExists.stream()
.filter(person -> person.getStringMap().get("key") != null).toList();
Expand All @@ -671,7 +670,7 @@ void findByIsNotNull() {
repository.save(stefan);
assertThat(repository.findByStringMapNotContaining(null, VALUE)).doesNotContain(stefan);

personsWithMapKeyExists = repository.findByStringMapContaining("key", VALUE_EXISTS);
personsWithMapKeyExists = repository.findByStringMapContaining("key", KEY);
personsWithMapValueNotNull = personsWithMapKeyExists.stream()
.filter(person -> person.getStringMap().get("key") != null).toList();
assertThat(personsWithMapValueNotNull).doesNotContain(stefan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ public interface PersonRepository<P extends Person> extends AerospikeRepository<
List<P> findByAddressZipCode(String zipCode);

/**
* Find all entities that satisfy the condition "have address with zipCode which is not equal to the given argument"
* Find all entities that satisfy the condition "have address with zipCode which is not equal to the given
* argument"
*/
List<P> findByAddressZipCodeIsNot(String zipCode);

Expand Down Expand Up @@ -343,20 +344,20 @@ public interface PersonRepository<P extends Person> extends AerospikeRepository<
/**
* Find all entities containing the given map element (key or value depending on the given criterion)
*
* @param value map value
* @param element map value
* @param criterion {@link CriteriaDefinition.AerospikeMapCriteria#KEY} or
* {@link CriteriaDefinition.AerospikeMapCriteria#VALUE}
*/
List<P> findByStringMapContaining(String value, CriteriaDefinition.AerospikeMapCriteria criterion);
List<P> findByStringMapContaining(String element, CriteriaDefinition.AerospikeMapCriteria criterion);

/**
* Find all entities that do not contain the given map element (key or value depending on the given criterion)
*
* @param value map value
* @param element map value
* @param criterion {@link CriteriaDefinition.AerospikeMapCriteria#KEY} or
* {@link CriteriaDefinition.AerospikeMapCriteria#VALUE}
*/
List<P> findByStringMapNotContaining(String value, CriteriaDefinition.AerospikeMapCriteria criterion);
List<P> findByStringMapNotContaining(String element, CriteriaDefinition.AerospikeMapCriteria criterion);

/**
* Find all entities that satisfy the condition "have the given map key and the value equal to the given string"
Expand Down

0 comments on commit 4eda2bb

Please sign in to comment.