in odps-console-tunnel/src/main/java/com/aliyun/openservices/odps/console/tunnel/TunnelCommand.java [161:222]
private static String transformIntoDshipCommand(String tableName, String partitionSpec,
String filename, boolean isUpload)
throws ODPSConsoleException {
StringBuilder dshipCommandBuilder = new StringBuilder();
dshipCommandBuilder.append(DSHIP_COMMAND);
dshipCommandBuilder.append(" ");
if (isUpload) {
dshipCommandBuilder.append(DSHIP_SUBCOMMAND_UPLOAD);
} else {
dshipCommandBuilder.append(DSHIP_SUBCOMMAND_DOWNLOAD);
}
dshipCommandBuilder.append(" ");
// Handle tunnel command configurations
Config config = Config.getConfig();
String charset = config.getCharset();
String datetimeFormat = config.getDateFormat();
Character colDelimiter = config.getColDelimiter();
Character rowDelimiter = config.getRowDelimiter();
String nullIndicator = config.getNullIndicator();
dshipCommandBuilder.append(DSHIP_OPTION_CHARSET);
dshipCommandBuilder.append(formatArgument(charset));
dshipCommandBuilder.append(DSHIP_OPTION_DATETIME_FORMAT_PATTERN);
dshipCommandBuilder.append(formatArgument(datetimeFormat));
dshipCommandBuilder.append(DSHIP_OPTION_FIELD_DELIMITER);
dshipCommandBuilder.append(formatArgument(colDelimiter));
dshipCommandBuilder.append(DSHIP_OPTION_RECORD_DELIMITER);
dshipCommandBuilder.append(formatArgument(rowDelimiter));
dshipCommandBuilder.append(DSHIP_OPTION_NULL_INDICATOR);
dshipCommandBuilder.append(formatArgument(nullIndicator));
if (isUpload) {
Boolean discardBadRecord = config.isBadDiscard();
dshipCommandBuilder.append(DSHIP_OPTION_DISCARD_BAD_RECORDS);
dshipCommandBuilder.append(formatArgument(discardBadRecord.toString()));
Long maxSize = config.getMaxSize();
// Check if max size is violated
File fileToUpload = new File(filename);
if (fileToUpload.exists() && fileToUpload.length() > maxSize) {
throw new ODPSConsoleException("file size exceed " + maxSize / 1024 / 1024 + "M");
} else if (!fileToUpload.exists()) {
throw new ODPSConsoleException("file not found.");
}
}
// Handle table name, partition spec and file name
String tableAndPartition = tableName;
if (!StringUtils.isNullOrEmpty(partitionSpec)) {
tableAndPartition += "/" + partitionSpec;
}
if (isUpload) {
dshipCommandBuilder.append(filename);
dshipCommandBuilder.append(" ");
dshipCommandBuilder.append(tableAndPartition);
} else {
dshipCommandBuilder.append(tableAndPartition);
dshipCommandBuilder.append(" ");
dshipCommandBuilder.append(filename);
}
return dshipCommandBuilder.toString();
}