use of io.nosqlbench.virtdata.core.templates.StringBindingsTemplate in project nosqlbench by nosqlbench.
the class StdoutActivity method initOpSequencer.
private OpSequence<StringBindings> initOpSequencer() {
// List<StringBindingsTemplate> stringBindingsTemplates = new ArrayList<>();
SequencerType sequencerType = SequencerType.valueOf(getParams().getOptionalString("seq").orElse("bucket"));
SequencePlanner<StringBindings> sequencer = new SequencePlanner<>(sequencerType);
String tagfilter = activityDef.getParams().getOptionalString("tags").orElse("");
List<OpTemplate> stmts = stmtsDocList.getStmts(tagfilter);
String format = getParams().getOptionalString("format").orElse(null);
if ((stmts.size() == 0 && stmtsDocList.getDocBindings().size() > 0) || format != null) {
if (format != null && format.startsWith("diag")) {
logger.info("Creating diagnostic log for resolver construction...");
BindingsTemplate bt = new BindingsTemplate();
stmtsDocList.getDocBindings().forEach(bt::addFieldBinding);
String diagnostics = bt.getDiagnostics();
getConsoleOut().println(diagnostics);
getConsoleOut().flush();
System.exit(2);
} else {
logger.info("Creating stdout statement template from bindings, since none is otherwise defined.");
Set<String> activeBindingNames = new LinkedHashSet<>();
String bindings = getActivityDef().getParams().getOptionalString("bindings").orElse("doc");
activeBindingNames.addAll(stmtsDocList.getDocBindings().keySet());
Pattern bindingsFilter = Pattern.compile(bindings.equalsIgnoreCase("doc") ? ".*" : bindings);
Set<String> filteredBindingNames = new LinkedHashSet<>();
activeBindingNames.stream().filter(n -> {
if (bindingsFilter.matcher(n).matches()) {
logger.trace("bindings filter kept binding '" + n + "'");
return true;
} else {
logger.trace("bindings filter removed binding '" + n + "'");
return false;
}
}).forEach(filteredBindingNames::add);
activeBindingNames = filteredBindingNames;
String generatedStmt = genStatementTemplate(activeBindingNames);
BindingsTemplate bt = new BindingsTemplate();
stmtsDocList.getDocBindings().forEach(bt::addFieldBinding);
StringBindings sb = new StringBindings(generatedStmt, bt.getMap());
sequencer.addOp(sb, 1L);
}
} else if (stmts.size() > 0) {
for (OpTemplate stmt : stmts) {
ParsedTemplate parsed = stmt.getParsed().orElseThrow();
BindingsTemplate bt = new BindingsTemplate(parsed.getBindPoints());
String statement = parsed.getPositionalStatement(Function.identity());
Objects.requireNonNull(statement);
if (!statement.endsWith("\n") && getParams().getOptionalBoolean("newline").orElse(true)) {
statement = statement + "\n";
}
StringBindingsTemplate sbt = new StringBindingsTemplate(stmt.getStmt().orElseThrow(), bt);
StringBindings sb = sbt.resolve();
sequencer.addOp(sb, stmt.getParamOrDefault("ratio", 1));
}
} else {
logger.error("Unable to create a stdout statement if you have no active statements or bindings configured.");
}
OpSequence<StringBindings> opSequence = sequencer.resolve();
return opSequence;
}
Aggregations