mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
Find Distinct op
This commit is contained in:
parent
c5f74e688c
commit
92f96f6bb4
@ -65,6 +65,7 @@ public class DataApiOpMapper implements OpMapper<DataApiBaseOp> {
|
||||
case estimated_document_count ->
|
||||
new DataApiEstimatedDocumentCountOpDispenser(adapter, op, typeAndTarget.targetFunction);
|
||||
case find_by_id -> new DataApiFindByIdOpDispenser(adapter, op, typeAndTarget.targetFunction);
|
||||
case find_distinct -> new DataApiFindDistinctOpDispenser(adapter, op, typeAndTarget.targetFunction);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.nosqlbench.adapter.dataapi.opdispensers;
|
||||
|
||||
import com.datastax.astra.client.Database;
|
||||
import com.datastax.astra.client.model.Filter;
|
||||
import io.nosqlbench.adapter.dataapi.DataApiDriverAdapter;
|
||||
import io.nosqlbench.adapter.dataapi.ops.DataApiBaseOp;
|
||||
import io.nosqlbench.adapter.dataapi.ops.DataApiFindDistinctOp;
|
||||
import io.nosqlbench.adapters.api.templating.ParsedOp;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.function.LongFunction;
|
||||
|
||||
public class DataApiFindDistinctOpDispenser extends DataApiOpDispenser {
|
||||
private static final Logger logger = LogManager.getLogger(DataApiFindDistinctOpDispenser.class);
|
||||
private final LongFunction<DataApiFindDistinctOp> opFunction;
|
||||
public DataApiFindDistinctOpDispenser(DataApiDriverAdapter adapter, ParsedOp op, LongFunction<String> targetFunction) {
|
||||
super(adapter, op, targetFunction);
|
||||
this.opFunction = createOpFunction(op);
|
||||
}
|
||||
|
||||
private LongFunction<DataApiFindDistinctOp> createOpFunction(ParsedOp op) {
|
||||
return (l) -> {
|
||||
Database db = spaceFunction.apply(l).getDatabase();
|
||||
Filter filter = getFilterFromOp(op, l);
|
||||
Class<?> targetClass = getTargetClass(op, l);
|
||||
return new DataApiFindDistinctOp(
|
||||
db,
|
||||
db.getCollection(targetFunction.apply(l)),
|
||||
op.getAsRequiredFunction("fieldName", String.class).apply(l),
|
||||
filter,
|
||||
targetClass
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
private Class<?> getTargetClass(ParsedOp op, long l) {
|
||||
String className = op.getAsFunctionOr("resultClass", "java.lang.String").apply(l);
|
||||
try {
|
||||
return Class.forName(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataApiBaseOp getOp(long value) {
|
||||
return opFunction.apply(value);
|
||||
}
|
||||
}
|
@ -43,7 +43,7 @@ public class DataApiUpdateManyOpDispenser extends DataApiOpDispenser {
|
||||
Database db = spaceFunction.apply(l).getDatabase();
|
||||
Filter filter = getFilterFromOp(op, l);
|
||||
UpdateManyOptions options = getUpdateManyOptions(op, l);
|
||||
LongFunction<Map<String,Object>> docMapFunc = op.getAsRequiredFunction("updates", Map.class);
|
||||
LongFunction<Map> docMapFunc = op.getAsRequiredFunction("updates", Map.class);
|
||||
|
||||
return new DataApiUpdateManyOp(
|
||||
db,
|
||||
|
@ -43,7 +43,7 @@ public class DataApiUpdateOneOpDispenser extends DataApiOpDispenser {
|
||||
Database db = spaceFunction.apply(l).getDatabase();
|
||||
Filter filter = getFilterFromOp(op, l);
|
||||
UpdateOneOptions options = getUpdateOneOptions(op, l);
|
||||
LongFunction<Map<String,Object>> docMapFunc = op.getAsRequiredFunction("update", Map.class);
|
||||
LongFunction<Map> docMapFunc = op.getAsRequiredFunction("update", Map.class);
|
||||
|
||||
return new DataApiUpdateOneOp(
|
||||
db,
|
||||
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2024 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.adapter.dataapi.ops;
|
||||
|
||||
import com.datastax.astra.client.Collection;
|
||||
import com.datastax.astra.client.Database;
|
||||
import com.datastax.astra.client.model.CollectionOptions;
|
||||
import com.datastax.astra.client.model.Filter;
|
||||
|
||||
public class DataApiFindDistinctOp extends DataApiBaseOp {
|
||||
private final Collection collection;
|
||||
private final String fieldName;
|
||||
private final Filter filter;
|
||||
private final Class<?> resultClass;
|
||||
|
||||
public DataApiFindDistinctOp(Database db, Collection collection, String fieldName, Filter filter, Class<?> resultClass) {
|
||||
super(db);
|
||||
this.collection = collection;
|
||||
this.fieldName = fieldName;
|
||||
this.filter = filter;
|
||||
this.resultClass = resultClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(long value) {
|
||||
return collection.distinct(fieldName, filter, resultClass);
|
||||
}
|
||||
}
|
@ -36,4 +36,5 @@ public enum DataApiOpType {
|
||||
list_collection_names,
|
||||
estimated_document_count,
|
||||
find_by_id,
|
||||
find_distinct,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user