in odps-console-dship/src/main/java/com/aliyun/odps/ship/common/OptionsBuilder.java [280:464]
public static void checkParameters(String type) {
checkDelimiters(type);
String project = DshipContext.INSTANCE.get(Constants.TABLE_PROJECT);
if (project != null && (project.trim().isEmpty())) {
throw new IllegalArgumentException(
"Project is empty.\nType 'tunnel help " + type + "' for usage.");
}
/*
Handle general options
*/
// charset
boolean isc = false;
String c = DshipContext.INSTANCE.get(Constants.CHARSET);
try {
isc = Charset.isSupported(c);
} catch (IllegalCharsetNameException e) {
//ignore bad charset name
}
isc = isc || Constants.IGNORE_CHARSET.equals(c);
if (c == null || c.isEmpty() || !isc) {
throw new IllegalArgumentException("Unsupported encoding: '" + c + "'\nType 'tunnel help "
+ type + "' for usage.");
}
// TODO: not a parameter from user
// Make sure session create time initialized
String sct = DshipContext.INSTANCE.get(Constants.SESSION_CREATE_TIME);
if (sct == null) {
throw new IllegalArgumentException(Constants.ERROR_INDICATOR + "create time is null.");
}
// compress
String cp = DshipContext.INSTANCE.get(Constants.COMPRESS);
if (cp == null) {
throw new IllegalArgumentException(Constants.ERROR_INDICATOR + "compress info is null.");
}
// threads
int threads;
try {
threads = Integer.parseInt(DshipContext.INSTANCE.get(Constants.THREADS));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(
Constants.THREADS + " " + DshipContext.INSTANCE.get(Constants.THREADS) + " Invalid.");
}
if (threads <= 0) {
throw new IllegalArgumentException(Constants.THREADS + " argument must > 0.");
}
if (threads > 1 && "true".equalsIgnoreCase(DshipContext.INSTANCE.get(Constants.HEADER))) {
throw new IllegalArgumentException("Do not support write header in multi-threads.");
}
String table = DshipContext.INSTANCE.get(Constants.TABLE);
/*
Handle download options
*/
if ("download".equals(type)) {
// table or instance ID
if (com.aliyun.odps.utils.StringUtils.isNullOrEmpty(table)
&& com.aliyun.odps.utils.StringUtils
.isNullOrEmpty(DshipContext.INSTANCE.get(Constants.INSTANE_ID))) {
throw new IllegalArgumentException("Table or instanceId is null.\nType 'tunnel help " + type
+ "' for usage.");
}
// limit
String limit = DshipContext.INSTANCE.get(Constants.LIMIT);
if (limit != null) {
try {
if (Long.valueOf(limit) <= 0) {
throw new IllegalArgumentException(Constants.LIMIT + " argument must > 0.");
}
} catch (NumberFormatException e) {
throw new IllegalArgumentException(Constants.LIMIT + " " + limit + " Invalid.");
}
}
// exponential format
String exponential = DshipContext.INSTANCE.get(Constants.EXPONENTIAL);
if (exponential != null && !(exponential.equalsIgnoreCase("true")
|| exponential.equalsIgnoreCase("false"))) {
throw new IllegalArgumentException(
"Invalid parameter : exponential format in double expected 'true' or 'false', found '"
+ exponential
+ "'\nType 'tunnel help " + type + "' for usage.");
}
// column name & column index
String columnNames = DshipContext.INSTANCE.get(Constants.COLUMNS_NAME);
String columnIndexes = DshipContext.INSTANCE.get(Constants.COLUMNS_INDEX);
if (columnNames != null && columnIndexes != null) {
throw new IllegalArgumentException(String.format(
"Invalid parameter, these two params cannot be used together: %s and %s ",
Constants.COLUMNS_INDEX, Constants.COLUMNS_NAME));
}
if (columnIndexes != null) {
for (String index : columnIndexes.split(",")) {
if (!StringUtils.isNumeric(index.trim())) {
throw new IllegalArgumentException(
"Invalid parameter, columns indexes expected numeric, found " + columnIndexes);
}
}
}
}
/*
Upload options
*/
if ("upload".equals(type) || "upsert".equals(type)) {
// table
if (com.aliyun.odps.utils.StringUtils.isNullOrEmpty(table)) {
throw new IllegalArgumentException("Table is null.\nType 'tunnel help " + type
+ "' for usage.");
}
if("upload".equals(type)) {
// scan
String scan = DshipContext.INSTANCE.get(Constants.SCAN);
if (scan == null || !(scan.equals("true") || scan.equals("false") || scan.equals("only"))) {
throw new IllegalArgumentException("-scan, expected:(true|false|only), actual: '" + scan
+ "'\nType 'tunnel help " + type + "' for usage.");
}
}
// discard bad records
String dbr = DshipContext.INSTANCE.get(Constants.DISCARD_BAD_RECORDS);
if (dbr == null || !(dbr.equals("true") || dbr.equals("false"))) {
throw new IllegalArgumentException(
"Invalid parameter : discard bad records expected 'true' or 'false', found '" + dbr
+ "'\nType 'tunnel help " + type + "' for usage.");
}
// strict schema
String ss = DshipContext.INSTANCE.get(Constants.STRICT_SCHEMA);
if (ss == null || !(ss.equals("true") || ss.equals("false"))) {
throw new IllegalArgumentException(
"Invalid parameter : strict schema expected 'true' or 'false', found '" + ss
+ "'\nType 'tunnel help " + type + "' for usage.");
}
// block size
String bs = DshipContext.INSTANCE.get(Constants.BLOCK_SIZE);
if (bs != null) {
try {
Long.valueOf(bs);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
"Illegal number 'block-size', please check config file.");
}
}
// max bad records
String mbr = DshipContext.INSTANCE.get(Constants.MAX_BAD_RECORDS);
if (mbr != null) {
try {
Long.valueOf(mbr);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
"Illegal number 'max-bad-records', please check config file.");
}
}
// resume path
String path = DshipContext.INSTANCE.get(Constants.RESUME_PATH);
File sFile = new File(path);
if (!sFile.exists()) {
throw new IllegalArgumentException("Upload File not found: '" + path
+ "'\nType 'tunnel help " + type + "' for usage.");
}
}
// dfp
String dfp = DshipContext.INSTANCE.get(Constants.DATE_FORMAT_PATTERN);
if (dfp != null) {
try {
DateTimeFormatter.ofPattern(dfp);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(
"Unsupported date format pattern '" + dfp + "'");
}
}
}