Handle analytic functions in subqueries

With this commit we add proper checks to examine if a subquery
containing an analytic function is eligible for rewrite by transforming
it into a join.

Change-Id: Icf87c3040cf83ca0676d292ce81ea2c3e03cf7b3
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/4277
Reviewed-by: Dimitris Tsirogiannis <dtsirogiannis@cloudera.com>
Tested-by: jenkins