mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
commit
2a04b9057b
@ -155,6 +155,7 @@ public class CqlActivity extends SimpleActivity implements Activity, ActivityDef
|
|||||||
|
|
||||||
ParsedStmt parsed = stmtDef.getParsed().orError();
|
ParsedStmt parsed = stmtDef.getParsed().orError();
|
||||||
boolean prepared = Boolean.valueOf(stmtDef.getParams().getOrDefault("prepared", "true"));
|
boolean prepared = Boolean.valueOf(stmtDef.getParams().getOrDefault("prepared", "true"));
|
||||||
|
boolean parametrized = Boolean.valueOf(stmtDef.getParams().getOrDefault("parametrized", "false"));
|
||||||
long ratio = Long.valueOf(stmtDef.getParams().getOrDefault("ratio", "1"));
|
long ratio = Long.valueOf(stmtDef.getParams().getOrDefault("ratio", "1"));
|
||||||
|
|
||||||
Optional<ConsistencyLevel> cl = Optional.ofNullable(
|
Optional<ConsistencyLevel> cl = Optional.ofNullable(
|
||||||
@ -218,7 +219,7 @@ public class CqlActivity extends SimpleActivity implements Activity, ActivityDef
|
|||||||
psummary.append(" idempotent=>").append(i);
|
psummary.append(" idempotent=>").append(i);
|
||||||
simpleStatement.setIdempotent(i);
|
simpleStatement.setIdempotent(i);
|
||||||
});
|
});
|
||||||
template = new ReadyCQLStatementTemplate(getSession(), simpleStatement, ratio, parsed.getName());
|
template = new ReadyCQLStatementTemplate(getSession(), simpleStatement, ratio, parsed.getName(), parametrized);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional.ofNullable(stmtDef.getParams().getOrDefault("save", null))
|
Optional.ofNullable(stmtDef.getParams().getOrDefault("save", null))
|
||||||
|
@ -1,19 +1,55 @@
|
|||||||
package io.nosqlbench.activitytype.cql.statements.binders;
|
package io.nosqlbench.activitytype.cql.statements.binders;
|
||||||
|
|
||||||
|
import com.datastax.driver.core.ConsistencyLevel;
|
||||||
import com.datastax.driver.core.SimpleStatement;
|
import com.datastax.driver.core.SimpleStatement;
|
||||||
import com.datastax.driver.core.Statement;
|
import com.datastax.driver.core.Statement;
|
||||||
import io.nosqlbench.virtdata.core.bindings.ValuesArrayBinder;
|
import io.nosqlbench.virtdata.core.bindings.ValuesArrayBinder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This binder is not meant to be used with anything but DDL or statements
|
* This binder is not meant to be used with anything but DDL or statements
|
||||||
* which should not be trying to parameterize values in general. If this changes,
|
* which should not be trying to parameterize values in general.
|
||||||
* support will be added for parameterized values here.
|
* Parametrized values are still possible through parametrized constructor parameter.
|
||||||
|
* This binder should be avoided in favor of binders returning PreparedStatement
|
||||||
*/
|
*/
|
||||||
public class SimpleStatementValuesBinder
|
public class SimpleStatementValuesBinder
|
||||||
implements ValuesArrayBinder<SimpleStatement, Statement> {
|
implements ValuesArrayBinder<SimpleStatement, Statement> {
|
||||||
|
|
||||||
|
private final boolean parametrized;
|
||||||
|
|
||||||
|
public SimpleStatementValuesBinder(boolean parametrized){
|
||||||
|
this.parametrized = parametrized;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Statement bindValues(SimpleStatement context, Object[] values) {
|
public Statement bindValues(SimpleStatement context, Object[] values) {
|
||||||
return new SimpleStatement(context.getQueryString(), values);
|
String query = context.getQueryString();
|
||||||
|
if(parametrized) {
|
||||||
|
String[] splits = query.split("\\?");
|
||||||
|
assert splits.length == values.length+1;
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(splits[0]);
|
||||||
|
for(int i = 1; i < splits.length; i++) {
|
||||||
|
sb.append(values[i - 1]);
|
||||||
|
sb.append(splits[i]);
|
||||||
|
}
|
||||||
|
query = sb.toString();
|
||||||
|
System.out.println(query);
|
||||||
|
|
||||||
|
}
|
||||||
|
SimpleStatement simpleStatement = new SimpleStatement(query);
|
||||||
|
ConsistencyLevel cl = context.getConsistencyLevel();
|
||||||
|
if(cl != null){
|
||||||
|
simpleStatement.setConsistencyLevel(context.getConsistencyLevel());
|
||||||
|
}
|
||||||
|
//Does it really makes senses?
|
||||||
|
ConsistencyLevel serial_cl = context.getSerialConsistencyLevel();
|
||||||
|
if(serial_cl != null){
|
||||||
|
simpleStatement.setSerialConsistencyLevel(context.getSerialConsistencyLevel());
|
||||||
|
}
|
||||||
|
Boolean idempotent = context.isIdempotent();
|
||||||
|
if(idempotent != null){
|
||||||
|
simpleStatement.setIdempotent(idempotent);
|
||||||
|
}
|
||||||
|
return simpleStatement;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,13 +50,13 @@ public class ReadyCQLStatementTemplate {
|
|||||||
this.ratio = ratio;
|
this.ratio = ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReadyCQLStatementTemplate(Session session, SimpleStatement simpleStatement, long ratio, String name) {
|
public ReadyCQLStatementTemplate(Session session, SimpleStatement simpleStatement, long ratio, String name, boolean parametrized) {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
template = new ContextualBindingsArrayTemplate<>(
|
template = new ContextualBindingsArrayTemplate<>(
|
||||||
simpleStatement,
|
simpleStatement,
|
||||||
new BindingsTemplate(),
|
new BindingsTemplate(),
|
||||||
new SimpleStatementValuesBinder()
|
new SimpleStatementValuesBinder(parametrized)
|
||||||
);
|
);
|
||||||
this.ratio = ratio;
|
this.ratio = ratio;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user