in iotdb-client/cli/src/main/java/org/apache/iotdb/tool/data/ImportData.java [236:338]
private static void parseSpecialParams(CommandLine commandLine) throws ArgsErrorException {
timeZoneID = commandLine.getOptionValue(Constants.TIME_ZONE_ARGS);
targetPath = commandLine.getOptionValue(Constants.FILE_ARGS);
if (commandLine.getOptionValue(Constants.BATCH_POINT_SIZE_ARGS) != null) {
batchPointSize =
Integer.parseInt(commandLine.getOptionValue(Constants.BATCH_POINT_SIZE_ARGS));
}
if (commandLine.getOptionValue(Constants.FAIL_DIR_ARGS) != null) {
failedFileDirectory = commandLine.getOptionValue(Constants.FAIL_DIR_ARGS);
File file = new File(failedFileDirectory);
if (!file.isDirectory()) {
file.mkdir();
failedFileDirectory = file.getAbsolutePath() + File.separator;
} else if (!failedFileDirectory.endsWith("/") && !failedFileDirectory.endsWith("\\")) {
failedFileDirectory += File.separator;
}
}
if (commandLine.getOptionValue(Constants.ALIGNED_ARGS) != null) {
aligned = Boolean.valueOf(commandLine.getOptionValue(Constants.ALIGNED_ARGS));
}
if (commandLine.getOptionValue(Constants.THREAD_NUM_ARGS) != null) {
threadNum = Integer.parseInt(commandLine.getOptionValue(Constants.THREAD_NUM_ARGS));
if (threadNum <= 0) {
ioTPrinter.println(
String.format(
"error: Invalid thread number '%s'. Please set a positive integer.", threadNum));
System.exit(Constants.CODE_ERROR);
}
}
if (commandLine.getOptionValue(Constants.TIMESTAMP_PRECISION_ARGS) != null) {
timestampPrecision = commandLine.getOptionValue(Constants.TIMESTAMP_PRECISION_ARGS);
}
final String[] opTypeInferValues = commandLine.getOptionValues(Constants.TYPE_INFER_ARGS);
if (opTypeInferValues != null && opTypeInferValues.length > 0) {
for (String opTypeInferValue : opTypeInferValues) {
if (opTypeInferValue.contains("=")) {
final String[] typeInfoExpressionArr = opTypeInferValue.split("=");
final String key = typeInfoExpressionArr[0];
final String value = typeInfoExpressionArr[1];
applyTypeInferArgs(key, value);
}
}
}
if (commandLine.getOptionValue(Constants.LINES_PER_FAILED_FILE_ARGS) != null) {
linesPerFailedFile =
Integer.parseInt(commandLine.getOptionValue(Constants.LINES_PER_FAILED_FILE_ARGS));
}
if (commandLine.getOptionValue(Constants.DB_ARGS) != null) {
database = commandLine.getOptionValue(Constants.DB_ARGS);
}
if (commandLine.getOptionValue(Constants.TABLE_ARGS) != null) {
table = commandLine.getOptionValue(Constants.TABLE_ARGS);
}
if (commandLine.getOptionValue(Constants.START_TIME_ARGS) != null) {
startTime = commandLine.getOptionValue(Constants.START_TIME_ARGS);
}
if (commandLine.getOptionValue(Constants.END_TIME_ARGS) != null) {
endTime = commandLine.getOptionValue(Constants.END_TIME_ARGS);
}
try {
isRemoteLoad = !NodeUrlUtils.containsLocalAddress(Collections.singletonList(host));
if (!sqlDialectTree && isRemoteLoad && Constants.TSFILE_SUFFIXS.equalsIgnoreCase(fileType)) {
ioTPrinter.println(
"host: " + host + " is remote load,only local load is supported in table model");
}
} catch (UnknownHostException e) {
ioTPrinter.println(
"Unknown host: " + host + ". Exception: " + e.getMessage() + ". Will use local load.");
}
final String os = commandLine.getOptionValue(Constants.ON_SUCCESS_ARGS);
final String onSuccess = StringUtils.isNotBlank(os) ? os.trim().toLowerCase() : null;
final String of = commandLine.getOptionValue(Constants.ON_FAIL_ARGS);
final String onFail = StringUtils.isNotBlank(of) ? of.trim().toLowerCase() : null;
if (Constants.TSFILE_SUFFIXS.equalsIgnoreCase(fileType)
&& (!ImportTsFileOperation.isValidOperation(onSuccess)
|| !ImportTsFileOperation.isValidOperation(onFail))) {
ioTPrinter.println("Args error: os/of must be one of none, mv, cp, delete");
System.exit(Constants.CODE_ERROR);
}
if (Constants.TSFILE_SUFFIXS.equalsIgnoreCase(fileType)) {
boolean isSuccessDirEqualsSourceDir = false;
if (ImportTsFileOperation.MV.name().equalsIgnoreCase(onSuccess)
|| ImportTsFileOperation.CP.name().equalsIgnoreCase(onSuccess)) {
File dir = createSuccessDir(commandLine);
isSuccessDirEqualsSourceDir = isFileStoreEquals(targetPath, dir);
}
boolean isFailDirEqualsSourceDir = false;
if (ImportTsFileOperation.MV.name().equalsIgnoreCase(onFail)
|| ImportTsFileOperation.CP.name().equalsIgnoreCase(onFail)) {
File dir = createFailDir(commandLine);
isFailDirEqualsSourceDir = isFileStoreEquals(targetPath, dir);
}
successOperation = ImportTsFileOperation.getOperation(onSuccess, isSuccessDirEqualsSourceDir);
failOperation = ImportTsFileOperation.getOperation(onFail, isFailDirEqualsSourceDir);
}
if (!sqlDialectTree
&& Constants.CSV_SUFFIXS.equalsIgnoreCase(fileType)
&& StringUtils.isBlank(table)) {
ioTPrinter.println("Invalid args: Required values for option table not provided.");
System.exit(Constants.CODE_ERROR);
}
}