-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f6772c
commit f7ea27a
Showing
4 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...in/java/io/nosqlbench/adapter/dataapi/opdispensers/DataApiInsertOneVectorOpDispenser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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.model.Document; | ||
import io.nosqlbench.adapter.dataapi.DataApiDriverAdapter; | ||
import io.nosqlbench.adapter.dataapi.ops.DataApiBaseOp; | ||
import io.nosqlbench.adapter.dataapi.ops.DataApiInsertOneOp; | ||
import io.nosqlbench.adapter.dataapi.ops.DataApiInsertOneVectorOp; | ||
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 DataApiInsertOneVectorOpDispenser extends DataApiOpDispenser { | ||
private static final Logger logger = LogManager.getLogger(DataApiInsertOneVectorOpDispenser.class); | ||
private final LongFunction<DataApiInsertOneVectorOp> opFunction; | ||
|
||
public DataApiInsertOneVectorOpDispenser(DataApiDriverAdapter adapter, ParsedOp op, LongFunction<String> targetFunction) { | ||
super(adapter, op, targetFunction); | ||
this.opFunction = createOpFunction(op); | ||
} | ||
|
||
private LongFunction<DataApiInsertOneVectorOp> createOpFunction(ParsedOp op) { | ||
return (l) -> { | ||
Document.parse(op.get("document", l)); | ||
float[] vector = op.get("vector", l); | ||
return new DataApiInsertOneVectorOp( | ||
spaceFunction.apply(l).getDatabase(), | ||
targetFunction.apply(l), | ||
Document.parse(op.get("document", l)), | ||
vector | ||
); | ||
}; | ||
} | ||
|
||
@Override | ||
public DataApiBaseOp getOp(long value) { | ||
return opFunction.apply(value); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...s/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/ops/DataApiInsertOneOp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.nosqlbench.adapter.dataapi.ops; | ||
|
||
import com.datastax.astra.client.Database; | ||
import com.datastax.astra.client.model.Document; | ||
|
||
public class DataApiInsertOneOp extends DataApiBaseOp { | ||
private final Document doc; | ||
private final String collectionName; | ||
|
||
public DataApiInsertOneOp(Database db, String collectionName, Document doc) { | ||
super(db); | ||
this.collectionName = collectionName; | ||
this.doc = doc; | ||
} | ||
|
||
@Override | ||
public Object apply(long value) { | ||
return db.getCollection(collectionName).insertOne(doc); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/ops/DataApiInsertOneVectorOp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.nosqlbench.adapter.dataapi.ops; | ||
|
||
import com.datastax.astra.client.Database; | ||
import com.datastax.astra.client.model.Document; | ||
|
||
public class DataApiInsertOneVectorOp extends DataApiBaseOp { | ||
private final Document doc; | ||
private final String collectionName; | ||
private float[] vector; | ||
|
||
public DataApiInsertOneVectorOp(Database db, String collectionName, Document doc, float[] vector) { | ||
super(db); | ||
this.collectionName = collectionName; | ||
this.doc = doc; | ||
this.vector = vector; | ||
} | ||
|
||
@Override | ||
public Object apply(long value) { | ||
return db.getCollection(collectionName).insertOne(doc, vector); | ||
} | ||
} |