This is an automated email from the ASF dual-hosted git repository.
kturner pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/2.1 by this push:
new 621ad51be1 adds javadoc and tests to GrepIterator (#4775)
621ad51be1 is described below
commit 621ad51be1c9b3cf65db91c3b21d2554da1404a0
Author: Keith Turner <[email protected]>
AuthorDate: Tue Aug 6 18:22:11 2024 -0400
adds javadoc and tests to GrepIterator (#4775)
---
.../accumulo/core/iterators/user/GrepIterator.java | 25 ++++
.../core/iterators/user/GrepIteratorTest.java | 141 ++++++++++++++++++++-
2 files changed, 165 insertions(+), 1 deletion(-)
diff --git
a/core/src/main/java/org/apache/accumulo/core/iterators/user/GrepIterator.java
b/core/src/main/java/org/apache/accumulo/core/iterators/user/GrepIterator.java
index ed327f70d1..e526851c65 100644
---
a/core/src/main/java/org/apache/accumulo/core/iterators/user/GrepIterator.java
+++
b/core/src/main/java/org/apache/accumulo/core/iterators/user/GrepIterator.java
@@ -148,22 +148,47 @@ public class GrepIterator extends Filter {
cfg.addOption(TERM_OPT, term);
}
+ /**
+ * Enable or disable matching on the row field of the key. Defaults to
enable.
+ *
+ * @since 2.1.3
+ */
public static void matchRow(IteratorSetting cfg, boolean match) {
cfg.addOption(MATCH_ROW_OPT, Boolean.toString(match));
}
+ /**
+ * Enable or disable matching on the family field of the key. Defaults to
enable.
+ *
+ * @since 2.1.3
+ */
public static void matchColumnFamily(IteratorSetting cfg, boolean match) {
cfg.addOption(MATCH_COLFAM_OPT, Boolean.toString(match));
}
+ /**
+ * Enable or disable matching on the qualifier field of the key. Defaults to
enable.
+ *
+ * @since 2.1.3
+ */
public static void matchColumnQualifier(IteratorSetting cfg, boolean match) {
cfg.addOption(MATCH_COLQUAL_OPT, Boolean.toString(match));
}
+ /**
+ * Enable or disable matching on the visibility field of the key. Defaults
to disable.
+ *
+ * @since 2.1.3
+ */
public static void matchColumnVisibility(IteratorSetting cfg, boolean match)
{
cfg.addOption(MATCH_COLVIS_OPT, Boolean.toString(match));
}
+ /**
+ * Enable or disable matching on the value. Defaults to enable.
+ *
+ * @since 2.1.3
+ */
public static void matchValue(IteratorSetting cfg, boolean match) {
cfg.addOption(MATCH_VALUE_OPT, Boolean.toString(match));
}
diff --git
a/core/src/test/java/org/apache/accumulo/core/iterators/user/GrepIteratorTest.java
b/core/src/test/java/org/apache/accumulo/core/iterators/user/GrepIteratorTest.java
index 191a0403a0..31acabac68 100644
---
a/core/src/test/java/org/apache/accumulo/core/iterators/user/GrepIteratorTest.java
+++
b/core/src/test/java/org/apache/accumulo/core/iterators/user/GrepIteratorTest.java
@@ -68,6 +68,9 @@ public class GrepIteratorTest {
output.put(new Key("dfh", "xyz", "xyz", 0), new Value("abcdef"));
input.put(new Key("dfh", "xyz", "xyz", 1), new Value("xyz"));
+ input.put(new Key("dfh", "xyz", "xyz", "abcdef", 0), new Value("xyz"));
+ output.put(new Key("dfh", "xyz", "xyz", "abcdef", 0), new Value("xyz"));
+
Key k = new Key("dfh", "xyz", "xyz", 1);
k.setDeleted(true);
input.put(k, new Value("xyz"));
@@ -82,6 +85,7 @@ public class GrepIteratorTest {
assertEquals(e.getValue(), skvi.getTopValue());
skvi.next();
}
+
assertFalse(skvi.hasTop());
}
@@ -90,9 +94,9 @@ public class GrepIteratorTest {
GrepIterator gi = new GrepIterator();
IteratorSetting is = new IteratorSetting(1, GrepIterator.class);
GrepIterator.setTerm(is, "ab");
+ GrepIterator.matchColumnVisibility(is, true);
gi.init(new SortedMapIterator(input), is.getOptions(), null);
gi.seek(new Range(), EMPTY_COL_FAMS, false);
- GrepIterator.matchColumnVisibility(is, true);
checkEntries(gi, output);
GrepIterator.setTerm(is, "cde");
gi.init(new SortedMapIterator(input), is.getOptions(), null);
@@ -118,4 +122,139 @@ public class GrepIteratorTest {
checkEntries(gi, output);
}
+
+ @Test
+ public void testMatchRow() throws Exception {
+ GrepIterator gi = new GrepIterator();
+ IteratorSetting is = new IteratorSetting(1, GrepIterator.class);
+
+ GrepIterator.setTerm(is, "abcdef");
+
+ GrepIterator.matchRow(is, true);
+ GrepIterator.matchColumnFamily(is, false);
+ GrepIterator.matchColumnQualifier(is, false);
+ GrepIterator.matchColumnVisibility(is, false);
+ GrepIterator.matchValue(is, false);
+
+ gi.init(new SortedMapIterator(input), is.getOptions(), null);
+ gi.seek(new Range(), EMPTY_COL_FAMS, false);
+
+ SortedMap<Key,Value> expectedOutput = new TreeMap<>();
+ input.forEach((k, v) -> {
+ if (k.getRowData().toString().contains("abcdef") || k.isDeleted()) {
+ expectedOutput.put(k, v);
+ }
+ });
+
+ assertFalse(expectedOutput.isEmpty());
+ checkEntries(gi, expectedOutput);
+ }
+
+ @Test
+ public void testMatchFamily() throws Exception {
+ GrepIterator gi = new GrepIterator();
+ IteratorSetting is = new IteratorSetting(1, GrepIterator.class);
+
+ GrepIterator.setTerm(is, "abcdef");
+
+ GrepIterator.matchRow(is, false);
+ GrepIterator.matchColumnFamily(is, true);
+ GrepIterator.matchColumnQualifier(is, false);
+ GrepIterator.matchColumnVisibility(is, false);
+ GrepIterator.matchValue(is, false);
+
+ gi.init(new SortedMapIterator(input), is.getOptions(), null);
+ gi.seek(new Range(), EMPTY_COL_FAMS, false);
+
+ SortedMap<Key,Value> expectedOutput = new TreeMap<>();
+ input.forEach((k, v) -> {
+ if (k.getColumnFamilyData().toString().contains("abcdef") ||
k.isDeleted()) {
+ expectedOutput.put(k, v);
+ }
+ });
+
+ assertFalse(expectedOutput.isEmpty());
+ checkEntries(gi, expectedOutput);
+ }
+
+ @Test
+ public void testMatchQualifier() throws Exception {
+ GrepIterator gi = new GrepIterator();
+ IteratorSetting is = new IteratorSetting(1, GrepIterator.class);
+
+ GrepIterator.setTerm(is, "abcdef");
+
+ GrepIterator.matchRow(is, false);
+ GrepIterator.matchColumnFamily(is, false);
+ GrepIterator.matchColumnQualifier(is, true);
+ GrepIterator.matchColumnVisibility(is, false);
+ GrepIterator.matchValue(is, false);
+
+ gi.init(new SortedMapIterator(input), is.getOptions(), null);
+ gi.seek(new Range(), EMPTY_COL_FAMS, false);
+
+ SortedMap<Key,Value> expectedOutput = new TreeMap<>();
+ input.forEach((k, v) -> {
+ if (k.getColumnQualifierData().toString().contains("abcdef") ||
k.isDeleted()) {
+ expectedOutput.put(k, v);
+ }
+ });
+
+ assertFalse(expectedOutput.isEmpty());
+ checkEntries(gi, expectedOutput);
+ }
+
+ @Test
+ public void testMatchVisibility() throws Exception {
+ GrepIterator gi = new GrepIterator();
+ IteratorSetting is = new IteratorSetting(1, GrepIterator.class);
+
+ GrepIterator.setTerm(is, "abcdef");
+
+ GrepIterator.matchRow(is, false);
+ GrepIterator.matchColumnFamily(is, false);
+ GrepIterator.matchColumnQualifier(is, false);
+ GrepIterator.matchColumnVisibility(is, true);
+ GrepIterator.matchValue(is, false);
+
+ gi.init(new SortedMapIterator(input), is.getOptions(), null);
+ gi.seek(new Range(), EMPTY_COL_FAMS, false);
+
+ SortedMap<Key,Value> expectedOutput = new TreeMap<>();
+ input.forEach((k, v) -> {
+ if (k.getColumnVisibilityData().toString().contains("abcdef") ||
k.isDeleted()) {
+ expectedOutput.put(k, v);
+ }
+ });
+
+ assertFalse(expectedOutput.isEmpty());
+ checkEntries(gi, expectedOutput);
+ }
+
+ @Test
+ public void testMatchValue() throws Exception {
+ GrepIterator gi = new GrepIterator();
+ IteratorSetting is = new IteratorSetting(1, GrepIterator.class);
+
+ GrepIterator.setTerm(is, "abcdef");
+
+ GrepIterator.matchRow(is, false);
+ GrepIterator.matchColumnFamily(is, false);
+ GrepIterator.matchColumnQualifier(is, false);
+ GrepIterator.matchColumnVisibility(is, false);
+ GrepIterator.matchValue(is, true);
+
+ gi.init(new SortedMapIterator(input), is.getOptions(), null);
+ gi.seek(new Range(), EMPTY_COL_FAMS, false);
+
+ SortedMap<Key,Value> expectedOutput = new TreeMap<>();
+ input.forEach((k, v) -> {
+ if (v.toString().contains("abcdef") || k.isDeleted()) {
+ expectedOutput.put(k, v);
+ }
+ });
+
+ assertFalse(expectedOutput.isEmpty());
+ checkEntries(gi, expectedOutput);
+ }
}