in odps-console-resource/src/main/java/com/aliyun/openservices/odps/console/resource/DropFunctionCommand.java [98:154]
public static DropFunctionCommand parse(String commandString, ExecutionContext sessionContext)
throws ODPSConsoleException {
// 1. check match
String[] args = CommandParserUtils.getCommandTokens(commandString);
if (args.length < 2) {
return null;
}
boolean matchDrop = "DROP".equalsIgnoreCase(args[0]) && "FUNCTION".equalsIgnoreCase(args[1]);
boolean matchDelete = "DELETE".equalsIgnoreCase(args[0]) && "FUNCTION".equalsIgnoreCase(args[1]);
if (!matchDelete && !matchDrop) {
return null;
}
// 2. parse
Coordinate coordinate;
String project = null;
String function = null;
boolean checkExists = false;
CommandWithOptionP cmdP = new CommandWithOptionP(commandString);
// get -p
if (matchDelete) {
project = cmdP.getProjectValue();
args = cmdP.getArgs();
}
// get functionName and ifExists
if (args.length == 3) {
// DROP FUNCTION NAME
function = args[2];
} else if (args.length == 5) {
// DROP FUNCTION IF EXISTS NAME
boolean matchIfExists = "IF".equalsIgnoreCase(args[2]) &&
"EXISTS".equalsIgnoreCase(args[3]);
if (!matchIfExists) {
throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND);
}
function = args[4];
checkExists = true;
} else {
throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND);
}
// set project.schema.function
if (matchDelete) {
if (function.contains(".")) {
// DELETE CMD not support pj.schema.function grammar
throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND);
}
coordinate = Coordinate.getCoordinateOptionP(project, function);
} else {
coordinate = Coordinate.getCoordinateABC(function);
}
return new DropFunctionCommand(checkExists, coordinate, commandString, sessionContext);
}