@Test
  public void testParsePercentileCont() throws Exception {
    ASTNode tree = parseDriver.parseSelect(
        "SELECT percentile_cont(0.4) WITHIN GROUP (ORDER BY val) FROM src", null).getTree();

    assertEquals(1, tree.getChildCount());
    ASTNode selExprNode = (ASTNode) tree.getChild(0);
    assertEquals(1, selExprNode.getChildCount());
    ASTNode functionNode = (ASTNode) selExprNode.getChild(0);
    assertEquals(HiveParser.TOK_FUNCTION, functionNode.getType());
    assertEquals(3, functionNode.getChildCount());

    ASTNode functionNameNode = (ASTNode) functionNode.getChild(0);
    assertEquals(HiveParser.Identifier, functionNameNode.getType());
    assertEquals("percentile_cont", functionNameNode.getText());

    ASTNode fractionNode = (ASTNode) functionNode.getChild(1);
    assertEquals(HiveParser.Number, fractionNode.getType());
    assertEquals("0.4", fractionNode.getText());

    ASTNode withinGroupNode = (ASTNode) functionNode.getChild(2);
    assertEquals(HiveParser.TOK_WITHIN_GROUP, withinGroupNode.getType());

    ASTNode orderByNode = (ASTNode) withinGroupNode.getChild(0);
    assertEquals(HiveParser.TOK_ORDERBY, orderByNode.getType());

    ASTNode tabSortColNameNode = (ASTNode) orderByNode.getChild(0);
    assertEquals(HiveParser.TOK_TABSORTCOLNAMEASC, tabSortColNameNode.getType());
  }
Test cases for parse WITHIN GROUP clause syntax.
function(expression) WITHIN GROUP (ORDER BY sort_expression)
parser/src/test/org/apache/hadoop/hive/ql/parse/TestParseWithinGroupClause.java