expose capture points on ParsedOp

This commit is contained in:
Jonathan Shook
2023-02-22 15:59:15 -06:00
parent add442066c
commit fe094d0011
4 changed files with 26 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 nosqlbench
* Copyright (c) 2022-2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
package io.nosqlbench.engine.api.templating;
import io.nosqlbench.virtdata.core.templates.CapturePoint;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -25,6 +27,7 @@ public class ParsedTemplateList implements LongFunction<List<?>> {
private final List<Object> protolist = new ArrayList<>();
private final int[] dynamic_idx;
private final LongFunction<?>[] functions;
private final List<CapturePoint> captures = new ArrayList<>();
public ParsedTemplateList(List<Object> sublist, Map<String, String> bindings, List<Map<String, Object>> cfgsources) {
@@ -34,6 +37,7 @@ public class ParsedTemplateList implements LongFunction<List<?>> {
for (int i = 0; i < sublist.size(); i++) {
Object item = sublist.get(i);
Templatizer.Result result = Templatizer.make(bindings, item, null, cfgsources);
this.captures.addAll(result.getCaptures());
switch (result.getType()) {
case literal:
protolist.add(result.getValue());
@@ -64,4 +68,8 @@ public class ParsedTemplateList implements LongFunction<List<?>> {
public boolean isStatic() {
return dynamic_idx.length==0;
}
public List<CapturePoint> getCaptures() {
return this.captures;
}
}

View File

@@ -76,7 +76,7 @@ public class ParsedTemplateMap implements LongFunction<Map<String, ?>>, StaticFi
* representation of a result. If the values are defined, then each one represents the name
* that the found value should be saved as instead of the original name.
*/
private final List<List<CapturePoint>> captures = new ArrayList<>();
private final List<CapturePoint> captures = new ArrayList<>();
private final int mapsize;
/**
@@ -103,9 +103,9 @@ public class ParsedTemplateMap implements LongFunction<Map<String, ?>>, StaticFi
this.specmap = map;
this.bindings = bindings;
map.forEach((k, v) -> {
if (v instanceof CharSequence) {
ParsedStringTemplate pt = ParsedStringTemplate.of(((CharSequence) v).toString(), bindings);
this.captures.add(pt.getCaptures());
if (v instanceof CharSequence charvalue) {
ParsedTemplateString pt = ParsedTemplateString.of(charvalue.toString(), bindings);
this.captures.addAll(pt.getCaptures());
switch (pt.getType()) {
case literal:
statics.put(k, charvalue.toString());
@@ -134,6 +134,7 @@ public class ParsedTemplateMap implements LongFunction<Map<String, ?>>, StaticFi
});
Map<String, Object> submap = (Map<String, Object>) v;
ParsedTemplateMap subtpl = new ParsedTemplateMap(getName(),submap, bindings, cfgsources);
this.captures.addAll(subtpl.getCaptures());
if (subtpl.isStatic()) {
statics.put(k, submap);
protomap.put(k, submap);
@@ -144,6 +145,7 @@ public class ParsedTemplateMap implements LongFunction<Map<String, ?>>, StaticFi
} else if (v instanceof List listvalue) {
List<Object> sublist = listvalue;
ParsedTemplateList subtpl = new ParsedTemplateList(sublist, bindings, cfgsources);
this.captures.addAll(subtpl.getCaptures());
if (subtpl.isStatic()) {
statics.put(k, sublist);
protomap.put(k, sublist);
@@ -162,6 +164,10 @@ public class ParsedTemplateMap implements LongFunction<Map<String, ?>>, StaticFi
}
public List<CapturePoint> getCaptures() {
return this.captures;
}
/**
* @return true if any field of this template map is dynamic
*/

View File

@@ -111,7 +111,7 @@ public class ParsedStringTemplate {
private final static Logger logger = LogManager.getLogger(ParsedStringTemplate.class);
private final String rawtemplate;
private final List<CapturePoint> captures;
private final List<CapturePoint> captures = new ArrayList<>();
private final List<BindPoint> bindpoints;
public static ParsedStringTemplate of(String rawtemplate, Map<String, String> bindings) {
@@ -142,7 +142,7 @@ public class ParsedStringTemplate {
CapturePointParser capturePointParser = new CapturePointParser();
CapturePointParser.Result captureData = capturePointParser.apply(rawtemplate);
this.captures = captureData.getCaptures();
this.captures.addAll(captureData.getCaptures());
BindPointParser bindPointParser = new BindPointParser();
BindPointParser.Result bindPointsResult = bindPointParser.apply(captureData.getRawTemplate(), availableBindings);