This is an automated email from the ASF dual-hosted git repository.

haonan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 18d7f0ba6b0 update import and export data -help description (#12677)
18d7f0ba6b0 is described below

commit 18d7f0ba6b08489ee863119413d52cf41faaefe6
Author: Summer <[email protected]>
AuthorDate: Thu Jun 6 18:03:09 2024 +0800

    update import and export data -help description (#12677)
    
    Co-authored-by: 2b3c511 <[email protected]>
---
 .../apache/iotdb/tools/it/ExportDataTestIT.java    | 12 ++++----
 .../apache/iotdb/tools/it/ImportDataTestIT.java    | 16 +++++------
 .../org/apache/iotdb/tool/AbstractDataTool.java    | 33 +++++++++++++---------
 .../java/org/apache/iotdb/tool/ExportData.java     | 14 ++++-----
 .../java/org/apache/iotdb/tool/ImportData.java     |  8 +++---
 5 files changed, 44 insertions(+), 39 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/tools/it/ExportDataTestIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/tools/it/ExportDataTestIT.java
index ec53326f427..f04f387fd38 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/tools/it/ExportDataTestIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/tools/it/ExportDataTestIT.java
@@ -89,7 +89,7 @@ public class ExportDataTestIT extends AbstractScript {
             "root",
             "-pw",
             "root",
-            "-td",
+            "-t",
             "target",
             "-q",
             "select * from root.test.t2 where time > 1 and time < 
1000000000000",
@@ -115,7 +115,7 @@ public class ExportDataTestIT extends AbstractScript {
             "root",
             "-pw",
             "root",
-            "-td",
+            "-t",
             "target",
             "-q",
             "select * from root.test.t2 where time > 1 and time < 
1000000000000",
@@ -141,7 +141,7 @@ public class ExportDataTestIT extends AbstractScript {
             "root",
             "-pw",
             "root",
-            "-td",
+            "-t",
             "target",
             "-type",
             "sql",
@@ -170,7 +170,7 @@ public class ExportDataTestIT extends AbstractScript {
             "root",
             "-pw",
             "root",
-            "-td",
+            "-t",
             "target",
             "-q",
             "select * from root.**");
@@ -193,7 +193,7 @@ public class ExportDataTestIT extends AbstractScript {
             "root",
             "-pw",
             "root",
-            "-td",
+            "-t",
             "target",
             "-q",
             "select * from root.**");
@@ -216,7 +216,7 @@ public class ExportDataTestIT extends AbstractScript {
             "root",
             "-pw",
             "root",
-            "-td",
+            "-t",
             "target",
             "-type",
             "sql",
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/tools/it/ImportDataTestIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/tools/it/ImportDataTestIT.java
index 625d2b9481c..391b726f6d7 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/tools/it/ImportDataTestIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/tools/it/ImportDataTestIT.java
@@ -25,8 +25,8 @@ import org.apache.iotdb.it.framework.IoTDBTestRunner;
 import org.apache.iotdb.itbase.category.ClusterIT;
 import org.apache.iotdb.itbase.category.LocalStandaloneIT;
 
-import org.junit.After;
-import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.runner.RunWith;
@@ -46,7 +46,7 @@ public class ImportDataTestIT extends AbstractScript {
 
   private static String libPath;
 
-  @Before
+  @BeforeClass
   public static void setUp() {
     EnvFactory.getEnv().initClusterEnvironment();
     ip = EnvFactory.getEnv().getIP();
@@ -55,7 +55,7 @@ public class ImportDataTestIT extends AbstractScript {
     libPath = EnvFactory.getEnv().getLibPath();
   }
 
-  @After
+  @AfterClass
   public static void tearDown() {
     EnvFactory.getEnv().cleanClusterEnvironment();
   }
@@ -74,7 +74,7 @@ public class ImportDataTestIT extends AbstractScript {
   @Override
   protected void testOnWindows() throws IOException {
     final String[] output = {
-      "The file name must end with \"csv\" or \"txt\" or \"sql\"!",
+      "The file name must end with \"csv\" or \"txt\"!",
     };
     ProcessBuilder builder =
         new ProcessBuilder(
@@ -89,7 +89,7 @@ public class ImportDataTestIT extends AbstractScript {
             "root",
             "-pw",
             "root",
-            "-f",
+            "-s",
             "./",
             "&",
             "exit",
@@ -101,7 +101,7 @@ public class ImportDataTestIT extends AbstractScript {
   @Override
   protected void testOnUnix() throws IOException {
     final String[] output = {
-      "The file name must end with \"csv\" or \"txt\" or \"sql\"!",
+      "The file name must end with \"csv\" or \"txt\"!",
     };
     ProcessBuilder builder =
         new ProcessBuilder(
@@ -115,7 +115,7 @@ public class ImportDataTestIT extends AbstractScript {
             "root",
             "-pw",
             "root",
-            "-f",
+            "-s",
             "./");
     builder.environment().put("CLASSPATH", libPath);
     testOutput(builder, output, 0);
diff --git 
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/AbstractDataTool.java 
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/AbstractDataTool.java
index 6ae1a1791dc..1e689e903c1 100644
--- a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/AbstractDataTool.java
+++ b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/AbstractDataTool.java
@@ -31,6 +31,7 @@ import org.apache.commons.cli.Options;
 import org.apache.commons.csv.CSVFormat;
 import org.apache.commons.csv.CSVPrinter;
 import org.apache.commons.csv.QuoteMode;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -43,17 +44,21 @@ public abstract class AbstractDataTool {
 
   protected static final String HOST_ARGS = "h";
   protected static final String HOST_NAME = "host";
+  protected static final String HOST_DEFAULT_VALUE = "127.0.0.1";
 
   protected static final String HELP_ARGS = "help";
 
   protected static final String PORT_ARGS = "p";
   protected static final String PORT_NAME = "port";
+  protected static final String PORT_DEFAULT_VALUE = "6667";
 
   protected static final String PW_ARGS = "pw";
   protected static final String PW_NAME = "password";
+  protected static final String PW_DEFAULT_VALUE = "root";
 
   protected static final String USERNAME_ARGS = "u";
   protected static final String USERNAME_NAME = "username";
+  protected static final String USERNAME_DEFAULT_VALUE = "root";
 
   protected static final String TIME_FORMAT_ARGS = "tf";
   protected static final String TIME_FORMAT_NAME = "timeformat";
@@ -61,7 +66,7 @@ public abstract class AbstractDataTool {
   protected static final String TIME_ZONE_ARGS = "tz";
   protected static final String TIME_ZONE_NAME = "timeZone";
 
-  protected static final String TIMEOUT_ARGS = "t";
+  protected static final String TIMEOUT_ARGS = "timeout";
   protected static final String TIMEOUT_NAME = "timeout";
   protected static final int MAX_HELP_CONSOLE_WIDTH = 92;
   protected static final String[] TIME_FORMAT =
@@ -125,10 +130,14 @@ public abstract class AbstractDataTool {
 
   protected AbstractDataTool() {}
 
-  protected static String checkRequiredArg(String arg, String name, 
CommandLine commandLine)
+  protected static String checkRequiredArg(
+      String arg, String name, CommandLine commandLine, String defaultValue)
       throws ArgsErrorException {
     String str = commandLine.getOptionValue(arg);
     if (str == null) {
+      if (StringUtils.isNotBlank(defaultValue)) {
+        return defaultValue;
+      }
       String msg = String.format("Required values for option '%s' not 
provided", name);
       LOGGER.info(msg);
       LOGGER.info("Use -help for more information");
@@ -145,11 +154,10 @@ public abstract class AbstractDataTool {
   }
 
   protected static void parseBasicParams(CommandLine commandLine) throws 
ArgsErrorException {
-    host = checkRequiredArg(HOST_ARGS, HOST_NAME, commandLine);
-    port = checkRequiredArg(PORT_ARGS, PORT_NAME, commandLine);
-    username = checkRequiredArg(USERNAME_ARGS, USERNAME_NAME, commandLine);
-
-    password = commandLine.getOptionValue(PW_ARGS);
+    host = checkRequiredArg(HOST_ARGS, HOST_NAME, commandLine, 
HOST_DEFAULT_VALUE);
+    port = checkRequiredArg(PORT_ARGS, PORT_NAME, commandLine, 
PORT_DEFAULT_VALUE);
+    username = checkRequiredArg(USERNAME_ARGS, USERNAME_NAME, commandLine, 
USERNAME_DEFAULT_VALUE);
+    password = commandLine.getOptionValue(PW_ARGS, PW_DEFAULT_VALUE);
   }
 
   protected static boolean checkTimeFormat() {
@@ -176,30 +184,27 @@ public abstract class AbstractDataTool {
     Option opHost =
         Option.builder(HOST_ARGS)
             .longOpt(HOST_NAME)
-            .required()
             .argName(HOST_NAME)
             .hasArg()
-            .desc("Host Name (required)")
+            .desc("Host Name (optional)")
             .build();
     options.addOption(opHost);
 
     Option opPort =
         Option.builder(PORT_ARGS)
             .longOpt(PORT_NAME)
-            .required()
             .argName(PORT_NAME)
             .hasArg()
-            .desc("Port (required)")
+            .desc("Port (optional)")
             .build();
     options.addOption(opPort);
 
     Option opUsername =
         Option.builder(USERNAME_ARGS)
             .longOpt(USERNAME_NAME)
-            .required()
             .argName(USERNAME_NAME)
             .hasArg()
-            .desc("Username (required)")
+            .desc("Username (optional)")
             .build();
     options.addOption(opUsername);
 
@@ -209,7 +214,7 @@ public abstract class AbstractDataTool {
             .optionalArg(true)
             .argName(PW_NAME)
             .hasArg()
-            .desc("Password (required)")
+            .desc("Password (optional)")
             .build();
     options.addOption(opPassword);
     return options;
diff --git 
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/ExportData.java 
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/ExportData.java
index 1475eb4a2c1..e67d8584792 100644
--- a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/ExportData.java
+++ b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/ExportData.java
@@ -67,14 +67,14 @@ import java.util.regex.Pattern;
  */
 public class ExportData extends AbstractDataTool {
 
-  private static final String TARGET_DIR_ARGS = "td";
+  private static final String TARGET_DIR_ARGS = "t";
   private static final String TARGET_DIR_NAME = "targetDirectory";
 
-  private static final String TARGET_FILE_ARGS = "f";
-  private static final String TARGET_FILE_NAME = "targetFile";
+  private static final String TARGET_FILE_ARGS = "tfn";
+  private static final String TARGET_FILE_NAME = "targetFileName";
 
   private static final String SQL_FILE_ARGS = "s";
-  private static final String SQL_FILE_NAME = "sqlfile";
+  private static final String SQL_FILE_NAME = "sourceSqlFile";
 
   private static final String DATA_TYPE_ARGS = "datatype";
   private static final String DATA_TYPE_NAME = "datatype";
@@ -90,8 +90,8 @@ public class ExportData extends AbstractDataTool {
 
   private static final String ALIGNED_ARGS = "aligned";
   private static final String ALIGNED_NAME = "export aligned insert sql";
-  private static final String LINES_PER_FILE_ARGS = "linesPerFile";
-  private static final String LINES_PER_FILE_ARGS_NAME = "Lines Per File";
+  private static final String LINES_PER_FILE_ARGS = "lpf";
+  private static final String LINES_PER_FILE_ARGS_NAME = "linesPerFile";
 
   private static final String TSFILEDB_CLI_PREFIX = "ExportData";
 
@@ -207,7 +207,7 @@ public class ExportData extends AbstractDataTool {
   }
 
   private static void parseSpecialParams(CommandLine commandLine) throws 
ArgsErrorException {
-    targetDirectory = checkRequiredArg(TARGET_DIR_ARGS, TARGET_DIR_NAME, 
commandLine);
+    targetDirectory = checkRequiredArg(TARGET_DIR_ARGS, TARGET_DIR_NAME, 
commandLine, null);
     targetFile = commandLine.getOptionValue(TARGET_FILE_ARGS);
     needDataTypePrinted = 
Boolean.valueOf(commandLine.getOptionValue(DATA_TYPE_ARGS));
     queryCommand = commandLine.getOptionValue(QUERY_COMMAND_ARGS);
diff --git 
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/ImportData.java 
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/ImportData.java
index 647bd2a497f..fac86ac07fd 100644
--- a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/ImportData.java
+++ b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/ImportData.java
@@ -75,8 +75,8 @@ import static org.apache.tsfile.enums.TSDataType.TEXT;
 
 public class ImportData extends AbstractDataTool {
 
-  private static final String FILE_ARGS = "f";
-  private static final String FILE_NAME = "file or folder";
+  private static final String FILE_ARGS = "s";
+  private static final String FILE_NAME = "sourceFileOrFolder";
 
   private static final String FAILED_FILE_ARGS = "fd";
   private static final String FAILED_FILE_NAME = "failed file directory";
@@ -98,8 +98,8 @@ public class ImportData extends AbstractDataTool {
   private static final String TYPE_INFER_ARGS = "typeInfer";
   private static final String TYPE_INFER_ARGS_NAME = "type infer";
 
-  private static final String LINES_PER_FAILED_FILE_ARGS = 
"linesPerFailedFile";
-  private static final String LINES_PER_FAILED_FILE_ARGS_NAME = "Lines Per 
FailedFile";
+  private static final String LINES_PER_FAILED_FILE_ARGS = "lpf";
+  private static final String LINES_PER_FAILED_FILE_ARGS_NAME = 
"linesPerFailedFile";
 
   private static final String TSFILEDB_CLI_PREFIX = "ImportData";
 

Reply via email to