mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
support anonymous bindings in anchors
This commit is contained in:
parent
5415f0b138
commit
c87778cf32
@ -5,11 +5,28 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class ParsedCommandTest {
|
public class ParsedCommandTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParsedCommand() {
|
public void testParsedCommand() {
|
||||||
ParsedCommand pc = new ParsedCommand(new OpData().applyFields(Map.of("op", Map.of("stmt", "test"))));
|
ParsedCommand pc = new ParsedCommand(
|
||||||
|
new OpData().applyFields(
|
||||||
|
Map.of(
|
||||||
|
"op", Map.of(
|
||||||
|
"stmt", "test",
|
||||||
|
"dyna1", "{dyna1}",
|
||||||
|
"dyna2", "{{NumberNameToString()}}"
|
||||||
|
),
|
||||||
|
"bindings", Map.of(
|
||||||
|
"dyna1", "NumberNameToString()"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
Map<String, Object> m1 = pc.apply(0);
|
||||||
|
assertThat(m1).containsEntry("stmt", "test");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,10 @@ import java.util.stream.StreamSupport;
|
|||||||
public class ParsedTemplate {
|
public class ParsedTemplate {
|
||||||
|
|
||||||
private final static Logger logger = LogManager.getLogger(ParsedTemplate.class);
|
private final static Logger logger = LogManager.getLogger(ParsedTemplate.class);
|
||||||
private final List<CapturePoint> captures;
|
|
||||||
private final String rawtemplate;
|
private final String rawtemplate;
|
||||||
|
private final List<CapturePoint> captures;
|
||||||
|
private final List<BindPoint> bindpoints;
|
||||||
|
|
||||||
public static ParsedTemplate of(String rawtemplate, Map<String,String> bindings) {
|
public static ParsedTemplate of(String rawtemplate, Map<String,String> bindings) {
|
||||||
return new ParsedTemplate(rawtemplate,bindings);
|
return new ParsedTemplate(rawtemplate,bindings);
|
||||||
@ -142,8 +144,9 @@ public class ParsedTemplate {
|
|||||||
|
|
||||||
CapturePointParser.Result captureData = capturePointParser.apply(rawtemplate);
|
CapturePointParser.Result captureData = capturePointParser.apply(rawtemplate);
|
||||||
this.captures = captureData.getCaptures();
|
this.captures = captureData.getCaptures();
|
||||||
List<String> spanData = bindPointParser.apply(captureData.getRawTemplate());
|
BindPointParser.Result bindPointsResult = bindPointParser.apply(captureData.getRawTemplate(),availableBindings);
|
||||||
this.spans = spanData.toArray(new String[0]);
|
this.spans = bindPointsResult.getSpans().toArray(new String[0]);
|
||||||
|
this.bindpoints = bindPointsResult.getBindpoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
@ -225,25 +228,16 @@ public class ParsedTemplate {
|
|||||||
* such as an anchor which has no provided binding.
|
* such as an anchor which has no provided binding.
|
||||||
*/
|
*/
|
||||||
public List<BindPoint> getBindPoints() {
|
public List<BindPoint> getBindPoints() {
|
||||||
List<BindPoint> bindpoints = new ArrayList<>();
|
bindpoints.forEach(b -> {
|
||||||
for (int i = 1; i < spans.length; i += 2) {
|
if (b.getBindspec()==null || b.getBindspec().isEmpty()) {
|
||||||
if (!bindings.containsKey(spans[i])) {
|
throw new RuntimeException("No binding spec was provided for bind point '" + b + "'");
|
||||||
throw new InvalidParameterException("Binding named '" + spans[i] + "' is not contained in the bindings map.");
|
|
||||||
}
|
}
|
||||||
bindpoints.add(new BindPoint(spans[i], bindings.get(spans[i])));
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return bindpoints;
|
return bindpoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<BindPoint> getUncheckedBindPoints() {
|
private List<BindPoint> getUncheckedBindPoints() {
|
||||||
List<BindPoint> bindpoints = new ArrayList<>();
|
|
||||||
for (int i = 1; i < spans.length; i += 2) {
|
|
||||||
bindpoints.add(new BindPoint(spans[i], bindings.getOrDefault(spans[i], null)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return bindpoints;
|
return bindpoints;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -282,7 +276,7 @@ public class ParsedTemplate {
|
|||||||
*/
|
*/
|
||||||
public Optional<BindPoint> asBinding() {
|
public Optional<BindPoint> asBinding() {
|
||||||
if (spans.length == 3 && spans[0].isEmpty() && spans[2].isEmpty()) {
|
if (spans.length == 3 && spans[0].isEmpty() && spans[2].isEmpty()) {
|
||||||
return Optional.of(new BindPoint(spans[1], bindings.getOrDefault(spans[1], null)));
|
return Optional.of(bindpoints.get(0));
|
||||||
} else {
|
} else {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user