mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
Incremental name changes; use of builder; fix in normalize
This commit is contained in:
@@ -81,7 +81,12 @@
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-statistics-distribution</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.datastax.oss</groupId>
|
||||
<artifactId>java-driver-core</artifactId>
|
||||
<version>4.15.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -17,12 +17,16 @@
|
||||
package io.nosqlbench.virtdata.api.bindings;
|
||||
|
||||
import io.nosqlbench.api.errors.BasicError;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.function.*;
|
||||
import java.util.function.LongFunction;
|
||||
|
||||
public class VirtDataConversions {
|
||||
|
||||
@@ -33,7 +37,7 @@ public class VirtDataConversions {
|
||||
LongFunction(LongFunction.class, long.class, Object.class),
|
||||
LongUnaryOperator(java.util.function.LongUnaryOperator.class, long.class, long.class),
|
||||
IntFunction(java.util.function.IntFunction.class, int.class, Object.class),
|
||||
IntToDoubleFunction(java.util.function.IntToDoubleFunction.class,int.class,double.class),
|
||||
IntToDoubleFunction(java.util.function.IntToDoubleFunction.class, int.class, double.class),
|
||||
IntToLongFunction(java.util.function.IntToLongFunction.class, int.class, long.class),
|
||||
IntUnaryOperator(java.util.function.IntUnaryOperator.class, int.class, int.class),
|
||||
DoubleFunction(java.util.function.DoubleFunction.class, double.class, Object.class),
|
||||
@@ -46,6 +50,7 @@ public class VirtDataConversions {
|
||||
private final Class<?> inputClazz;
|
||||
private final Class<?> outputClazz;
|
||||
|
||||
|
||||
FuncType(Class<?> functionClazz, Class<?> inputClazz, Class<?> outputClazz) {
|
||||
this.functionClazz = functionClazz;
|
||||
this.inputClazz = inputClazz;
|
||||
@@ -63,6 +68,8 @@ public class VirtDataConversions {
|
||||
|
||||
}
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(VirtDataConversions.class);
|
||||
|
||||
public static <F, T> List<T> adaptFunctionList(F[] funcs, Class<T> functionType, Class<Object>... resultSignature) {
|
||||
List<T> functions = new ArrayList<>();
|
||||
for (Object func : funcs) {
|
||||
@@ -83,6 +90,7 @@ public class VirtDataConversions {
|
||||
* @return An instance of T
|
||||
*/
|
||||
public static <F, T> T adaptFunction(F func, Class<T> functionType, Class<?>... resultSignature) {
|
||||
|
||||
FuncType funcType = FuncType.valueOf(func.getClass());
|
||||
|
||||
List<Class<?>> signature = new ArrayList<>();
|
||||
@@ -96,6 +104,7 @@ public class VirtDataConversions {
|
||||
signature.addAll(fromSignature);
|
||||
signature.addAll(toSignature);
|
||||
|
||||
logger.debug("Adapting function from " + fromSignature + " to " + toSignature);
|
||||
if (fromSignature.equals(toSignature)) {
|
||||
return (T) func;
|
||||
}
|
||||
@@ -108,8 +117,11 @@ public class VirtDataConversions {
|
||||
Method adapter = null;
|
||||
Class<?> hostclass = NBFunctionConverter.class;
|
||||
try {
|
||||
logger.debug("Looking for adapter method for " + hostclass.getCanonicalName() + " with signature " + signature);
|
||||
adapter = NBFunctionConverter.class.getMethod("adapt", methodSignature);
|
||||
} catch (NoSuchMethodException e) {
|
||||
|
||||
logger.debug("No adapter method found for " + hostclass.getCanonicalName() + " with signature " + signature);
|
||||
StringBuilder example = new StringBuilder();
|
||||
|
||||
|
||||
@@ -134,6 +146,8 @@ public class VirtDataConversions {
|
||||
|
||||
}
|
||||
|
||||
logger.debug("Found adapter method for " + hostclass.getCanonicalName() + " with signature " + signature);
|
||||
|
||||
FuncType fromType = FuncType.valueOf(func.getClass());
|
||||
if (fromType.functionClazz.getTypeParameters().length > 0) {
|
||||
TypeVariable<? extends Class<?>>[] funcParms = func.getClass().getTypeParameters();
|
||||
@@ -148,6 +162,8 @@ public class VirtDataConversions {
|
||||
T result = null;
|
||||
|
||||
try {
|
||||
logger.debug("Invoking adapter method for " + hostclass.getCanonicalName() + " with signature "
|
||||
+ signature + " and args " + Arrays.toString(args));
|
||||
result = (T) adapter.invoke(null, args);
|
||||
return result;
|
||||
} catch (IllegalArgumentException e) {
|
||||
@@ -161,9 +177,10 @@ public class VirtDataConversions {
|
||||
|
||||
/**
|
||||
* Slice the incoming object list into a set of functions, based on a grouping interval and an offset.
|
||||
* @param mod The grouping interval, or modulo to slice the function groups into
|
||||
*
|
||||
* @param mod The grouping interval, or modulo to slice the function groups into
|
||||
* @param offset The offset within the group for the provided function
|
||||
* @param funcs A list of source objects to convert to functions.
|
||||
* @param funcs A list of source objects to convert to functions.
|
||||
* @return
|
||||
*/
|
||||
public static <T> List<T> getFunctions(int mod, int offset, Class<? extends T> functionType, Object... funcs) {
|
||||
@@ -171,7 +188,7 @@ public class VirtDataConversions {
|
||||
// throw new RuntimeException("uneven division of functions, where multiples of " + mod + " are expected.");
|
||||
// }
|
||||
List<T> functions = new ArrayList<>();
|
||||
for (int i = offset; i < funcs.length; i+=mod) {
|
||||
for (int i = offset; i < funcs.length; i += mod) {
|
||||
Object func = funcs[i];
|
||||
T longFunction = VirtDataConversions.adaptFunction(func, functionType, Object.class);
|
||||
functions.add(longFunction);
|
||||
|
||||
Reference in New Issue
Block a user