mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
merge main into http_finish and fixup conflicts and http APIs
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<artifactId>mvn-defaults</artifactId>
|
||||
<groupId>io.nosqlbench</groupId>
|
||||
<version>3.12.128-SNAPSHOT</version>
|
||||
<version>3.12.145-SNAPSHOT</version>
|
||||
<relativePath>../mvn-defaults</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -20,17 +20,19 @@
|
||||
<dependency>
|
||||
<groupId>io.nosqlbench</groupId>
|
||||
<artifactId>virtdata-api</artifactId>
|
||||
<version>3.12.128-SNAPSHOT</version>
|
||||
<version>3.12.145-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-csv</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mvel</groupId>
|
||||
<artifactId>mvel2</artifactId>
|
||||
@@ -49,23 +51,12 @@
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-math3</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.elega9t</groupId>
|
||||
<artifactId>number-to-words</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -8,6 +8,11 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
*/
|
||||
public class SharedState {
|
||||
|
||||
public enum Scope {
|
||||
process,
|
||||
thread
|
||||
}
|
||||
|
||||
// A thread-local map of objects by name
|
||||
public static ThreadLocal<HashMap<String,Object>> tl_ObjectMap = ThreadLocal.withInitial(HashMap::new);
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ public class HashedToByteBuffer implements LongFunction<ByteBuffer> {
|
||||
buffer.putLong(l);
|
||||
}
|
||||
buffer.flip();
|
||||
buffer.limit(length);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ public class ListFunctions implements LongFunction<java.util.List<Object>> {
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of object values of each function output. Produces values like ['one','one','one']"
|
||||
})
|
||||
|
||||
public ListFunctions(Object... funcs) {
|
||||
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
|
||||
this.size = valueFuncs.size();
|
||||
|
||||
@@ -45,9 +45,9 @@ public class ListHashed implements LongFunction<List<Object>> {
|
||||
long hash = value;
|
||||
List<Object> list = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
hash = hasher.applyAsLong(hash);
|
||||
int selector = Math.min(i, valueFuncs.size() - 1);
|
||||
LongFunction<?> func = valueFuncs.get(selector);
|
||||
hash = hasher.applyAsLong(value);
|
||||
list.add(func.apply(hash));
|
||||
}
|
||||
return list;
|
||||
|
||||
@@ -34,12 +34,16 @@ public class ListSized implements LongFunction<List<Object>> {
|
||||
"ListSized(FixedValue(5), NumberNameToString(),NumberNameToString(), WeightedStrings('text:1'))",
|
||||
"Create a sized list of object values of each function output. List size function will recursively call the last function till" +
|
||||
"end of the list size functions",
|
||||
"ListSized output ['one','one','text','text','text']"
|
||||
"output: ['one','one','text','text','text']"
|
||||
})
|
||||
public ListSized(Object sizeFunc, Object... funcs) {
|
||||
this.sizeFunc = VirtDataConversions.adaptFunction(sizeFunc, LongToIntFunction.class);
|
||||
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
|
||||
}
|
||||
public ListSized(int size, Object... funcs) {
|
||||
this.sizeFunc = (s) -> size;
|
||||
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> apply(long value) {
|
||||
|
||||
@@ -43,6 +43,11 @@ public class ListSizedHashed implements LongFunction<List<Object>> {
|
||||
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
|
||||
}
|
||||
|
||||
public ListSizedHashed(int size, Object... funcs) {
|
||||
this.sizeFunc = s -> size;
|
||||
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> apply(long value) {
|
||||
int size = sizeFunc.applyAsInt(value);
|
||||
|
||||
@@ -39,6 +39,10 @@ public class ListSizedStepped implements LongFunction<List<Object>> {
|
||||
this.sizeFunc = VirtDataConversions.adaptFunction(sizeFunc,LongToIntFunction.class);
|
||||
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
|
||||
}
|
||||
public ListSizedStepped(int size, Object... funcs) {
|
||||
this.sizeFunc = s -> size;
|
||||
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> apply(long value) {
|
||||
|
||||
@@ -30,8 +30,8 @@ public class ListStepped implements LongFunction<List<Object>> {
|
||||
private final int size;
|
||||
|
||||
@Example({
|
||||
"ListFunctions(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','one']"
|
||||
"ListStepped(NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of ['one','two']"
|
||||
})
|
||||
public ListStepped(Object... funcs) {
|
||||
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs,LongFunction.class,Object.class);
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
import io.nosqlbench.virtdata.api.bindings.VirtDataConversions;
|
||||
import io.nosqlbench.virtdata.api.bindings.VirtDataFunctions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.function.LongFunction;
|
||||
|
||||
/**
|
||||
* Create a Map from a long input based on a set of provided key and value functions.
|
||||
* Any duplicate entries produced by the key functions are elided.
|
||||
*
|
||||
* As a 'Pair-wise' function, the size of the resulting collection is determined directly by the
|
||||
* number of provided element functions. Since this is a map, the functions come in pairs, each
|
||||
* even numbered function is a key function and each odd numbered function is the corresponding value function.
|
||||
*
|
||||
* As neither a 'Stepped' nor a 'Hashed' function, the input value used by each key and value function is the same
|
||||
* as that provided to the outer function.
|
||||
*/
|
||||
@Categories({Category.collections})
|
||||
@ThreadSafeMapper
|
||||
public class MapFunctions implements LongFunction<java.util.Map<Object,Object>> {
|
||||
|
||||
private final List<LongFunction> valueFuncs;
|
||||
private final List<LongFunction> keyFuncs;
|
||||
private final int size;
|
||||
|
||||
@Example({
|
||||
"MapFunctions(NumberNameToString(),NumberNameToString(),ToString(),ToString())",
|
||||
"Create a map of object values. Produces values like {'one':'one'1:1}."
|
||||
})
|
||||
public MapFunctions(Object... funcs) {
|
||||
this.keyFuncs = VirtDataConversions.getFunctions(2, 0, LongFunction.class, funcs);
|
||||
this.valueFuncs = VirtDataConversions.getFunctions(2,1,LongFunction.class, funcs);
|
||||
this.size = valueFuncs.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Map<Object,Object> apply(long value) {
|
||||
java.util.Map<Object,Object> map = new HashMap<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
Object keyObject = keyFuncs.get(i).apply(value);
|
||||
Object valueObject = valueFuncs.get(i).apply(value);
|
||||
map.put(keyObject,valueObject);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
import io.nosqlbench.virtdata.api.bindings.VirtDataConversions;
|
||||
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_long.Hash;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongToIntFunction;
|
||||
|
||||
/**
|
||||
* Create a Map from a long input based on a set of provided key and value functions.
|
||||
* Any duplicate entries produced by the key functions are elided.
|
||||
*
|
||||
* As a 'Pair-wise' function, the size of the resulting collection is determined directly by the
|
||||
* number of provided element functions. Since this is a map, the functions come in pairs, each
|
||||
* even numbered function is a key function and each odd numbered function is the corresponding value function.
|
||||
*
|
||||
* As a 'Hashed' function, the input value is hashed again before being used by each key and value function.
|
||||
*/
|
||||
@Categories({Category.collections})
|
||||
@ThreadSafeMapper
|
||||
public class MapHashed implements LongFunction<java.util.Map<Object,Object>> {
|
||||
|
||||
private final List<LongFunction> valueFuncs;
|
||||
private final List<LongFunction> keyFuncs;
|
||||
private final Hash hasher = new Hash();
|
||||
private final int size;
|
||||
|
||||
|
||||
@Example({
|
||||
"MapHashed(NumberNameToString(),NumberNameToString(),ToString(),ToString())",
|
||||
"Create a map of object values. Produces values like {'one':'one','4464361019114304900','4464361019114304900'}."
|
||||
})
|
||||
public MapHashed(Object... funcs) {
|
||||
this.keyFuncs = VirtDataConversions.getFunctions(2, 0, LongFunction.class, funcs);
|
||||
this.valueFuncs = VirtDataConversions.getFunctions(2,1, LongFunction.class, funcs);
|
||||
this.size = keyFuncs.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Map<Object,Object> apply(long value) {
|
||||
long hash = value;
|
||||
|
||||
java.util.Map<Object,Object> map = new HashMap<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
hash = hasher.applyAsLong(hash);
|
||||
int keySelector = Math.min(i, keyFuncs.size() - 1);
|
||||
int valSelector = Math.min(i, valueFuncs.size() -1);
|
||||
|
||||
Object keyObject = keyFuncs.get(keySelector).apply(hash);
|
||||
Object valueObject = valueFuncs.get(valSelector).apply(hash);
|
||||
map.put(keyObject,valueObject);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
import io.nosqlbench.virtdata.api.bindings.VirtDataConversions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongToIntFunction;
|
||||
|
||||
/**
|
||||
* Create a Map from a long input based on a set of provided key and value functions.
|
||||
* Any duplicate entries produced by the key functions are elided.
|
||||
*
|
||||
* As a 'Sized' function, the first argument is a function which determines the size of the resulting map.
|
||||
* Additional functions provided are used to generate the elements to add to the collection, as in the pair-wise
|
||||
* mode of {@link MapFunctions}. If the size is larger than the number of provided functions, the last provided
|
||||
* function is used repeatedly as needed. (respectively for key functions as well as value functions)
|
||||
*
|
||||
* As neither a 'Stepped' nor a 'Hashed' function, the input value used by each key and value function is the same
|
||||
* as that provided to the outer function.
|
||||
*/
|
||||
@Categories({Category.collections})
|
||||
@ThreadSafeMapper
|
||||
public class MapSized implements LongFunction<java.util.Map<Object,Object>> {
|
||||
|
||||
private final List<LongFunction> valueFuncs;
|
||||
private final List<LongFunction> keyFuncs;
|
||||
private final LongToIntFunction sizeFunc;
|
||||
|
||||
@Example({
|
||||
"MapSized(1, NumberNameToString(),NumberNameToString(),ToString(),ToString())",
|
||||
"Create a map of object values. Produces values like {'one':'one'1:1}."
|
||||
})
|
||||
public MapSized(Object sizeFunc, Object... funcs) {
|
||||
this.sizeFunc = VirtDataConversions.adaptFunction(sizeFunc, LongToIntFunction.class);
|
||||
this.keyFuncs = VirtDataConversions.getFunctions(2, 0, LongFunction.class, funcs);
|
||||
this.valueFuncs = VirtDataConversions.getFunctions(2,1,LongFunction.class, funcs);
|
||||
}
|
||||
public MapSized(int size, Object... funcs) {
|
||||
this.sizeFunc = s -> size;
|
||||
this.keyFuncs = VirtDataConversions.getFunctions(2, 0, LongFunction.class, funcs);
|
||||
this.valueFuncs = VirtDataConversions.getFunctions(2,1,LongFunction.class, funcs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Map<Object,Object> apply(long value) {
|
||||
int size = sizeFunc.applyAsInt(value);
|
||||
java.util.Map<Object,Object> map = new HashMap<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
int keySelector = Math.min(i, keyFuncs.size() - 1);
|
||||
int valSelector = Math.min(i, valueFuncs.size() -1);
|
||||
|
||||
Object keyObject = keyFuncs.get(keySelector).apply(value);
|
||||
Object valueObject = valueFuncs.get(valSelector).apply(value);
|
||||
map.put(keyObject,valueObject);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
import io.nosqlbench.virtdata.api.bindings.VirtDataConversions;
|
||||
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_long.Hash;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongToIntFunction;
|
||||
|
||||
/**
|
||||
* Create a Map from a long input based on a set of provided key and value functions.
|
||||
* Any duplicate entries produced by the key functions are elided.
|
||||
*
|
||||
* As a 'Sized' function, the first argument is a function which determines the size of the resulting map.
|
||||
* Additional functions provided are used to generate the elements to add to the collection, as in the pair-wise
|
||||
* mode of {@link MapFunctions}. If the size is larger than the number of provided functions, the last provided
|
||||
* function is used repeatedly as needed. (respectively for key functions as well as value functions)
|
||||
*
|
||||
* As a 'Hashed' function, the input value is hashed again before being used by each key and value function.
|
||||
*/
|
||||
@Categories({Category.collections})
|
||||
@ThreadSafeMapper
|
||||
public class MapSizedHashed implements LongFunction<java.util.Map<Object,Object>> {
|
||||
|
||||
private final List<LongFunction> valueFuncs;
|
||||
private final List<LongFunction> keyFuncs;
|
||||
private final LongToIntFunction sizeFunc;
|
||||
private final Hash hasher = new Hash();
|
||||
|
||||
|
||||
@Example({
|
||||
"MapSizedHashed(1, NumberNameToString(),NumberNameToString(),ToString(),ToString())",
|
||||
"Create a map of object values. Produces values like {'one':'one'1:1}."
|
||||
})
|
||||
@Example({
|
||||
"MapSizedHashed(HashRange(3,5), NumberNameToString(),NumberNameToString())",
|
||||
"Create a map of object values. Produces values like {'one':'one'1:1}."
|
||||
})
|
||||
public MapSizedHashed(Object sizeFunc, Object... funcs) {
|
||||
this.sizeFunc = VirtDataConversions.adaptFunction(sizeFunc, LongToIntFunction.class);
|
||||
this.keyFuncs = VirtDataConversions.getFunctions(2, 0, LongFunction.class, funcs);
|
||||
this.valueFuncs = VirtDataConversions.getFunctions(2,1, LongFunction.class, funcs);
|
||||
}
|
||||
public MapSizedHashed(int size, Object... funcs) {
|
||||
this.sizeFunc = s -> size;
|
||||
this.keyFuncs = VirtDataConversions.getFunctions(2, 0, LongFunction.class, funcs);
|
||||
this.valueFuncs = VirtDataConversions.getFunctions(2,1, LongFunction.class, funcs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Map<Object,Object> apply(long value) {
|
||||
int size = sizeFunc.applyAsInt(value);
|
||||
long hash = value;
|
||||
|
||||
java.util.Map<Object,Object> map = new HashMap<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
hash = hasher.applyAsLong(hash);
|
||||
int keySelector = Math.min(i, keyFuncs.size() - 1);
|
||||
int valSelector = Math.min(i, valueFuncs.size() -1);
|
||||
|
||||
Object keyObject = keyFuncs.get(keySelector).apply(hash);
|
||||
Object valueObject = valueFuncs.get(valSelector).apply(hash);
|
||||
map.put(keyObject,valueObject);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
import io.nosqlbench.virtdata.api.bindings.VirtDataConversions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongToIntFunction;
|
||||
|
||||
/**
|
||||
* Create a Map from a long input based on a set of provided key and value functions.
|
||||
* Any duplicate entries produced by the key functions are elided.
|
||||
*
|
||||
* As a 'Sized' function, the first argument is a function which determines the size of the resulting map.
|
||||
* Additional functions provided are used to generate the elements to add to the collection, as in the pair-wise
|
||||
* mode of {@link MapFunctions}. If the size is larger than the number of provided functions, the last provided
|
||||
* function is used repeatedly as needed. (respectively for key functions as well as value functions)
|
||||
*
|
||||
* As a 'Stepped' function, the input value is incremented before being used by each key or value function.
|
||||
*/
|
||||
@Categories({Category.collections})
|
||||
@ThreadSafeMapper
|
||||
public class MapSizedStepped implements LongFunction<java.util.Map<Object,Object>> {
|
||||
|
||||
private final List<LongFunction> valueFuncs;
|
||||
private final List<LongFunction> keyFuncs;
|
||||
private final LongToIntFunction sizeFunc;
|
||||
|
||||
@Example({
|
||||
"MapSizedStepped(1, NumberNameToString(),NumberNameToString())",
|
||||
"Create a map of object values. Produces values like {'one':'one'1:1}."
|
||||
})
|
||||
public MapSizedStepped(Object sizeFunc, Object... funcs) {
|
||||
this.sizeFunc = VirtDataConversions.adaptFunction(sizeFunc, LongToIntFunction.class);
|
||||
this.keyFuncs = VirtDataConversions.getFunctions(2, 0, LongFunction.class, funcs);
|
||||
this.valueFuncs = VirtDataConversions.getFunctions(2,1, LongFunction.class, funcs);
|
||||
}
|
||||
public MapSizedStepped(int size, Object... funcs) {
|
||||
this.sizeFunc = s -> size;
|
||||
this.keyFuncs = VirtDataConversions.getFunctions(2, 0, LongFunction.class, funcs);
|
||||
this.valueFuncs = VirtDataConversions.getFunctions(2,1, LongFunction.class, funcs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Map<Object,Object> apply(long value) {
|
||||
int size = sizeFunc.applyAsInt(value);
|
||||
java.util.Map<Object,Object> map = new HashMap<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
int keySelector = Math.min(i, keyFuncs.size() - 1);
|
||||
int valSelector = Math.min(i, valueFuncs.size() -1);
|
||||
|
||||
Object keyObject = keyFuncs.get(keySelector).apply(value+i);
|
||||
Object valueObject = valueFuncs.get(valSelector).apply(value+i);
|
||||
map.put(keyObject,valueObject);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
import io.nosqlbench.virtdata.api.bindings.VirtDataConversions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongToIntFunction;
|
||||
|
||||
/**
|
||||
* Create a Map from a long input based on a set of provided key and value functions.
|
||||
* Any duplicate entries produced by the key functions are elided.
|
||||
*
|
||||
* As a 'Pair-wise' function, the size of the resulting collection is determined directly by the
|
||||
* number of provided element functions. Since this is a map, the functions come in pairs, each
|
||||
* even numbered function is a key function and each odd numbered function is the corresponding value function.
|
||||
*
|
||||
* As a 'Stepped' function, the input value is incremented before being used by each key or value function.
|
||||
*/
|
||||
@Categories({Category.collections})
|
||||
@ThreadSafeMapper
|
||||
public class MapStepped implements LongFunction<java.util.Map<Object,Object>> {
|
||||
|
||||
private final List<LongFunction> valueFuncs;
|
||||
private final List<LongFunction> keyFuncs;
|
||||
private final int size;
|
||||
|
||||
@Example({
|
||||
"MapStepped(1, NumberNameToString(),NumberNameToString(),ToString(),ToString())",
|
||||
"Create a map of object values. Produces values like {'one':'one'1:1}."
|
||||
})
|
||||
public MapStepped(Object... funcs) {
|
||||
this.keyFuncs = VirtDataConversions.getFunctions(2, 0, LongFunction.class, funcs);
|
||||
this.valueFuncs = VirtDataConversions.getFunctions(2,1,LongFunction.class, funcs);
|
||||
this.size = keyFuncs.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Map<Object,Object> apply(long value) {
|
||||
java.util.Map<Object,Object> map = new HashMap<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
int keySelector = Math.min(i, keyFuncs.size() - 1);
|
||||
int valSelector = Math.min(i, valueFuncs.size() -1);
|
||||
|
||||
Object keyObject = keyFuncs.get(keySelector).apply(value+i);
|
||||
Object valueObject = valueFuncs.get(valSelector).apply(value+i);
|
||||
map.put(keyObject,valueObject);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import io.nosqlbench.nb.api.errors.BasicError;
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
import io.nosqlbench.virtdata.api.annotations.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.function.LongFunction;
|
||||
@@ -20,6 +17,8 @@ import java.util.function.LongUnaryOperator;
|
||||
*/
|
||||
@Categories({Category.collections})
|
||||
@ThreadSafeMapper
|
||||
@Deprecated
|
||||
@DeprecatedFunction("use MapFunctions and related functions instead")
|
||||
public class Set implements LongFunction<java.util.Set<Object>> {
|
||||
|
||||
private final LongToIntFunction sizeFunc;
|
||||
|
||||
@@ -30,11 +30,6 @@ public class SetFunctions implements LongFunction<java.util.Set<Object>> {
|
||||
"SetFunctions(NumberNameToString(),NumberNameToString(),NumberNameToString())",
|
||||
"Create a list of object values of each function output. Produces values like ['one'], as each function produces the same value."
|
||||
})
|
||||
@Example({
|
||||
"SetFunctions(NumberNameToString(),FixedValue('bar'))",
|
||||
"Create a list of object values of each function output. Produces values like ['one','bar']."
|
||||
})
|
||||
|
||||
public SetFunctions(Object... funcs) {
|
||||
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
|
||||
this.size = valueFuncs.size();
|
||||
|
||||
@@ -42,9 +42,9 @@ public class SetHashed implements LongFunction<java.util.Set<Object>> {
|
||||
long hash = value;
|
||||
java.util.Set<Object> list = new HashSet<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
hash = hasher.applyAsLong(hash);
|
||||
int selector = Math.min(i, valueFuncs.size() - 1);
|
||||
LongFunction<?> func = valueFuncs.get(selector);
|
||||
hash = hasher.applyAsLong(value);
|
||||
list.add(func.apply(hash));
|
||||
}
|
||||
return list;
|
||||
|
||||
@@ -36,6 +36,10 @@ public class SetSized implements LongFunction<java.util.Set<Object>> {
|
||||
this.sizeFunc = VirtDataConversions.adaptFunction(sizeFunc, LongToIntFunction.class);
|
||||
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
|
||||
}
|
||||
public SetSized(int size, Object... funcs) {
|
||||
this.sizeFunc = s -> size;
|
||||
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Set<Object> apply(long value) {
|
||||
|
||||
@@ -37,6 +37,10 @@ public class SetSizedHashed implements LongFunction<java.util.Set<Object>> {
|
||||
this.sizeFunc = VirtDataConversions.adaptFunction(sizeFunc, LongToIntFunction.class);
|
||||
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
|
||||
}
|
||||
public SetSizedHashed(int size, Object... funcs) {
|
||||
this.sizeFunc = s -> size;
|
||||
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Set<Object> apply(long value) {
|
||||
|
||||
@@ -36,6 +36,11 @@ public class SetSizedStepped implements LongFunction<java.util.Set<Object>> {
|
||||
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
|
||||
}
|
||||
|
||||
public SetSizedStepped(int size, Object... funcs) {
|
||||
this.sizeFunc = s -> size;
|
||||
this.valueFuncs = VirtDataConversions.adaptFunctionList(funcs, LongFunction.class, Object.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Set<Object> apply(long value) {
|
||||
int size = sizeFunc.applyAsInt(value);
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Template implements LongFunction<String> {
|
||||
private final static Logger logger = LogManager.getLogger(Template.class);
|
||||
private static final String EXPR_BEGIN = "[[";
|
||||
private static final String EXPR_END = "]]";
|
||||
private final static ThreadLocal<StringBuilder> sb = ThreadLocal.withInitial(StringBuilder::new);
|
||||
// private final static ThreadLocal<StringBuilder> sb = ThreadLocal.withInitial(StringBuilder::new);
|
||||
private final String rawTemplate;
|
||||
private LongUnaryOperator iterOp;
|
||||
private String[] literals;
|
||||
@@ -138,7 +138,7 @@ public class Template implements LongFunction<String> {
|
||||
|
||||
@Override
|
||||
public String apply(long value) {
|
||||
StringBuilder buffer = sb.get();
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.setLength(0);
|
||||
buffer.append(literals[0]);
|
||||
if (literals.length > 1) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_uuid;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
import io.nosqlbench.virtdata.library.basics.shared.from_long.to_long.Hash;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.LongFunction;
|
||||
@@ -10,15 +9,6 @@ import java.util.function.LongFunction;
|
||||
* This function creates a non-random UUID in the type 4 version (Random).
|
||||
* It always puts the same value in the MSB position of the UUID format.
|
||||
* The input value is put in the LSB position.
|
||||
* <pre>
|
||||
* xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
|
||||
* mmmmmmmm-mmmm-Mmmm-Llll-llllllllllll
|
||||
* 4 3
|
||||
* </pre>
|
||||
* As shown above, the LSB position does not have the complication of having
|
||||
* a version identifier (position M) dividing the dynamic range of the data type.
|
||||
* For this reason, only the LSB side is used for this mapper, which allows
|
||||
* an effective range of Long.MAX_VALUE/8, given the loss of 3 digits of precision.
|
||||
*
|
||||
* This function is suitable for deterministic testing of scenarios which depend
|
||||
* on type 4 UUIDs, but without the mandated randomness that makes testing difficult.
|
||||
@@ -29,7 +19,6 @@ import java.util.function.LongFunction;
|
||||
public class ToUUID implements LongFunction<UUID> {
|
||||
|
||||
private final long msbs;
|
||||
private Hash longHash = new Hash();
|
||||
|
||||
public ToUUID() {
|
||||
// Something memorable, but the correct version
|
||||
@@ -37,7 +26,7 @@ public class ToUUID implements LongFunction<UUID> {
|
||||
}
|
||||
|
||||
public ToUUID(long msbs) {
|
||||
this.msbs = (msbs & 0xFFFFFFFFFFFF0FFFL) | 0x0000000000004000L;;
|
||||
this.msbs = (msbs & 0xFFFFFFFFFFFF0FFFL) | 0x0000000000004000L;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.function.Function;
|
||||
* date time, yielding a DateTime object.
|
||||
*
|
||||
* If no arguments are provided, then the format is set to
|
||||
* <pre>yyyy-MM-dd HH:mm:ss.SSSZ</pre>.
|
||||
* "yyyy-MM-dd HH:mm:ss.SSSZ".
|
||||
*
|
||||
* For details on formatting options, see @see <a href="https://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html">DateTimeFormat</a>
|
||||
*/
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.function.Function;
|
||||
* name is fixed or a generated variable name from a provided function.
|
||||
* Note that the input type is not that suitable for constructing names,
|
||||
* so this is more likely to be used in an indirect naming pattern like
|
||||
* <pre>SaveDouble(Load('id'))</pre>
|
||||
* SaveDouble(Load('id'))
|
||||
*/
|
||||
@Categories(Category.state)
|
||||
@ThreadSafeMapper
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.function.UnaryOperator;
|
||||
* name is fixed or a generated variable name from a provided function.
|
||||
* Note that the input type is not that suitable for constructing names,
|
||||
* so this is more likely to be used in an indirect naming pattern like
|
||||
* <pre>SaveDouble(Load('id'))</pre>
|
||||
* SaveFloat(Load('id'))
|
||||
*/
|
||||
@Categories(Category.state)
|
||||
@ThreadSafeMapper
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.function.IntUnaryOperator;
|
||||
* name is fixed or a generated variable name from a provided function.
|
||||
* Note that the input type is not that suitable for constructing names,
|
||||
* so this is more likely to be used in an indirect naming pattern like
|
||||
* <pre>SaveDouble(Load('id'))</pre>
|
||||
* SaveInteger(Load('id'))
|
||||
*/
|
||||
@Categories(Category.state)
|
||||
@ThreadSafeMapper
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.function.LongUnaryOperator;
|
||||
* name is fixed or a generated variable name from a provided function.
|
||||
* Note that the input type is not that suitable for constructing names,
|
||||
* so this is more likely to be used in an indirect naming pattern like
|
||||
* <pre>SaveDouble(Load('id'))</pre>
|
||||
* SaveLong(Load('id'))
|
||||
*/
|
||||
@Categories(Category.state)
|
||||
@ThreadSafeMapper
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.function.Function;
|
||||
* name is fixed or a generated variable name from a provided function.
|
||||
* Note that the input type is not that suitable for constructing names,
|
||||
* so this is more likely to be used in an indirect naming pattern like
|
||||
* <pre>SaveDouble(Load('id'))</pre>
|
||||
* SaveString(Load('id'))
|
||||
*/
|
||||
@Categories(Category.state)
|
||||
@ThreadSafeMapper
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.function.LongToDoubleFunction;
|
||||
* name is fixed or a generated variable name from a provided function.
|
||||
* Note that the input type is not that suitable for constructing names,
|
||||
* so this is more likely to be used in an indirect naming pattern like
|
||||
* <pre>SaveDouble(Load('id'))</pre>
|
||||
* SaveDouble(Load('id'))
|
||||
*/
|
||||
@Categories(Category.state)
|
||||
@ThreadSafeMapper
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.function.LongFunction;
|
||||
* name is fixed or a generated variable name from a provided function.
|
||||
* Note that the input type is not that suitable for constructing names,
|
||||
* so this is more likely to be used in an indirect naming pattern like
|
||||
* <pre>SaveDouble(Load('id'))</pre>
|
||||
* SaveFloat(Load('id'))
|
||||
*/
|
||||
@Categories(Category.state)
|
||||
@ThreadSafeMapper
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.function.LongToIntFunction;
|
||||
* name is fixed or a generated variable name from a provided function.
|
||||
* Note that the input type is not that suitable for constructing names,
|
||||
* so this is more likely to be used in an indirect naming pattern like
|
||||
* <pre>SaveDouble(Load('id'))</pre>
|
||||
* SaveInteger(Load('id'))
|
||||
*/
|
||||
@Categories(Category.state)
|
||||
@ThreadSafeMapper
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.function.LongUnaryOperator;
|
||||
* name is fixed or a generated variable name from a provided function.
|
||||
* Note that the input type is not that suitable for constructing names,
|
||||
* so this is more likely to be used in an indirect naming pattern like
|
||||
* <pre>SaveDouble(Load('id'))</pre>
|
||||
* SaveLong(Load('id'))
|
||||
*/
|
||||
@Categories(Category.state)
|
||||
@ThreadSafeMapper
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.function.LongFunction;
|
||||
* name is fixed or a generated variable name from a provided function.
|
||||
* Note that the input type is not that suitable for constructing names,
|
||||
* so this is more likely to be used in an indirect naming pattern like
|
||||
* <pre>SaveDouble(Load('id'))</pre>
|
||||
* SaveString(Load('id'))
|
||||
*/
|
||||
@Categories(Category.state)
|
||||
@ThreadSafeMapper
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongUnaryOperator;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class MapFunctionsTest {
|
||||
|
||||
@Test
|
||||
public void testMapFunctions() {
|
||||
MapFunctions mf1 = new MapFunctions((LongUnaryOperator) l -> l, (LongUnaryOperator) m -> m);
|
||||
Map<Object, Object> mv1 = mf1.apply(3L);
|
||||
assertThat(mv1).containsAllEntriesOf(Map.of(3L, 3L));
|
||||
|
||||
MapFunctions mf2 = new MapFunctions(
|
||||
(LongFunction<String>) a -> "Ayyy",
|
||||
(LongFunction<String>) b -> "Byyy",
|
||||
(LongFunction<Double>) c -> 123.456d,
|
||||
(LongFunction<Double>) d -> 789.1011d);
|
||||
Map<Object, Object> mv2 = mf2.apply(13L);
|
||||
assertThat(mv2).containsAllEntriesOf(Map.of("Ayyy", "Byyy", 123.456d, 789.1011d));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapSized() {
|
||||
MapSized mf1 = new MapSized(
|
||||
(LongUnaryOperator) s -> s,
|
||||
(LongFunction<Double>) c -> 123.456d,
|
||||
(LongFunction<Double>) d -> (double) d,
|
||||
(LongFunction<String>) String::valueOf,
|
||||
(LongFunction<String>) b -> "Byyy"
|
||||
);
|
||||
Map<Object, Object> mv1 = mf1.apply(5L);
|
||||
assertThat(mv1).containsAllEntriesOf(Map.of(
|
||||
"5", "Byyy",
|
||||
123.456d, 5.0
|
||||
));
|
||||
|
||||
// Notice that the trailing function is used repeatedly, which affects
|
||||
// when duplicate values occur, as compared to the above function.
|
||||
MapSized mf2 = new MapSized(
|
||||
(LongUnaryOperator) s -> s,
|
||||
(LongFunction<String>) String::valueOf,
|
||||
(LongFunction<String>) b -> "Byyy",
|
||||
(LongFunction<Double>) c -> 123.456d,
|
||||
(LongFunction<Double>) d -> (double) d);
|
||||
Map<Object, Object> mv2 = mf2.apply(5L);
|
||||
assertThat(mv2).containsAllEntriesOf(Map.of(
|
||||
"5", "Byyy",
|
||||
123.456d, 5.0
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapSizedStepped() {
|
||||
MapSizedStepped mf2 = new MapSizedStepped(
|
||||
(LongUnaryOperator) s -> s,
|
||||
(LongFunction<Double>) a -> 123.456d,
|
||||
(LongFunction<String>) b -> "Byyy",
|
||||
(LongFunction<String>) String::valueOf,
|
||||
(LongFunction<Double>) d -> (double) d);
|
||||
Map<Object, Object> mv2 = mf2.apply(5L);
|
||||
assertThat(mv2).containsAllEntriesOf(Map.of(
|
||||
123.456, "Byyy",
|
||||
"6", 6.0d,
|
||||
"7", 7.0d,
|
||||
"8", 8.0d,
|
||||
"9", 9.0d
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapStepped() {
|
||||
MapStepped mf2 = new MapStepped(
|
||||
(LongFunction<String>) String::valueOf,
|
||||
(LongFunction<Double>) d -> (double) d,
|
||||
(LongFunction<String>) String::valueOf,
|
||||
(LongFunction<Double>) d -> (double) d
|
||||
);
|
||||
Map<Object, Object> mv2 = mf2.apply(5L);
|
||||
assertThat(mv2).containsAllEntriesOf(Map.of(
|
||||
"5", 5.0d,
|
||||
"6", 6.0d
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapHashed() {
|
||||
MapHashed mf2 = new MapHashed(
|
||||
(LongFunction<String>) String::valueOf,
|
||||
(LongFunction<String>) String::valueOf,
|
||||
(LongFunction<String>) String::valueOf,
|
||||
(LongFunction<String>) String::valueOf
|
||||
);
|
||||
Map<Object, Object> mv2 = mf2.apply(5L);
|
||||
assertThat(mv2).containsAllEntriesOf(Map.of(
|
||||
"4464361019114304900","4464361019114304900",
|
||||
"7193842733564486108","7193842733564486108"
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapSizedHashed() {
|
||||
MapSizedHashed mf2 = new MapSizedHashed(
|
||||
(LongUnaryOperator) s -> s,
|
||||
(LongFunction<String>) String::valueOf,
|
||||
(LongFunction<String>) String::valueOf);
|
||||
Map<Object, Object> mv2 = mf2.apply(5L);
|
||||
assertThat(mv2).containsAllEntriesOf(
|
||||
Map.of(
|
||||
"4464361019114304900", "4464361019114304900"
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public class SetFunctionsTest {
|
||||
public void testSetHashed() {
|
||||
SetHashed f1 = new SetHashed((DoubleUnaryOperator) i -> i, (DoubleToLongFunction) i -> (long) i);
|
||||
Set<Object> set = f1.apply(2L);
|
||||
assertThat(set).contains(8218881827949364224L, 8.2188818279493642E18);
|
||||
assertThat(set).contains(8.2188818279493642E18, 3417914777143645696L);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user