This is an automated email from the ASF dual-hosted git repository.
ddanielr 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 c2681b3f9b Fix CF and CQ cli options for DeleteMany and Grep commands
(#5445)
c2681b3f9b is described below
commit c2681b3f9bc46b5144f8571ba3bfc5dbb8250cd5
Author: Daniel Roberts <[email protected]>
AuthorDate: Thu Apr 3 13:06:35 2025 -0400
Fix CF and CQ cli options for DeleteMany and Grep commands (#5445)
* Use Column CF and CQ cli options
Use the CF and CQ command line options in the DeleteMany and Grep
commands.
* Fix minor spelling of "interpreter"
* Simplify column fetching methods
Reduce the two separate column fetch methods into a single method.
---
.../accumulo/shell/commands/DeleteManyCommand.java | 6 +-
.../accumulo/shell/commands/GrepCommand.java | 6 +-
.../accumulo/shell/commands/ScanCommand.java | 102 +++++++++------------
3 files changed, 49 insertions(+), 65 deletions(-)
diff --git
a/shell/src/main/java/org/apache/accumulo/shell/commands/DeleteManyCommand.java
b/shell/src/main/java/org/apache/accumulo/shell/commands/DeleteManyCommand.java
index 5384736b53..9bf09830c8 100644
---
a/shell/src/main/java/org/apache/accumulo/shell/commands/DeleteManyCommand.java
+++
b/shell/src/main/java/org/apache/accumulo/shell/commands/DeleteManyCommand.java
@@ -42,7 +42,7 @@ public class DeleteManyCommand extends ScanCommand {
final String tableName = OptUtil.getTableOpt(cl, shellState);
@SuppressWarnings("deprecation")
- final org.apache.accumulo.core.util.interpret.ScanInterpreter interpeter =
+ final org.apache.accumulo.core.util.interpret.ScanInterpreter interpreter =
getInterpreter(cl, tableName, shellState);
// handle first argument, if present, the authorizations list to
@@ -57,12 +57,12 @@ public class DeleteManyCommand extends ScanCommand {
addScanIterators(shellState, cl, scanner, tableName);
// handle remaining optional arguments
- scanner.setRange(getRange(cl, interpeter));
+ scanner.setRange(getRange(cl, interpreter));
scanner.setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS);
// handle columns
- fetchColumns(cl, scanner, interpeter);
+ fetchColumns(cl, scanner, interpreter);
// output / delete the records
final BatchWriter writer =
shellState.getAccumuloClient().createBatchWriter(tableName,
diff --git
a/shell/src/main/java/org/apache/accumulo/shell/commands/GrepCommand.java
b/shell/src/main/java/org/apache/accumulo/shell/commands/GrepCommand.java
index 2695f572f3..4f6160fcdd 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/commands/GrepCommand.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/commands/GrepCommand.java
@@ -65,7 +65,7 @@ public class GrepCommand extends ScanCommand {
}
final Class<? extends Formatter> formatter = getFormatter(cl, tableName,
shellState);
@SuppressWarnings("deprecation")
- final org.apache.accumulo.core.util.interpret.ScanInterpreter interpeter
=
+ final org.apache.accumulo.core.util.interpret.ScanInterpreter
interpreter =
getInterpreter(cl, tableName, shellState);
// handle first argument, if present, the authorizations list to
@@ -83,7 +83,7 @@ public class GrepCommand extends ScanCommand {
final Authorizations auths = getAuths(cl, shellState);
final BatchScanner scanner =
shellState.getAccumuloClient().createBatchScanner(tableName, auths,
numThreads);
- scanner.setRanges(Collections.singletonList(getRange(cl, interpeter)));
+ scanner.setRanges(Collections.singletonList(getRange(cl, interpreter)));
scanner.setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS);
@@ -98,7 +98,7 @@ public class GrepCommand extends ScanCommand {
}
try {
// handle columns
- fetchColumns(cl, scanner, interpeter);
+ fetchColumns(cl, scanner, interpreter);
// output the records
printRecords(cl, shellState, config, scanner, formatter, printFile);
diff --git
a/shell/src/main/java/org/apache/accumulo/shell/commands/ScanCommand.java
b/shell/src/main/java/org/apache/accumulo/shell/commands/ScanCommand.java
index d9bc9f7d90..d2c5286c2d 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/commands/ScanCommand.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/commands/ScanCommand.java
@@ -58,7 +58,7 @@ import org.apache.hadoop.io.Text;
public class ScanCommand extends Command {
private Option scanOptAuths, scanOptRow, scanOptColumns,
disablePaginationOpt, formatterOpt,
- interpreterOpt, formatterInterpeterOpt, outputFileOpt, scanOptCf,
scanOptCq;
+ interpreterOpt, formatterInterpreterOpt, outputFileOpt, scanOptCf,
scanOptCq;
protected Option showFewOpt;
protected Option timestampOpt;
@@ -104,7 +104,7 @@ public class ScanCommand extends Command {
final Class<? extends Formatter> formatter = getFormatter(cl, tableName,
shellState);
@SuppressWarnings("deprecation")
- final org.apache.accumulo.core.util.interpret.ScanInterpreter interpeter
=
+ final org.apache.accumulo.core.util.interpret.ScanInterpreter
interpreter =
getInterpreter(cl, tableName, shellState);
String classLoaderContext = null;
@@ -121,11 +121,10 @@ public class ScanCommand extends Command {
addScanIterators(shellState, cl, scanner, tableName);
// handle remaining optional arguments
- scanner.setRange(getRange(cl, interpeter));
+ scanner.setRange(getRange(cl, interpreter));
// handle columns
- fetchColumns(cl, scanner, interpeter);
- fetchColumsWithCFAndCQ(cl, scanner, interpeter);
+ fetchColumns(cl, scanner, interpreter);
// set timeout
scanner.setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS);
@@ -244,11 +243,11 @@ public class ScanCommand extends Command {
clazz =
ClassLoaderUtil.loadClass(cl.getOptionValue(interpreterOpt.getOpt()),
org.apache.accumulo.core.util.interpret.ScanInterpreter.class);
- } else if (cl.hasOption(formatterInterpeterOpt.getOpt())) {
+ } else if (cl.hasOption(formatterInterpreterOpt.getOpt())) {
Shell.log
.warn("Scan Interpreter option is deprecated and will be removed
in a future version.");
- clazz =
ClassLoaderUtil.loadClass(cl.getOptionValue(formatterInterpeterOpt.getOpt()),
+ clazz =
ClassLoaderUtil.loadClass(cl.getOptionValue(formatterInterpreterOpt.getOpt()),
org.apache.accumulo.core.util.interpret.ScanInterpreter.class);
}
} catch (ClassNotFoundException e) {
@@ -275,11 +274,11 @@ public class ScanCommand extends Command {
return shellState.getClassLoader(cl, shellState)
.loadClass(cl.getOptionValue(formatterOpt.getOpt())).asSubclass(Formatter.class);
- } else if (cl.hasOption(formatterInterpeterOpt.getOpt())) {
+ } else if (cl.hasOption(formatterInterpreterOpt.getOpt())) {
Shell.log.warn("Formatter option is deprecated and will be removed in
a future version.");
return shellState.getClassLoader(cl, shellState)
- .loadClass(cl.getOptionValue(formatterInterpeterOpt.getOpt()))
+ .loadClass(cl.getOptionValue(formatterInterpreterOpt.getOpt()))
.asSubclass(Formatter.class);
}
} catch (Exception e) {
@@ -290,69 +289,54 @@ public class ScanCommand extends Command {
}
protected void fetchColumns(final CommandLine cl, final ScannerBase scanner,
- @SuppressWarnings("deprecation") final
org.apache.accumulo.core.util.interpret.ScanInterpreter formatter)
+ @SuppressWarnings("deprecation") final
org.apache.accumulo.core.util.interpret.ScanInterpreter interpreter)
throws UnsupportedEncodingException {
- if ((cl.hasOption(scanOptCf.getOpt()) || cl.hasOption(scanOptCq.getOpt()))
- && cl.hasOption(scanOptColumns.getOpt())) {
-
- String formattedString =
- String.format("Option -%s is mutually exclusive with options -%s and
-%s.",
- scanOptColumns.getOpt(), scanOptCf.getOpt(), scanOptCq.getOpt());
- throw new IllegalArgumentException(formattedString);
- }
-
- if (cl.hasOption(scanOptColumns.getOpt())) {
+ if (cl.hasOption(scanOptCf.getOpt()) || cl.hasOption(scanOptCq.getOpt())) {
+ if (cl.hasOption(scanOptColumns.getOpt())) {
+ String formattedString =
+ String.format("Option -%s is mutually exclusive with options -%s
and -%s.",
+ scanOptColumns.getOpt(), scanOptCf.getOpt(),
scanOptCq.getOpt());
+ throw new IllegalArgumentException(formattedString);
+ }
+ String cf = cl.getOptionValue(scanOptCf.getOpt(), "");
+ String cq = cl.getOptionValue(scanOptCq.getOpt(), "");
+
+ if (!cq.isEmpty()) {
+ if (cf.isEmpty()) {
+ String formattedString = String.format("Option -%s is required when
using -%s.",
+ scanOptCf.getOpt(), scanOptCq.getOpt());
+ throw new IllegalArgumentException(formattedString);
+ } else {
+ var interprettedCF =
+ interpreter.interpretColumnFamily(new
Text(cf.getBytes(Shell.CHARSET)));
+ var interprettedCQ =
+ interpreter.interpretColumnQualifier(new
Text(cq.getBytes(Shell.CHARSET)));
+ scanner.fetchColumn(interprettedCF, interprettedCQ);
+ }
+ } else if (!cf.isEmpty()) {
+ var interprettedCF =
+ interpreter.interpretColumnFamily(new
Text(cf.getBytes(Shell.CHARSET)));
+ scanner.fetchColumnFamily(interprettedCF);
+ }
+ } else if (cl.hasOption(scanOptColumns.getOpt())) {
for (String a : cl.getOptionValue(scanOptColumns.getOpt()).split(",")) {
final String[] sa = a.split(":", 2);
if (sa.length == 1) {
- @SuppressWarnings("deprecation")
- var interprettedCF = formatter.interpretColumnFamily(new
Text(a.getBytes(Shell.CHARSET)));
+ var interprettedCF =
+ interpreter.interpretColumnFamily(new
Text(a.getBytes(Shell.CHARSET)));
scanner.fetchColumnFamily(interprettedCF);
} else {
- @SuppressWarnings("deprecation")
var interprettedCF =
- formatter.interpretColumnFamily(new
Text(sa[0].getBytes(Shell.CHARSET)));
- @SuppressWarnings("deprecation")
+ interpreter.interpretColumnFamily(new
Text(sa[0].getBytes(Shell.CHARSET)));
var interprettedCQ =
- formatter.interpretColumnQualifier(new
Text(sa[1].getBytes(Shell.CHARSET)));
+ interpreter.interpretColumnQualifier(new
Text(sa[1].getBytes(Shell.CHARSET)));
scanner.fetchColumn(interprettedCF, interprettedCQ);
}
}
}
}
- private void fetchColumsWithCFAndCQ(CommandLine cl, Scanner scanner,
- @SuppressWarnings("deprecation")
org.apache.accumulo.core.util.interpret.ScanInterpreter interpeter) {
- String cf = "";
- String cq = "";
- if (cl.hasOption(scanOptCf.getOpt())) {
- cf = cl.getOptionValue(scanOptCf.getOpt());
- }
- if (cl.hasOption(scanOptCq.getOpt())) {
- cq = cl.getOptionValue(scanOptCq.getOpt());
- }
-
- if (cf.isEmpty() && !cq.isEmpty()) {
- String formattedString = String.format("Option -%s is required when
using -%s.",
- scanOptCf.getOpt(), scanOptCq.getOpt());
- throw new IllegalArgumentException(formattedString);
- } else if (!cf.isEmpty() && cq.isEmpty()) {
- @SuppressWarnings("deprecation")
- var interprettedCF = interpeter.interpretColumnFamily(new
Text(cf.getBytes(Shell.CHARSET)));
- scanner.fetchColumnFamily(interprettedCF);
- } else if (!cf.isEmpty() && !cq.isEmpty()) {
- @SuppressWarnings("deprecation")
- var interprettedCF = interpeter.interpretColumnFamily(new
Text(cf.getBytes(Shell.CHARSET)));
- @SuppressWarnings("deprecation")
- var interprettedCQ =
- interpeter.interpretColumnQualifier(new
Text(cq.getBytes(Shell.CHARSET)));
- scanner.fetchColumn(interprettedCF, interprettedCQ);
-
- }
-
- }
-
protected Range getRange(final CommandLine cl,
@SuppressWarnings("deprecation") final
org.apache.accumulo.core.util.interpret.ScanInterpreter formatter)
throws UnsupportedEncodingException {
@@ -436,7 +420,7 @@ public class ScanCommand extends Command {
new Option("fm", "formatter", true, "fully qualified name of the
formatter class to use");
interpreterOpt = new Option("i", "interpreter", true,
"fully qualified name of the interpreter class to use");
- formatterInterpeterOpt = new Option("fi", "fmt-interpreter", true,
+ formatterInterpreterOpt = new Option("fi", "fmt-interpreter", true,
"fully qualified name of a class that is a formatter and interpreter");
timeoutOption = new Option(null, "timeout", true,
"time before scan should fail if no data is returned. If no unit is"
@@ -483,7 +467,7 @@ public class ScanCommand extends Command {
o.addOption(OptUtil.tableOpt("table to be scanned"));
o.addOption(formatterOpt);
o.addOption(interpreterOpt);
- o.addOption(formatterInterpeterOpt);
+ o.addOption(formatterInterpreterOpt);
o.addOption(timeoutOption);
if (Arrays.asList(ScanCommand.class.getName(), GrepCommand.class.getName(),
EGrepCommand.class.getName()).contains(this.getClass().getName())) {