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 892d58470..35d9aa168 100644 --- a/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java +++ b/src/main/java/org/springframework/data/aerospike/query/FilterOperation.java @@ -1697,6 +1697,11 @@ private static Exp mapKeysNotContain(Map qualifierMap) { private static Exp mapKeysContain(Map qualifierMap) { String errMsg = "MAP_KEYS_CONTAIN FilterExpression unsupported type: got " + getValue(qualifierMap).getClass().getSimpleName(); + String[] dotPathArray = getDotPathArray(getDotPath(qualifierMap)); + if (hasMapKeyPlaceholder(qualifierMap) && dotPathArray != null && dotPathArray.length > 1) { + List ctxList = convertToStringListExclStart(dotPathArray); + qualifierMap.put(CTX_ARRAY, resolveCtxList(ctxList)); + } return mapKeysCountComparedToZero(qualifierMap, Exp::gt, getValue(qualifierMap), errMsg); } @@ -2007,4 +2012,8 @@ protected Filter collectionRange(IndexCollectionType collectionType, Map qualifierMap) { return Filter.geoContains(getBinName(qualifierMap), getValue(qualifierMap).toString()); } + + private static boolean hasMapKeyPlaceholder(Map qualifierMap) { + return (Boolean) qualifierMap.getOrDefault(MAP_KEY_PLACEHOLDER, false); + } } diff --git a/src/main/java/org/springframework/data/aerospike/query/qualifier/BaseQualifierBuilder.java b/src/main/java/org/springframework/data/aerospike/query/qualifier/BaseQualifierBuilder.java index bc1210390..dc513985f 100644 --- a/src/main/java/org/springframework/data/aerospike/query/qualifier/BaseQualifierBuilder.java +++ b/src/main/java/org/springframework/data/aerospike/query/qualifier/BaseQualifierBuilder.java @@ -19,8 +19,7 @@ public abstract class BaseQualifierBuilder> im protected final Map map = new HashMap<>(); public boolean getIgnoreCase() { - Object ignoreCase = map.get(IGNORE_CASE); - return ignoreCase != null && Boolean.parseBoolean(ignoreCase.toString()); + return (Boolean) map.getOrDefault(IGNORE_CASE, false); } public FilterOperation getFilterOperation() { diff --git a/src/main/java/org/springframework/data/aerospike/query/qualifier/QualifierKey.java b/src/main/java/org/springframework/data/aerospike/query/qualifier/QualifierKey.java index d193ed40a..8757fb108 100644 --- a/src/main/java/org/springframework/data/aerospike/query/qualifier/QualifierKey.java +++ b/src/main/java/org/springframework/data/aerospike/query/qualifier/QualifierKey.java @@ -24,5 +24,6 @@ public enum QualifierKey { FILTER_OPERATION, DIGEST_KEY, HAS_SINDEX_FILTER, - SERVER_VERSION_SUPPORT + SERVER_VERSION_SUPPORT, + MAP_KEY_PLACEHOLDER } diff --git a/src/main/java/org/springframework/data/aerospike/repository/query/MapQueryCreator.java b/src/main/java/org/springframework/data/aerospike/repository/query/MapQueryCreator.java index f95eeb8c5..9d23a300a 100644 --- a/src/main/java/org/springframework/data/aerospike/repository/query/MapQueryCreator.java +++ b/src/main/java/org/springframework/data/aerospike/repository/query/MapQueryCreator.java @@ -280,11 +280,8 @@ private Qualifier processMapContaining(QueryQualifierBuilder qb, Part part, Stri case KEY -> { op = keysOp; setQualifierBuilderValue(qb, queryParameters.get(1)); - // the actual value is irrelevant here, - // the last dotPath element is discarded within AerospikeQueryCreatorUtils.getCtxFromDotPathArray(), - // the elements except the first and the last are converted to CTX, - // the key object (can contain '.') is transferred separately via qualifier builder value - dotPath.add("mapKeyPlaceholder"); + // Map key placeholder is set for "Map keys containing" queries + qb.setMapKeyPlaceholder(); } case VALUE -> { op = valuesOp; diff --git a/src/main/java/org/springframework/data/aerospike/repository/query/QueryQualifierBuilder.java b/src/main/java/org/springframework/data/aerospike/repository/query/QueryQualifierBuilder.java index 1fe3af10e..3b3cfd1e2 100644 --- a/src/main/java/org/springframework/data/aerospike/repository/query/QueryQualifierBuilder.java +++ b/src/main/java/org/springframework/data/aerospike/repository/query/QueryQualifierBuilder.java @@ -102,8 +102,15 @@ public QueryQualifierBuilder setServerVersionSupport(ServerVersionSupport server return this; } + /** + * Set Map key placeholder (for "Map keys containing" queries). + */ + public QueryQualifierBuilder setMapKeyPlaceholder() { + this.map.put(MAP_KEY_PLACEHOLDER, true); + return this; + } + public boolean hasDotPath() { return map.get(DOT_PATH) != null; } - }