mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
create raw query
This commit is contained in:
parent
efe41e37b5
commit
e29aec1d1d
@ -155,6 +155,7 @@ public class CqlActivity extends SimpleActivity implements Activity, ActivityDef
|
||||
|
||||
ParsedStmt parsed = stmtDef.getParsed().orError();
|
||||
boolean prepared = Boolean.valueOf(stmtDef.getParams().getOrDefault("prepared", "true"));
|
||||
boolean raw = Boolean.valueOf(stmtDef.getParams().getOrDefault("raw", "false"));
|
||||
long ratio = Long.valueOf(stmtDef.getParams().getOrDefault("ratio", "1"));
|
||||
|
||||
Optional<ConsistencyLevel> cl = Optional.ofNullable(
|
||||
@ -204,6 +205,17 @@ public class CqlActivity extends SimpleActivity implements Activity, ActivityDef
|
||||
.getOrDefault("binder", CqlBinderTypes.DEFAULT.toString()));
|
||||
|
||||
template = new ReadyCQLStatementTemplate(binderType, getSession(), prepare, ratio, parsed.getName());
|
||||
} else if (raw) {
|
||||
cl.ifPresent((conlvl) -> {
|
||||
psummary.append(" consistency_level=>").append(conlvl);
|
||||
});
|
||||
serial_cl.ifPresent((scl) -> {
|
||||
psummary.append(" serial_consistency_level=>").append(scl);
|
||||
});
|
||||
idempotent.ifPresent((i) -> {
|
||||
psummary.append(" idempotent=>").append(i);
|
||||
});
|
||||
template = new ReadyCQLStatementTemplate(getSession(), stmtForDriver, ratio, parsed.getName(), cl, serial_cl, idempotent);
|
||||
} else {
|
||||
SimpleStatement simpleStatement = new SimpleStatement(stmtForDriver);
|
||||
cl.ifPresent((conlvl) -> {
|
||||
|
@ -0,0 +1,45 @@
|
||||
package io.nosqlbench.activitytype.cql.statements.binders;
|
||||
|
||||
import com.datastax.driver.core.ConsistencyLevel;
|
||||
import com.datastax.driver.core.SimpleStatement;
|
||||
import com.datastax.driver.core.Statement;
|
||||
import io.nosqlbench.engine.api.activityconfig.ParsedStmt;
|
||||
import io.nosqlbench.virtdata.core.bindings.ValuesArrayBinder;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class RawValueBinder
|
||||
implements ValuesArrayBinder<String[], Statement> {
|
||||
|
||||
private Optional<ConsistencyLevel> cl;
|
||||
private Optional<ConsistencyLevel> serial_cl;
|
||||
private Optional<Boolean> idempotent;
|
||||
|
||||
public RawValueBinder(Optional<ConsistencyLevel> cl, Optional<ConsistencyLevel> serial_cl, Optional<Boolean> idempotent) {
|
||||
this.cl = cl;
|
||||
this.serial_cl = serial_cl;
|
||||
this.idempotent = idempotent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement bindValues(String[] context, Object[] values) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(context[0]);
|
||||
for(int i=1; i<context.length; i++){
|
||||
sb.append(values[i-1]);
|
||||
sb.append(context[i]);
|
||||
}
|
||||
SimpleStatement simpleStatement = new SimpleStatement(sb.toString());
|
||||
cl.ifPresent((conlvl) -> {
|
||||
simpleStatement.setConsistencyLevel(conlvl);
|
||||
});
|
||||
serial_cl.ifPresent((scl) -> {
|
||||
simpleStatement.setSerialConsistencyLevel(scl);
|
||||
});
|
||||
idempotent.ifPresent((i) -> {
|
||||
simpleStatement.setIdempotent(i);
|
||||
});
|
||||
return simpleStatement;
|
||||
}
|
||||
}
|
@ -2,15 +2,14 @@ package io.nosqlbench.activitytype.cql.statements.core;
|
||||
|
||||
import com.codahale.metrics.Histogram;
|
||||
import com.codahale.metrics.Timer;
|
||||
import com.datastax.driver.core.PreparedStatement;
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.SimpleStatement;
|
||||
import com.datastax.driver.core.Statement;
|
||||
import com.datastax.driver.core.*;
|
||||
import io.nosqlbench.activitytype.cql.api.ResultSetCycleOperator;
|
||||
import io.nosqlbench.activitytype.cql.api.RowCycleOperator;
|
||||
import io.nosqlbench.activitytype.cql.core.CqlActivity;
|
||||
import io.nosqlbench.activitytype.cql.statements.binders.CqlBinderTypes;
|
||||
import io.nosqlbench.activitytype.cql.statements.binders.RawValueBinder;
|
||||
import io.nosqlbench.activitytype.cql.statements.binders.SimpleStatementValuesBinder;
|
||||
import io.nosqlbench.engine.api.activityconfig.ParsedStmt;
|
||||
import io.nosqlbench.engine.api.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.virtdata.core.bindings.BindingsTemplate;
|
||||
import io.nosqlbench.virtdata.core.bindings.ContextualBindingsArrayTemplate;
|
||||
@ -19,6 +18,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ReadyCQLStatementTemplate {
|
||||
|
||||
@ -61,6 +61,17 @@ public class ReadyCQLStatementTemplate {
|
||||
this.ratio = ratio;
|
||||
}
|
||||
|
||||
public ReadyCQLStatementTemplate(Session session, String stmtForDriver, long ratio, String name, Optional<ConsistencyLevel> cl, Optional<ConsistencyLevel> serial_cl, Optional<Boolean> idempotent) {
|
||||
this.session = session;
|
||||
this.name = name;
|
||||
template = new ContextualBindingsArrayTemplate<>(
|
||||
stmtForDriver.split("\\?"),
|
||||
new BindingsTemplate(),
|
||||
new RawValueBinder(cl, serial_cl, idempotent)
|
||||
);
|
||||
this.ratio = ratio;
|
||||
}
|
||||
|
||||
public ReadyCQLStatement resolve() {
|
||||
return new ReadyCQLStatement(template.resolveBindings(), ratio, name)
|
||||
.withMetrics(this.successTimer, this.errorTimer, this.rowsFetchedHisto)
|
||||
|
Loading…
Reference in New Issue
Block a user