IMPALA-1203: Correlated agg subquery may be incorrectly rewritten if it
has a LIMIT clause

This commit fixes the issue where a correlated subquery with a LIMIT
clause produces wrong results. Correlated IN and EXISTS subqueries are
rejected if they contain a LIMIT clause because there is no correct
rewrite. For correlated agg subqueries the LIMIT clause is removed
because it does not affect the results.

Change-Id: I8eaaf57f2a9b7ec09a42ebf4c4231e9509706e8c
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/4192
Reviewed-by: Dimitris Tsirogiannis <dtsirogiannis@cloudera.com>
Tested-by: Dimitris Tsirogiannis <dtsirogiannis@cloudera.com>
Address Marcel's CR comments on analytic functions.

Change-Id: Ic2bf6412a6cc78a17fdb881d8d96448f5c965fce
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/4252
Reviewed-by: Marcel Kornacker <marcel@cloudera.com>
Tested-by: jenkins
Analytic tests without explicit final ordering should verify after sorting

Change-Id: Ic4ebd15af0d027eaded62f181e74bf41de93310a
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/4264
Reviewed-by: Matthew Jacobs <mj@cloudera.com>
Tested-by: jenkins