mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2026-10-12 09:24:52 -05:00
find_one: fix projection, add inclSim, reinstate filters
This commit is contained in:
1 parent
615b3ff3c9
commit
8a5d394570
2 files changed
+34
-22
No files matched your search
+8
-2
@@ -41,7 +41,7 @@ public class DataApiCollectionFindOneOpDispenser extends DataApiOpDispenser {
|
||||
private LongFunction<DataApiCollectionFindOneOp> createOpFunction(ParsedOp op) {
|
||||
return (l) -> {
|
||||
Database db = spaceFunction.apply(l).getDatabase();
|
||||
Filter filter = getFilterFromOp(op, l);
|
||||
Filter filter = getLegacyFilterFromOp(op, l);
|
||||
CollectionFindOneOptions options = getCollectionFindOneOptions(op, l);
|
||||
return new DataApiCollectionFindOneOp(
|
||||
db,
|
||||
@@ -62,7 +62,13 @@ public class DataApiCollectionFindOneOpDispenser extends DataApiOpDispenser {
|
||||
if (projection != null) {
|
||||
options = options.projection(projection);
|
||||
}
|
||||
options.includeSimilarity(true);
|
||||
Boolean includeSimilarity = getIncludeSimilarityFromOp(op, l);
|
||||
if (includeSimilarity != null) {
|
||||
options.includeSimilarity(includeSimilarity);
|
||||
} else {
|
||||
// defaulting to true
|
||||
options.includeSimilarity(true);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
+26
-20
@@ -34,6 +34,7 @@ import io.nosqlbench.adapters.api.templating.ParsedOp;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class DataApiOpDispenser extends BaseOpDispenser<DataApiBaseOp, DataApiSpace> {
|
||||
protected final LongFunction<String> targetFunction;
|
||||
@@ -225,28 +226,24 @@ public abstract class DataApiOpDispenser extends BaseOpDispenser<DataApiBaseOp,
|
||||
}
|
||||
|
||||
protected Projection[] getProjectionFromOp(ParsedOp op, long l) {
|
||||
Projection[] projection = null;
|
||||
Optional<LongFunction<Map>> projectionFunction = op.getAsOptionalFunction("projection", Map.class);
|
||||
if (projectionFunction.isPresent()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String,List<String>> projectionFields = projectionFunction.get().apply(l);
|
||||
for (Map.Entry<String,List<String>> field : projectionFields.entrySet()) {
|
||||
List<String> includeFields = field.getValue();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String includeField : includeFields) {
|
||||
sb.append(includeField).append(",");
|
||||
}
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
if (field.getKey().equalsIgnoreCase("include")) {
|
||||
projection = Projection.include(sb.toString());
|
||||
} else if (field.getKey().equalsIgnoreCase("exclude")) {
|
||||
projection = Projection.exclude(sb.toString());
|
||||
} else {
|
||||
logger.error("Projection " + field + " not supported");
|
||||
}
|
||||
}
|
||||
if (projectionFunction.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return projection;
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, List<String>> projectionFields = projectionFunction.get().apply(l);
|
||||
return projectionFields.entrySet().stream()
|
||||
.flatMap(field -> {
|
||||
String[] arr = field.getValue().toArray(new String[0]);
|
||||
if (field.getKey().equalsIgnoreCase("include")) {
|
||||
return Arrays.stream(Projection.include(arr));
|
||||
} else if (field.getKey().equalsIgnoreCase("exclude")) {
|
||||
return Arrays.stream(Projection.exclude(arr));
|
||||
} else {
|
||||
logger.error("Projection directive '" + field.getKey() + "' not supported");
|
||||
return Stream.<Projection>empty();
|
||||
}
|
||||
}).toArray(Projection[]::new);
|
||||
}
|
||||
|
||||
protected Boolean getUpsertFromOp(ParsedOp op, long l) {
|
||||
@@ -258,6 +255,15 @@ public abstract class DataApiOpDispenser extends BaseOpDispenser<DataApiBaseOp,
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Boolean getIncludeSimilarityFromOp(ParsedOp op, long l) {
|
||||
Optional<LongFunction<Boolean>> includeSimFunction = op.getAsOptionalFunction("include_similarity", Boolean.class);
|
||||
if (includeSimFunction.isPresent()) {
|
||||
LongFunction<Boolean> uf = includeSimFunction.get();
|
||||
return uf.apply(l);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Map<String, Object> getFreeFormFromOp(ParsedOp op, long l, String fieldName, Boolean required) {
|
||||
Optional<LongFunction<Map>> ffMapFunc = op.getAsOptionalFunction(fieldName, Map.class);
|
||||
|
||||
Reference in new issue
Block a user