mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2024-11-22 08:46:56 -06:00
update many op impl
This commit is contained in:
parent
1aa8d9ec37
commit
c5f74e688c
@ -16,19 +16,57 @@
|
|||||||
|
|
||||||
package io.nosqlbench.adapter.dataapi.opdispensers;
|
package io.nosqlbench.adapter.dataapi.opdispensers;
|
||||||
|
|
||||||
|
import com.datastax.astra.client.Database;
|
||||||
|
import com.datastax.astra.client.model.*;
|
||||||
import io.nosqlbench.adapter.dataapi.DataApiDriverAdapter;
|
import io.nosqlbench.adapter.dataapi.DataApiDriverAdapter;
|
||||||
import io.nosqlbench.adapter.dataapi.ops.DataApiBaseOp;
|
import io.nosqlbench.adapter.dataapi.ops.DataApiBaseOp;
|
||||||
|
import io.nosqlbench.adapter.dataapi.ops.DataApiUpdateManyOp;
|
||||||
import io.nosqlbench.adapters.api.templating.ParsedOp;
|
import io.nosqlbench.adapters.api.templating.ParsedOp;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.LongFunction;
|
import java.util.function.LongFunction;
|
||||||
|
|
||||||
public class DataApiUpdateManyOpDispenser extends DataApiOpDispenser {
|
public class DataApiUpdateManyOpDispenser extends DataApiOpDispenser {
|
||||||
|
private static final Logger logger = LogManager.getLogger(DataApiUpdateManyOpDispenser.class);
|
||||||
|
private final LongFunction<DataApiUpdateManyOp> opFunction;
|
||||||
|
|
||||||
public DataApiUpdateManyOpDispenser(DataApiDriverAdapter adapter, ParsedOp op, LongFunction<String> targetFunction) {
|
public DataApiUpdateManyOpDispenser(DataApiDriverAdapter adapter, ParsedOp op, LongFunction<String> targetFunction) {
|
||||||
super(adapter, op, targetFunction);
|
super(adapter, op, targetFunction);
|
||||||
|
this.opFunction = createOpFunction(op);
|
||||||
|
}
|
||||||
|
|
||||||
|
private LongFunction<DataApiUpdateManyOp> createOpFunction(ParsedOp op) {
|
||||||
|
return (l) -> {
|
||||||
|
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);
|
||||||
|
|
||||||
|
return new DataApiUpdateManyOp(
|
||||||
|
db,
|
||||||
|
db.getCollection(targetFunction.apply(l)),
|
||||||
|
filter,
|
||||||
|
new Update(docMapFunc.apply(l)),
|
||||||
|
options
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private UpdateManyOptions getUpdateManyOptions(ParsedOp op, long l) {
|
||||||
|
UpdateManyOptions options = new UpdateManyOptions();
|
||||||
|
Optional<LongFunction<Boolean>> upsertFunction = op.getAsOptionalFunction("upsert", Boolean.class);
|
||||||
|
if (upsertFunction.isPresent()) {
|
||||||
|
options = options.upsert(upsertFunction.get().apply(l));
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataApiBaseOp getOp(long value) {
|
public DataApiBaseOp getOp(long value) {
|
||||||
return null;
|
return opFunction.apply(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,14 +43,13 @@ public class DataApiUpdateOneOpDispenser extends DataApiOpDispenser {
|
|||||||
Database db = spaceFunction.apply(l).getDatabase();
|
Database db = spaceFunction.apply(l).getDatabase();
|
||||||
Filter filter = getFilterFromOp(op, l);
|
Filter filter = getFilterFromOp(op, l);
|
||||||
UpdateOneOptions options = getUpdateOneOptions(op, l);
|
UpdateOneOptions options = getUpdateOneOptions(op, l);
|
||||||
LongFunction<Map> docMapFunc = op.getAsRequiredFunction("update", Map.class);
|
LongFunction<Map<String,Object>> docMapFunc = op.getAsRequiredFunction("update", Map.class);
|
||||||
LongFunction<Document> docFunc = (long m) -> new Document(docMapFunc.apply(m));
|
|
||||||
|
|
||||||
return new DataApiUpdateOneOp(
|
return new DataApiUpdateOneOp(
|
||||||
db,
|
db,
|
||||||
db.getCollection(targetFunction.apply(l)),
|
db.getCollection(targetFunction.apply(l)),
|
||||||
filter,
|
filter,
|
||||||
new Update(docFunc.apply(l)),
|
new Update(docMapFunc.apply(l)),
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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.Filter;
|
||||||
|
import com.datastax.astra.client.model.Update;
|
||||||
|
import com.datastax.astra.client.model.UpdateManyOptions;
|
||||||
|
|
||||||
|
public class DataApiUpdateManyOp extends DataApiBaseOp {
|
||||||
|
private final Collection collection;
|
||||||
|
private final Filter filter;
|
||||||
|
private final Update update;
|
||||||
|
private final UpdateManyOptions options;
|
||||||
|
|
||||||
|
public DataApiUpdateManyOp(Database db, Collection collection, Filter filter, Update update, UpdateManyOptions options) {
|
||||||
|
super(db);
|
||||||
|
this.collection = collection;
|
||||||
|
this.filter = filter;
|
||||||
|
this.update = update;
|
||||||
|
this.options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object apply(long value) {
|
||||||
|
return collection.updateMany(filter, update, options);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user