mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
trim spaces in tag specs, disallows spaces as delimiter between
This commit is contained in:
parent
ebc53ca3a9
commit
57762f3588
@ -88,23 +88,31 @@ public class TagFilter {
|
|||||||
*/
|
*/
|
||||||
public TagFilter(String filterSpec) {
|
public TagFilter(String filterSpec) {
|
||||||
if ((filterSpec != null) && (!filterSpec.isEmpty())) {
|
if ((filterSpec != null) && (!filterSpec.isEmpty())) {
|
||||||
String[] keyvalues = filterSpec.split("[, ] *");
|
filterSpec=unquote(filterSpec);
|
||||||
|
|
||||||
|
String[] keyvalues = filterSpec.split("[,] *");
|
||||||
for (String assignment : keyvalues) {
|
for (String assignment : keyvalues) {
|
||||||
String[] keyvalue = assignment.split("[:=]", 2);
|
String[] keyvalue = assignment.split("[:=]", 2);
|
||||||
String key = keyvalue[0];
|
String key = keyvalue[0];
|
||||||
String value = keyvalue.length > 1 ? keyvalue[1] : null;
|
String value = keyvalue.length > 1 ? keyvalue[1] : null;
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
if ((value.indexOf("\'") == 0) && ((value.indexOf("\'", 1) == (value.length() - 1)))) {
|
value = unquote(value);
|
||||||
value = value.substring(1, value.length() - 1);
|
value = value.trim();
|
||||||
} else {
|
|
||||||
value = value.trim();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
filter.put(key, value);
|
filter.put(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String unquote(String filterSpec) {
|
||||||
|
for (String s : new String[]{"'","\""}) {
|
||||||
|
if (filterSpec.indexOf(s)==0 && filterSpec.indexOf(s,1)==filterSpec.length()-1) {
|
||||||
|
filterSpec=filterSpec.substring(1,filterSpec.length()-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filterSpec;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Although this method could early-exit for certain conditions, the full tag matching logic
|
* Although this method could early-exit for certain conditions, the full tag matching logic
|
||||||
* is allowed to complete in order to present more complete diagnostic information back
|
* is allowed to complete in order to present more complete diagnostic information back
|
||||||
|
@ -36,7 +36,7 @@ public class TagFilterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyTagFilterDoesMatch() {
|
public void testEmptyTagFilterDoesMatch() {
|
||||||
Map<String,String> itemtags = new HashMap<String,String>() {{
|
Map<String,String> itemtags = new HashMap<>() {{
|
||||||
put("a","tag");
|
put("a","tag");
|
||||||
}};
|
}};
|
||||||
TagFilter tf = new TagFilter("");
|
TagFilter tf = new TagFilter("");
|
||||||
@ -45,7 +45,7 @@ public class TagFilterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSomeFilterTagsNoItemTagsDoesNotMatch() {
|
public void testSomeFilterTagsNoItemTagsDoesNotMatch() {
|
||||||
Map<String,String> itemtags = new HashMap<String,String>() {{
|
Map<String,String> itemtags = new HashMap<>() {{
|
||||||
}};
|
}};
|
||||||
TagFilter tf = new TagFilter("tag=foo");
|
TagFilter tf = new TagFilter("tag=foo");
|
||||||
assertThat(tf.matches(itemtags).matched()).isFalse();
|
assertThat(tf.matches(itemtags).matched()).isFalse();
|
||||||
@ -54,7 +54,7 @@ public class TagFilterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyTagFilterValueDoesMatch() {
|
public void testEmptyTagFilterValueDoesMatch() {
|
||||||
Map<String,String> itemtags = new HashMap<String,String>() {{
|
Map<String,String> itemtags = new HashMap<>() {{
|
||||||
put("one","two");
|
put("one","two");
|
||||||
}};
|
}};
|
||||||
TagFilter tf = new TagFilter("");
|
TagFilter tf = new TagFilter("");
|
||||||
@ -64,14 +64,14 @@ public class TagFilterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMatchingTagKeyValueDoesMatch() {
|
public void testMatchingTagKeyValueDoesMatch() {
|
||||||
Map<String,String> itemtags = new HashMap<String,String>() {{
|
Map<String,String> itemtags = new HashMap<>() {{
|
||||||
put("one","two");
|
put("one","two");
|
||||||
}};
|
}};
|
||||||
TagFilter tf = new TagFilter("one");
|
TagFilter tf = new TagFilter("one");
|
||||||
TagFilter.Result result = tf.matches(itemtags);
|
TagFilter.Result result = tf.matches(itemtags);
|
||||||
assertThat(result.matched()).isTrue();
|
assertThat(result.matched()).isTrue();
|
||||||
|
|
||||||
Map<String,String> itemtags2 = new HashMap<String,String>() {{
|
Map<String,String> itemtags2 = new HashMap<>() {{
|
||||||
put("one",null);
|
put("one",null);
|
||||||
}};
|
}};
|
||||||
assertThat(tf.matches(itemtags2).matched()).isTrue();
|
assertThat(tf.matches(itemtags2).matched()).isTrue();
|
||||||
@ -80,7 +80,7 @@ public class TagFilterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMatchingKeyMismatchingValueDoesNotMatch() {
|
public void testMatchingKeyMismatchingValueDoesNotMatch() {
|
||||||
Map<String,String> itemtags = new HashMap<String,String>() {{
|
Map<String,String> itemtags = new HashMap<>() {{
|
||||||
put("one","four");
|
put("one","four");
|
||||||
}};
|
}};
|
||||||
TagFilter tf = new TagFilter("one:two");
|
TagFilter tf = new TagFilter("one:two");
|
||||||
@ -90,7 +90,7 @@ public class TagFilterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMatchingKeyAndValueDoesMatch() {
|
public void testMatchingKeyAndValueDoesMatch() {
|
||||||
Map<String,String> itemtags = new HashMap<String,String>() {{
|
Map<String,String> itemtags = new HashMap<>() {{
|
||||||
put("one","four");
|
put("one","four");
|
||||||
}};
|
}};
|
||||||
TagFilter tf = new TagFilter("one:four");
|
TagFilter tf = new TagFilter("one:four");
|
||||||
@ -99,7 +99,7 @@ public class TagFilterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMatchingKeyAndValueRegexDoesMatch() {
|
public void testMatchingKeyAndValueRegexDoesMatch() {
|
||||||
Map<String,String> itemtags = new HashMap<String,String>() {{
|
Map<String,String> itemtags = new HashMap<>() {{
|
||||||
put("one","four-five-six");
|
put("one","four-five-six");
|
||||||
}};
|
}};
|
||||||
TagFilter tfLeft = new TagFilter("one:'four-.*'");
|
TagFilter tfLeft = new TagFilter("one:'four-.*'");
|
||||||
@ -114,7 +114,7 @@ public class TagFilterTest {
|
|||||||
Tagged tagged = new Tagged() {
|
Tagged tagged = new Tagged() {
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> getTags() {
|
public Map<String, String> getTags() {
|
||||||
return new HashMap<String,String>() {{
|
return new HashMap<>() {{
|
||||||
put("one","four-five-six");
|
put("one","four-five-six");
|
||||||
put("two","three-seven-nine");
|
put("two","three-seven-nine");
|
||||||
put("five",null);
|
put("five",null);
|
||||||
@ -136,7 +136,7 @@ public class TagFilterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRawSubstringDoesNotMatchRegex() {
|
public void testRawSubstringDoesNotMatchRegex() {
|
||||||
Map<String,String> itemtags = new HashMap<String,String>() {{
|
Map<String,String> itemtags = new HashMap<>() {{
|
||||||
put("one","four-five-six");
|
put("one","four-five-six");
|
||||||
}};
|
}};
|
||||||
TagFilter tf = new TagFilter("one:'five'");
|
TagFilter tf = new TagFilter("one:'five'");
|
||||||
@ -145,11 +145,22 @@ public class TagFilterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAlternation() {
|
public void testAlternation() {
|
||||||
Map<String,String> itemtags = new HashMap<String,String>() {{
|
Map<String,String> itemtags = new HashMap<>() {{
|
||||||
put("one","four-five-six");
|
put("one","four-five-six");
|
||||||
}};
|
}};
|
||||||
TagFilter tf = new TagFilter("one:'four.*|seven'");
|
TagFilter tf = new TagFilter("one:'four.*|seven'");
|
||||||
assertThat(tf.matches(itemtags).matched()).isTrue();
|
assertThat(tf.matches(itemtags).matched()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLeadingSpaceTrimmedInQuotedTag() {
|
||||||
|
|
||||||
|
Map<String,String> itemtags = new HashMap<>() {{
|
||||||
|
put("phase","main");
|
||||||
|
}};
|
||||||
|
|
||||||
|
TagFilter tf = new TagFilter("\"phase: main\"");
|
||||||
|
assertThat(tf.matches(itemtags).matched()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user