diff --git a/hadoop-ozone/dist/src/main/smoketest/debug/ozone-debug-ldb.robot b/hadoop-ozone/dist/src/main/smoketest/debug/ozone-debug-ldb.robot index 61ea61099015..7157c232d1a9 100644 --- a/hadoop-ozone/dist/src/main/smoketest/debug/ozone-debug-ldb.robot +++ b/hadoop-ozone/dist/src/main/smoketest/debug/ozone-debug-ldb.robot @@ -110,6 +110,16 @@ Test ozone debug ldb scan with filter option success Should not contain ${output} testfile1 Should not contain ${output} testfile2 Should not contain ${output} testfile3 + # test filter option with regex matching numbers + ${output} = Execute ozone debug ldb --db=/data/metadata/om.db scan --cf=keyTable --filter="dataSize:regex:^1[0-2]{3}$" + Should contain ${output} testfile1 + Should not contain ${output} testfile2 + Should not contain ${output} testfile3 + # test filter option with regex matching string + ${output} = Execute ozone debug ldb --db=/data/metadata/om.db scan --cf=keyTable --filter="keyName:regex:^test.*[0-1]$" + Should contain ${output} testfile1 + Should not contain ${output} testfile2 + Should not contain ${output} testfile3 Test ozone debug ldb scan with filter option failure # test filter option with invalid operator diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/debug/TestLDBCli.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/debug/TestLDBCli.java index 135a8ffd070b..7e16c0a29e35 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/debug/TestLDBCli.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/debug/TestLDBCli.java @@ -120,6 +120,7 @@ public void shutdown() throws IOException { /** * Defines ldb tool test cases. */ + @SuppressWarnings({"methodlength"}) private static Stream scanTestCases() { return Stream.of( Arguments.of( @@ -206,6 +207,19 @@ private static Stream scanTestCases() { Named.of("Filter dataSize>2000", Arrays.asList("--filter", "dataSize:greater:2000")), Named.of("Expect empty result", null) ), + Arguments.of( + Named.of(KEY_TABLE, Pair.of(KEY_TABLE, false)), + Named.of("Default", Pair.of(0, "")), + Named.of("Filter key3 regex", Arrays.asList("--filter", "keyName:regex:^.*3$")), + Named.of("Expect key3", Pair.of("key3", "key4")) + ), + Arguments.of( + Named.of(KEY_TABLE, Pair.of(KEY_TABLE, false)), + Named.of("Default", Pair.of(0, "")), + Named.of("Filter keys whose dataSize digits start with 5 using regex", + Arrays.asList("--filter", "dataSize:regex:^5.*$")), + Named.of("Expect empty result", null) + ), Arguments.of( Named.of(BLOCK_DATA + " V3", Pair.of(BLOCK_DATA, true)), Named.of("Default", Pair.of(0, "")), diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/DBScanner.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/DBScanner.java index 92635b2e3781..8aa52166cb1c 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/DBScanner.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/DBScanner.java @@ -74,6 +74,8 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import static java.nio.charset.StandardCharsets.UTF_8; @@ -132,9 +134,11 @@ public class DBScanner implements Callable, SubcommandWithParent { @CommandLine.Option(names = {"--filter"}, description = "Comma-separated list of \"::\" where " + " is any valid field of the record, " + - " is (EQUALS,LESSER or GREATER) and " + - " is the value of the field. " + - "eg.) \"dataSize:equals:1000\" for showing records having the value 1000 for dataSize") + " is [EQUALS,LESSER, GREATER or REGEX]. (EQUALS compares the exact string, " + + "REGEX compares with a valid regular expression passed, and LESSER/GREATER works with numeric values), " + + " is the value of the field. \n" + + "eg.) \"dataSize:equals:1000\" for showing records having the value 1000 for dataSize, \n" + + " \"keyName:regex:^key.*$\" for showing records having keyName that matches the given regex.") private String filter; @CommandLine.Option(names = {"--dnSchema", "--dn-schema", "-d"}, @@ -396,7 +400,6 @@ private boolean checkFilteredObject(Object obj, Class clazz, Map clazz, Map