Skip to content

Commit

Permalink
complete moving of resolving CTX list from FilterOperation
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr committed May 26, 2024
1 parent 12b4896 commit 26291ef
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.aerospike.client.query.IndexCollectionType;
import com.aerospike.client.query.RegexFlag;
import org.springframework.data.aerospike.config.AerospikeDataSettings;
import org.springframework.data.aerospike.index.AerospikeIndexResolverUtils;
import org.springframework.data.aerospike.query.qualifier.Qualifier;
import org.springframework.data.aerospike.query.qualifier.QualifierKey;
import org.springframework.data.aerospike.repository.query.CriteriaDefinition;
Expand All @@ -38,7 +37,6 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BinaryOperator;
import java.util.function.Function;
Expand All @@ -49,7 +47,6 @@
import static com.aerospike.client.command.ParticleType.LIST;
import static com.aerospike.client.command.ParticleType.MAP;
import static com.aerospike.client.command.ParticleType.STRING;
import static java.util.function.Predicate.not;
import static org.springframework.data.aerospike.query.qualifier.QualifierKey.*;
import static org.springframework.data.aerospike.repository.query.AerospikeQueryCreatorUtils.getDotPathArray;
import static org.springframework.data.aerospike.util.FilterOperationRegexpBuilder.getContaining;
Expand Down Expand Up @@ -1620,14 +1617,6 @@ private static Exp getFilterExp(Exp exp, String field,
return operator.apply(binExp.apply(field), exp);
}

private static CTX[] resolveCtxList(List<String> ctxList) {
return ctxList.stream()
.filter(not(String::isEmpty))
.map(AerospikeIndexResolverUtils::toCtx)
.filter(Objects::nonNull)
.toArray(CTX[]::new);
}

private static Exp toExp(Object value) {
Exp res;
if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) {
Expand Down Expand Up @@ -1711,16 +1700,13 @@ protected static Integer getNestedType(Map<QualifierKey, Object> qualifierMap) {

@SuppressWarnings("unchecked")
protected static CTX[] getCtxArr(Map<QualifierKey, Object> qualifierMap) {
CTX[] ctxArr = (CTX[]) qualifierMap.get(CTX_ARRAY);
List<String> ctxList = (List<String>) qualifierMap.get(CTX_LIST);
return (ctxList == null) ? ctxArr : resolveCtxList(ctxList);
return (CTX[]) qualifierMap.get(CTX_ARRAY);
}

@SuppressWarnings("unchecked")
protected static String getCtxArrAsString(Map<QualifierKey, Object> qualifierMap) {
CTX[] ctxArr = (CTX[]) qualifierMap.get(CTX_ARRAY);
List<String> ctxList = (List<String>) qualifierMap.get(CTX_LIST);
return (ctxList == null) ? ctxArrToString(ctxArr) : String.join(".", ctxList);
return ctxArrToString(ctxArr);
}

private static String ctxArrToString(CTX[] ctxArr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public enum QualifierKey {
SINGLE_ID_FIELD,
MULTIPLE_IDS_FIELD,
DOT_PATH,
CTX_LIST,
CTX_ARRAY,
IGNORE_CASE,
KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,11 @@ private void logQualifierDetails(CriteriaDefinition criteria) {
String field = (StringUtils.hasLength(qualifier.getBinName()) ? qualifier.getBinName() : "");
String operation = qualifier.getOperation().toString();
operation = (StringUtils.hasLength(operation) ? operation : "N/A");
Value k = qualifier.getKey();
String key = printValue(k);
Value val = qualifier.getValue();
String value = printValue(val);
Value val2 = qualifier.getSecondValue();
String value2 = printValue(val2);

LOG.debug("Created query: field = {}, operation = {}, key = {}, value = {}, value2 = {}",
String key = printValue(qualifier.getKey());
String value = printValue(qualifier.getValue());
String value2 = printValue(qualifier.getSecondValue());

LOG.debug("Created qualifier-based query: bin name = {}, operation = {}, key = {}, value = {}, value2 = {}",
field, operation, key, value, value2);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.springframework.data.aerospike.repository.query;

import com.aerospike.client.Value;
import com.aerospike.client.cdt.CTX;
import org.springframework.data.aerospike.convert.MappingAerospikeConverter;
import org.springframework.data.aerospike.index.AerospikeIndexResolverUtils;
import org.springframework.data.aerospike.mapping.AerospikePersistentProperty;
import org.springframework.data.aerospike.query.FilterOperation;
import org.springframework.data.aerospike.query.qualifier.Qualifier;
Expand All @@ -17,10 +19,12 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.util.function.Predicate.not;
import static org.springframework.data.aerospike.convert.AerospikeConverter.CLASS_KEY;
import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeNullQueryCriterion;
import static org.springframework.data.aerospike.repository.query.CriteriaDefinition.AerospikeNullQueryCriterion.NULL_PARAM;
Expand All @@ -38,13 +42,22 @@ protected static Qualifier setQualifier(QueryQualifierBuilder qb, String binName
qb.setDotPath(dotPath);
String[] dotPathArr = getDotPathArray(dotPath);
if (dotPathArr != null && dotPathArr.length > 2) {
qb.setCtxList(getCtxFromDotPathArray(dotPathArr));
List<String> ctxList = getCtxFromDotPathArray(dotPathArr);
qb.setCtxArray(resolveCtxList(ctxList));
}
}
qb.setServerVersionSupport(versionSupport);
return qb.build();
}

private static CTX[] resolveCtxList(List<String> ctxList) {
return ctxList.stream()
.filter(not(String::isEmpty))
.map(AerospikeIndexResolverUtils::toCtx)
.filter(Objects::nonNull)
.toArray(CTX[]::new);
}

public static String[] getDotPathArray(List<String> dotPathList) {
if (dotPathList != null && !dotPathList.isEmpty()) {
// the first element of dotPath is part.getProperty().toDotPath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ public QueryQualifierBuilder setDotPath(List<String> dotPath) {
return this;
}

/**
* Set context path as a list of Strings.
*/
public QueryQualifierBuilder setCtxList(List<String> ctxList) {
this.map.put(CTX_LIST, ctxList);
return this;
}

/**
* Set CTX[].
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ void queryIsCreated() {
creator.createQuery();

assertThat(memoryAppender.countEventsForLogger(LOGGER_NAME)).isPositive();
String msg = "Created query: field = firstName, operation = EQ, key = , value = TestName, value2 = ";
String msg = "Created qualifier-based query: bin name = firstName, operation = EQ, key = , value = TestName, " +
"value2 = ";
assertThat(memoryAppender.search(msg, Level.DEBUG).size()).isEqualTo(1);
assertThat(memoryAppender.contains(msg, Level.INFO)).isFalse();
}
Expand Down

0 comments on commit 26291ef

Please sign in to comment.