mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
standardize label parsing
This commit is contained in:
parent
5cc0a51fc8
commit
a5c3da2cf9
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.api.config;
|
||||
|
||||
import io.nosqlbench.api.errors.BasicError;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class NBLabelSpec {
|
||||
|
||||
public static NBLabels parseLabels(String labeldata) {
|
||||
NBLabels buf = NBLabels.forKV();
|
||||
|
||||
Map<String, String> parsedLabels = new LinkedHashMap<>();
|
||||
for (String component : labeldata.split("[,; ]+")) {
|
||||
String[] parts = component.split("[:=]+", 2);
|
||||
if (parts.length != 2) {
|
||||
throw new BasicError("Unable to parse labels to set:" + labeldata);
|
||||
}
|
||||
if (parts[1].startsWith("#")) {
|
||||
buf = buf.and(NBLabels.forKV().andInstances(parts[0], parts[1].substring(1)));
|
||||
} else if (parts[1].startsWith("$")) {
|
||||
buf = buf.and(NBLabels.forKV().andTypes(parts[0], parts[1].substring(1)));
|
||||
} else {
|
||||
if (parts[1].matches(".*[0-9]+.*")) {
|
||||
throw new BasicError("You have specified an auxiliary tag which contains numbers in its value (" + component + "), but you have not designated it as a dimension, as in " + parts[0] + ":$" + parts[1] + " or an instance value, as in " + parts[0] + ":#" + parts[1]);
|
||||
}
|
||||
buf = buf.and(NBLabels.forKV().andTypes(parts[0], parts[1]));
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user