Save global vars + Expr types

This commit is contained in:
phact 2020-03-03 23:57:43 -05:00
parent 4599b5da73
commit c795cfdc56
9 changed files with 131 additions and 1 deletions

View File

@ -18,6 +18,9 @@ public class SaveGlobalVars implements RowCycleOperator {
for (ColumnDefinitions.Definition definition : cdlist) {
String name = definition.getName();
Object object = row.getObject(name);
if (object == null){
object = "";
}
gl_vars.put(name,object);
}
return 0;

View File

@ -18,7 +18,8 @@ public class GlobalVarsScriptingPluginData implements ScriptingPluginInfo<Concur
@Override
public ConcurrentHashMap<String, Object> getExtensionObject(Logger logger, MetricRegistry metricRegistry, ScriptContext scriptContext) {
return SharedState.gl_ObjectMap;
ConcurrentHashMap<String, Object> map = SharedState.gl_ObjectMap;
return map;
}
@Override

View File

@ -0,0 +1,20 @@
package io.nosqlbench.engine.extensions.globalvars;
import io.nosqlbench.virtdata.library.basics.core.threadstate.SharedState;
import java.util.concurrent.ConcurrentHashMap;
public class GlobalVarsWrapper {
ConcurrentHashMap<String, Object> map = SharedState.gl_ObjectMap;
String test = "puppies";
public ConcurrentHashMap<String, Object> getMap(){
this.map.get("");
return this.map;
}
public String getTest(){
return this.test;
}
}

View File

@ -2,9 +2,12 @@
package io.nosqlbench.virtdata.lang.generated;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class VirtDataLexer extends Lexer {

View File

@ -3,8 +3,11 @@ package io.nosqlbench.virtdata.lang.generated;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.*;
import org.antlr.v4.runtime.tree.*;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class VirtDataParser extends Parser {

View File

@ -7,7 +7,11 @@ import org.mvel2.MVEL;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.DoubleUnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ThreadSafeMapper
public class Expr implements DoubleUnaryOperator {
@ -22,7 +26,14 @@ public class Expr implements DoubleUnaryOperator {
@Override
public double applyAsDouble(double operand) {
ConcurrentHashMap<String, Object> gl_map = SharedState.gl_ObjectMap;
HashMap<String, Object> map = SharedState.tl_ObjectMap.get();
// merge gl into tl, for duplicates use the value from tl
for (Map.Entry<String, Object> stringObjectEntry : gl_map.entrySet()) {
map.merge(stringObjectEntry.getKey(), stringObjectEntry.getValue(), (entry1, entry2) -> entry1);
}
map.put("cycle",operand);
double result = MVEL.executeExpression(compiledExpr, map, double.class);
return result;

View File

@ -7,6 +7,8 @@ import org.mvel2.MVEL;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.LongUnaryOperator;
@ThreadSafeMapper
@ -22,7 +24,14 @@ public class Expr implements LongUnaryOperator {
@Override
public long applyAsLong(long operand) {
ConcurrentHashMap<String, Object> gl_map = SharedState.gl_ObjectMap;
HashMap<String, Object> map = SharedState.tl_ObjectMap.get();
// merge gl into tl, for duplicates use the value from tl
for (Map.Entry<String, Object> stringObjectEntry : gl_map.entrySet()) {
map.merge(stringObjectEntry.getKey(), stringObjectEntry.getValue(), (entry1, entry2) -> entry1);
}
map.put("cycle",operand);
long result = MVEL.executeExpression(compiledExpr, map, long.class);
return result;

View File

@ -0,0 +1,40 @@
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_string;
import io.nosqlbench.virtdata.annotations.ThreadSafeMapper;
import io.nosqlbench.virtdata.library.basics.core.MVELExpr;
import io.nosqlbench.virtdata.library.basics.core.threadstate.SharedState;
import org.mvel2.MVEL;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.LongFunction;
import java.util.function.LongUnaryOperator;
@ThreadSafeMapper
public class Expr implements LongFunction<String> {
private final String expr;
private final Serializable compiledExpr;
public Expr(String expr) {
this.expr = expr;
this.compiledExpr = MVELExpr.compile(long.class, "cycle", expr);
}
@Override
public String apply(long operand) {
ConcurrentHashMap<String, Object> gl_map = SharedState.gl_ObjectMap;
HashMap<String, Object> map = SharedState.tl_ObjectMap.get();
// merge gl into tl, for duplicates use the value from tl
for (Map.Entry<String, Object> stringObjectEntry : gl_map.entrySet()) {
map.merge(stringObjectEntry.getKey(), stringObjectEntry.getValue(), (entry1, entry2) -> entry1);
}
map.put("cycle",operand);
String result = MVEL.executeExpression(compiledExpr, map, String.class);
return result;
}
}

View File

@ -0,0 +1,40 @@
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_uuid;
import io.nosqlbench.virtdata.annotations.ThreadSafeMapper;
import io.nosqlbench.virtdata.library.basics.core.MVELExpr;
import io.nosqlbench.virtdata.library.basics.core.threadstate.SharedState;
import org.mvel2.MVEL;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.LongFunction;
@ThreadSafeMapper
public class Expr implements LongFunction<UUID> {
private final String expr;
private final Serializable compiledExpr;
public Expr(String expr) {
this.expr = expr;
this.compiledExpr = MVELExpr.compile(long.class, "cycle", expr);
}
@Override
public UUID apply(long operand) {
ConcurrentHashMap<String, Object> gl_map = SharedState.gl_ObjectMap;
HashMap<String, Object> map = SharedState.tl_ObjectMap.get();
// merge gl into tl, for duplicates use the value from tl
for (Map.Entry<String, Object> stringObjectEntry : gl_map.entrySet()) {
map.merge(stringObjectEntry.getKey(), stringObjectEntry.getValue(), (entry1, entry2) -> entry1);
}
map.put("cycle",operand);
UUID result = MVEL.executeExpression(compiledExpr, map, UUID.class);
return result;
}
}