private AlterTableCompactDesc parseAndAnalyzeAlterTable(String query) throws Exception {
    ParseDriver hd = new ParseDriver();
    ASTNode head = (ASTNode)hd.parse(query).getTree().getChild(0);
    BaseSemanticAnalyzer a = SemanticAnalyzerFactory.get(queryState, head);
    a.analyze(head, new Context(conf));
    List<Task<?>> roots = a.getRootTasks();
    Assert.assertEquals(1, roots.size());
    return (AlterTableCompactDesc)((DDLWork)roots.get(0).getWork()).getDDLDesc();
  }
Tests for parsing and semantic analysis of ALTER TABLE ... compact.
ql/src/test/org/apache/hadoop/hive/ql/parse/TestQBCompact.java