ShowPartitionsCommand extends AbstractCommand { public static ShowPartitionsCommand parse(String cmd, ExecutionContext cxt) throws ODPSConsoleException { if (cmd == null || cxt == null) { return null; } ShowPartitionsCommand r = null; Matcher m = PATTERN.matcher(cmd); Matcher pubMatcher = PUBLIC_PATTERN.matcher(cmd); boolean match = m.matches(); boolean pubMatch = pubMatcher.matches(); TablePart tablePart = null; if (!match && !pubMatch) { return r; } if (pubMatch) { tablePart = getTablePartFromPublicCommand(pubMatcher.group(2)); } else { tablePart = ODPSConsoleUtils.getTablePart(m.group(1)); } if (tablePart == null || tablePart.tableName == null) { throw new ODPSConsoleException(ErrorCode.INVALID_COMMAND + ": Invalid syntax - SHOW PARTITIONS [project.]<table>[ partition(partitionSpec)];"); } String[] tableSpec = ODPSConsoleUtils.parseTableSpec(tablePart.tableName); String project = tableSpec[0]; String table = tableSpec[1]; r = new ShowPartitionsCommand(cmd, cxt, project, table, tablePart.partitionSpec); return r; } ShowPartitionsCommand(String cmd, ExecutionContext cxt, String project, String table,
                               String partition); static void printUsage(PrintStream stream); @Override void run(); static ShowPartitionsCommand parse(String cmd, ExecutionContext cxt); static TablePart getTablePartFromPublicCommand(String target); static final String[] HELP_TAGS; }
@Test public void testPositive() throws ODPSConsoleException { ExecutionContext ctx = ExecutionContext.init(); for (String cmd : positives) { assertNotNull(ShowPartitionsCommand.parse(cmd, ctx)); } }
@Test public void testNegative() throws ODPSConsoleException { ExecutionContext ctx = ExecutionContext.init(); for (String cmd : negatives) { assertNull(ShowPartitionsCommand.parse(cmd, ctx)); } }
@Test public void testException() throws ODPSConsoleException { ExecutionContext ctx = ExecutionContext.init(); for (String cmd : exceptions) { try { ShowPartitionsCommand.parse(cmd, ctx); Assert.assertNotNull(null); } catch (ODPSConsoleException e) { } } }