CompactCommand extends MultiClusterCommandBase { public static CompactCommand parse(String commandString, ExecutionContext sessionContext) throws ODPSConsoleException { String regstr = "\\s*ALTER\\s+TABLE\\s+(.*)\\s+COMPACT\\s+(.*)"; Pattern p = Pattern.compile(regstr, Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(commandString); if (m.find()) { String tablePart = m.group(1).trim(); String compactType = getCompactType(m.group(2).trim()); if (compactType == null) { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "Compact type should be MAJOR or MINOR."); } return new CompactCommand(tablePart, compactType, sessionContext); } return null; } CompactCommand(String command, String compactType, ExecutionContext context); static void printUsage(PrintStream stream); void run(); String getTaskName(); String getInstanceId(); static CompactCommand parse(String commandString, ExecutionContext sessionContext); static final String[] HELP_TAGS; }
@Test public void test() throws Exception { CompactCommand compactCommand = null; ExecutionContext context = ExecutionContext.init(); for (String cmd : positive) { compactCommand = CompactCommand.parse(cmd, context); assertNotNull(compactCommand); } int errorCount = 0; for (String cmd : negative) { try { compactCommand = CompactCommand.parse(cmd, context); } catch (ODPSConsoleException e) { ++ errorCount; } } Assert.assertEquals(errorCount, negative.length); }