Skip to content

Commit

Permalink
update import and export data -help description (#12677)
Browse files Browse the repository at this point in the history
Co-authored-by: 2b3c511 <[email protected]>
  • Loading branch information
2b3c511 and 2b3c511 authored Jun 6, 2024
1 parent 82f203e commit 18d7f0b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected void testOnWindows() throws IOException {
"root",
"-pw",
"root",
"-td",
"-t",
"target",
"-q",
"select * from root.test.t2 where time > 1 and time < 1000000000000",
Expand All @@ -115,7 +115,7 @@ protected void testOnWindows() throws IOException {
"root",
"-pw",
"root",
"-td",
"-t",
"target",
"-q",
"select * from root.test.t2 where time > 1 and time < 1000000000000",
Expand All @@ -141,7 +141,7 @@ protected void testOnWindows() throws IOException {
"root",
"-pw",
"root",
"-td",
"-t",
"target",
"-type",
"sql",
Expand Down Expand Up @@ -170,7 +170,7 @@ protected void testOnUnix() throws IOException {
"root",
"-pw",
"root",
"-td",
"-t",
"target",
"-q",
"select * from root.**");
Expand All @@ -193,7 +193,7 @@ protected void testOnUnix() throws IOException {
"root",
"-pw",
"root",
"-td",
"-t",
"target",
"-q",
"select * from root.**");
Expand All @@ -216,7 +216,7 @@ protected void testOnUnix() throws IOException {
"root",
"-pw",
"root",
"-td",
"-t",
"target",
"-type",
"sql",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
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;
Expand All @@ -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();
Expand All @@ -55,7 +55,7 @@ public static void setUp() {
libPath = EnvFactory.getEnv().getLibPath();
}

@After
@AfterClass
public static void tearDown() {
EnvFactory.getEnv().cleanClusterEnvironment();
}
Expand All @@ -74,7 +74,7 @@ public void test() throws IOException {
@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(
Expand All @@ -89,7 +89,7 @@ protected void testOnWindows() throws IOException {
"root",
"-pw",
"root",
"-f",
"-s",
"./",
"&",
"exit",
Expand All @@ -101,7 +101,7 @@ protected void testOnWindows() throws IOException {
@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(
Expand All @@ -115,7 +115,7 @@ protected void testOnUnix() throws IOException {
"root",
"-pw",
"root",
"-f",
"-s",
"./");
builder.environment().put("CLASSPATH", libPath);
testOutput(builder, output, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;

Expand All @@ -43,25 +44,29 @@ 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";

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 =
Expand Down Expand Up @@ -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");
Expand All @@ -145,11 +154,10 @@ protected static void setTimeZone() throws IoTDBConnectionException, StatementEx
}

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() {
Expand All @@ -176,30 +184,27 @@ protected static Options createNewOptions() {
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);

Expand All @@ -209,7 +214,7 @@ protected static Options createNewOptions() {
.optionalArg(true)
.argName(PW_NAME)
.hasArg()
.desc("Password (required)")
.desc("Password (optional)")
.build();
options.addOption(opPassword);
return options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@
*/
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";
Expand All @@ -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";

Expand Down Expand Up @@ -207,7 +207,7 @@ public static void main(String[] args) {
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@

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";
Expand All @@ -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";

Expand Down

0 comments on commit 18d7f0b

Please sign in to comment.