title: Hive: More clean way to SELECT AS and GROUP BY
body: <p>I try to write Hive Sql like that</p>
  
  <pre><code>SELECT count(1), substr(date, 1, 4) as year
  FROM ***
  GROUP BY year
  </code></pre>
  
  <p>But Hive cannot recognize the alias name 'year', it complains that:
  FAILED: SemanticException [Error 10004]: Line 1:79 Invalid table alias or column reference 'year'</p>
  
  <p>One solution(<a href="https://stackoverflow.com/questions/12600049/hive-select-as-and-group-by">Hive: SELECT AS and GROUP BY</a>) suggest to use 'GROUP BY substr(date, 1, 4)'.</p>
  
  <p>It works!
  However in some cases <strong>the value I want to group by may be generated from multiple lines of hive function code</strong>, it's very ugly to write code like</p>
  
  <pre><code>SELECT count(1), func1(func2(..........................)) AS something
  FROM ***
  GROUP BY func1(func2(..........................))
  </code></pre>
  
  <p>Is there any clean way in Hive to do that? Any suggestions?</p>