Skip to content

Commit

Permalink
use internal flag in Map keys containing queries
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr committed Jan 1, 2025
1 parent c619bb7 commit 61ca6cf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,11 @@ private static Exp mapKeysNotContain(Map<QualifierKey, Object> qualifierMap) {
private static Exp mapKeysContain(Map<QualifierKey, Object> 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<String> ctxList = convertToStringListExclStart(dotPathArray);
qualifierMap.put(CTX_ARRAY, resolveCtxList(ctxList));
}
return mapKeysCountComparedToZero(qualifierMap, Exp::gt, getValue(qualifierMap), errMsg);
}

Expand Down Expand Up @@ -2007,4 +2012,9 @@ protected Filter collectionRange(IndexCollectionType collectionType, Map<Qualifi
protected Filter geoWithinRadius(IndexCollectionType collectionType, Map<QualifierKey, Object> qualifierMap) {
return Filter.geoContains(getBinName(qualifierMap), getValue(qualifierMap).toString());
}

private static boolean hasMapKeyPlaceholder(Map<QualifierKey, Object> qualifierMap) {
Object mapKeyPlaceholder = qualifierMap.get(MAP_KEY_PLACEHOLDER);
return mapKeyPlaceholder != null && Boolean.parseBoolean(mapKeyPlaceholder.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ public enum QualifierKey {
FILTER_OPERATION,
DIGEST_KEY,
HAS_SINDEX_FILTER,
SERVER_VERSION_SUPPORT
SERVER_VERSION_SUPPORT,
MAP_KEY_PLACEHOLDER
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

0 comments on commit 61ca6cf

Please sign in to comment.