Add estimated document count API

This commit is contained in:
Madhavan Sridharan 2024-05-14 17:00:30 -04:00
parent cdb65ce56e
commit ce3bbe52d5
8 changed files with 99 additions and 1 deletions

View File

@ -62,6 +62,8 @@ public class DataApiOpMapper implements OpMapper<DataApiBaseOp> {
case list_collections -> new DataApiListCollectionsOpDispenser(adapter, op, typeAndTarget.targetFunction);
case list_collection_names ->
new DataApiListCollectionNamesOpDispenser(adapter, op, typeAndTarget.targetFunction);
case estimated_document_count ->
new DataApiEstimatedDocumentCountOpDispenser(adapter, op, typeAndTarget.targetFunction);
};
}
}

View File

@ -0,0 +1,47 @@
/*
* Copyright (c) 2020-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 io.nosqlbench.adapter.dataapi.DataApiDriverAdapter;
import io.nosqlbench.adapter.dataapi.ops.DataApiBaseOp;
import io.nosqlbench.adapter.dataapi.ops.DataApiEstimatedDocumentCountOp;
import io.nosqlbench.adapters.api.templating.ParsedOp;
import java.util.function.LongFunction;
public class DataApiEstimatedDocumentCountOpDispenser extends DataApiOpDispenser {
private final LongFunction<DataApiEstimatedDocumentCountOp> opFunction;
public DataApiEstimatedDocumentCountOpDispenser(
DataApiDriverAdapter adapter, ParsedOp op, LongFunction<String> targetFunction) {
super(adapter, op, targetFunction);
this.opFunction = createOpFunction(op);
}
private LongFunction<DataApiEstimatedDocumentCountOp> createOpFunction(ParsedOp op) {
return (l) -> {
return new DataApiEstimatedDocumentCountOp(
spaceFunction.apply(l).getDatabase(),
targetFunction.apply(l)
);
};
}
@Override
public DataApiBaseOp getOp(long value) {
return opFunction.apply(value);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 nosqlbench
* Copyright (c) 2020-2024 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2020-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.Document;
public class DataApiEstimatedDocumentCountOp extends DataApiBaseOp {
private final String collectionName;
public DataApiEstimatedDocumentCountOp(Database db, String collectionName) {
super(db);
this.collectionName = collectionName;
}
@Override
public Object apply(long value) {
long response;
Collection<Document> collection = db.getCollection(collectionName);
response = collection.estimatedDocumentCount();
return response;
}
}

View File

@ -34,4 +34,5 @@ public enum DataApiOpType {
delete_collection,
list_collections,
list_collection_names,
estimated_document_count,
}

View File

@ -0,0 +1,9 @@
scenarios:
default:
estimated_document_count: run driver=dataapi tags==blocks:estimated_document_count cycles=1
blocks:
estimated_document_count:
ops:
op1:
estimated_document_count: "collectionName"

View File

@ -6,3 +6,4 @@ blocks:
list_collection_names:
ops:
op1:
list_collection_names:

View File

@ -6,3 +6,4 @@ blocks:
list_collections:
ops:
op1:
list_collections: