Skip to content

Commit

Permalink
1st cut plugin adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkWolters committed Oct 5, 2023
1 parent db00f8c commit 3a6b849
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@
package io.nosqlbench.engine.extensions.vectormath;

import com.datastax.oss.driver.api.core.cql.Row;
import io.nosqlbench.components.NBBaseComponent;
import io.nosqlbench.components.NBComponent;

import java.util.List;
import java.util.Objects;

public class CqlUtils {
public class CqlUtils extends NBBaseComponent {

public CqlUtils(NBComponent parentComponent) {
super(parentComponent);
}

public static long[] cqlRowFieldsToLongArray(String fieldName, List<Row> rows) {
return rows.stream().mapToLong(r -> r.getLong(fieldName)).toArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public String getDescription() {

@Override
public CqlUtils getExtensionObject(Logger logger, NBComponent baseComponent) {
return new CqlUtils();
return new CqlUtils(baseComponent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
package io.nosqlbench.engine.extensions.vectormath;

import com.google.protobuf.Descriptors;
import io.nosqlbench.components.NBBaseComponent;
import io.nosqlbench.components.NBComponent;
import io.pinecone.proto.QueryResponse;
import io.pinecone.proto.ScoredVector;

public class PineconeScriptingUtils {
public class PineconeScriptingUtils extends NBBaseComponent {

public PineconeScriptingUtils(NBComponent parentComponent) {
super(parentComponent);
}

public String[] responseIdsToStringArray(QueryResponse response) {
return response.getMatchesList().stream().map(ScoredVector::getId).toArray(String[]::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public String getDescription() {

@Override
public PineconeScriptingUtils getExtensionObject(Logger logger, NBComponent baseComponent) {
return new PineconeScriptingUtils();
return new PineconeScriptingUtils(baseComponent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import io.nosqlbench.components.NBBaseComponent;
import io.pinecone.proto.QueryResponse;
import io.pinecone.proto.ScoredVector;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -50,7 +51,7 @@ private QueryResponse generateQueryResponse() {
@Test
void responseIdsToStringArrayTest() {
QueryResponse response = generateQueryResponse();
PineconeScriptingUtils utils = new PineconeScriptingUtils();
PineconeScriptingUtils utils = new PineconeScriptingUtils(new NBBaseComponent(null));
String[] ids = utils.responseIdsToStringArray(response);
assert(ids.length == 3);
assert(ids[0].equals("1"));
Expand All @@ -61,7 +62,7 @@ void responseIdsToStringArrayTest() {
@Test
void responseIdsToIntArrayTest() {
QueryResponse response = generateQueryResponse();
PineconeScriptingUtils utils = new PineconeScriptingUtils();
PineconeScriptingUtils utils = new PineconeScriptingUtils(new NBBaseComponent(null));
int[] ids = utils.responseIdsToIntArray(response);
assert(ids.length == 3);
assert(ids[0] == 1);
Expand All @@ -72,7 +73,7 @@ void responseIdsToIntArrayTest() {
@Test
void responseIdsToLongArrayTest() {
QueryResponse response = generateQueryResponse();
PineconeScriptingUtils utils = new PineconeScriptingUtils();
PineconeScriptingUtils utils = new PineconeScriptingUtils(new NBBaseComponent(null));
long[] ids = utils.responseIdsToLongArray(response);
assert(ids.length == 3);
assert(ids[0] == 1L);
Expand All @@ -83,7 +84,7 @@ void responseIdsToLongArrayTest() {
@Test
void responseFieldToStringArrayTest() {
QueryResponse response = generateQueryResponse();
PineconeScriptingUtils utils = new PineconeScriptingUtils();
PineconeScriptingUtils utils = new PineconeScriptingUtils(new NBBaseComponent(null));
String[] ids = utils.responseFieldToStringArray("a", response);
assert(ids.length == 3);
assert(ids[0].equals("4"));
Expand All @@ -94,7 +95,7 @@ void responseFieldToStringArrayTest() {
@Test
void responseFieldToIntArrayTest() {
QueryResponse response = generateQueryResponse();
PineconeScriptingUtils utils = new PineconeScriptingUtils();
PineconeScriptingUtils utils = new PineconeScriptingUtils(new NBBaseComponent(null));
int[] ids = utils.responseFieldToIntArray("b", response);
assert(ids.length == 3);
assert(ids[0] == 5);
Expand All @@ -105,7 +106,7 @@ void responseFieldToIntArrayTest() {
@Test
void responseFieldToLongArrayTest() {
QueryResponse response = generateQueryResponse();
PineconeScriptingUtils utils = new PineconeScriptingUtils();
PineconeScriptingUtils utils = new PineconeScriptingUtils(new NBBaseComponent(null));
long[] ids = utils.responseFieldToLongArray("c", response);
assert(ids.length == 3);
assert(ids[0] == 6L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public String getDescription() {

@Override
public ComputeFunctions getExtensionObject(Logger logger, NBComponent baseComponent) {
return new ComputeFunctions();
return new ComputeFunctions(baseComponent);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package io.nosqlbench.engine.extensions.computefunctions;

import io.nosqlbench.components.NBBaseComponent;
import io.nosqlbench.components.NBComponent;

import java.util.Arrays;
import java.util.DoubleSummaryStatistics;
import java.util.HashSet;
Expand All @@ -39,7 +42,11 @@
* these methods will yield incorrect results as they rely on the <EM>two-pointer</EM> method and do not
* elide duplicates internally.
*/
public class ComputeFunctions {
public class ComputeFunctions extends NBBaseComponent {

public ComputeFunctions(NBComponent parentComponent) {
super(parentComponent);
}

/**
* Compute the recall as the proportion of matching indices divided by the expected indices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@
package io.nosqlbench.engine.extensions.example;

import io.nosqlbench.api.extensions.SandboxPlugin;
import io.nosqlbench.components.NBBaseComponent;
import io.nosqlbench.components.NBComponent;

public class ExamplePlugin implements SandboxPlugin {
public class ExamplePlugin extends NBBaseComponent implements SandboxPlugin {

public ExamplePlugin(NBComponent parentComponent) {
super(parentComponent);
}

public long getSum(int addend1, int addend2) {
return addend1 + addend2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.nosqlbench.engine.extensions.example;

import io.nosqlbench.api.config.LabeledScenarioContext;
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
import io.nosqlbench.components.NBComponent;
import io.nosqlbench.nb.annotations.Service;
Expand All @@ -33,7 +32,7 @@ public String getDescription() {

@Override
public ExamplePlugin getExtensionObject(final Logger logger, final NBComponent baseComponent) {
return new ExamplePlugin();
return new ExamplePlugin(baseComponent);
}

}
4 changes: 4 additions & 0 deletions nb-api/src/main/java/io/nosqlbench/components/NBBuilders.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public PromPushReporterComponent pushReporter(String targetUri, int seconds, Str
return reporter;
}

// public ExamplePlugin getExamplePlugin(final NBComponent component) {
// return new ExamplePlugin(component);
// }

public static class csvReporterBuilder {
private final NBComponent component;
private Path reportTo = Path.of("metrics.csv");
Expand Down
Loading

0 comments on commit 3a6b849

Please sign in to comment.