<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Irregularities in Select query in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Irregularities-in-Select-query/m-p/208686#M62843</link>
    <description>&lt;P&gt;thank you &lt;A rel="user" href="https://community.cloudera.com/users/13511/dineshchitlangia.html" nodeid="13511"&gt;@Dinesh Chitlangia&lt;/A&gt; &lt;/P&gt;&lt;P&gt;that explains it very well. &lt;/P&gt;</description>
    <pubDate>Thu, 15 Jun 2017 14:04:41 GMT</pubDate>
    <dc:creator>nrbndsdb0509</dc:creator>
    <dc:date>2017-06-15T14:04:41Z</dc:date>
    <item>
      <title>Irregularities in Select query</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Irregularities-in-Select-query/m-p/208683#M62840</link>
      <description>&lt;P&gt;I am working with the HDP2.3 Rev6 VM for a self paced course. &lt;/P&gt;&lt;P&gt;I am getting the below errors for the same query, when using aliases. &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="16299-hive-select.jpg" style="width: 977px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/16849i9AC33661CCF58FB0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="16299-hive-select.jpg" alt="16299-hive-select.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;select sum(ordertotal), year(order_date) from orders group by year(order_date)&lt;/PRE&gt;&lt;P&gt;this query works fine. &lt;/P&gt;&lt;P&gt;But if I use aliases, it fails. &lt;/P&gt;&lt;P&gt;Am I missing something? &lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Anirban. &lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2019 04:21:04 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Irregularities-in-Select-query/m-p/208683#M62840</guid>
      <dc:creator>nrbndsdb0509</dc:creator>
      <dc:date>2019-08-18T04:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: Irregularities in Select query</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Irregularities-in-Select-query/m-p/208684#M62841</link>
      <description>&lt;P&gt;While some databases like MySql and Teradata allow using column alias in GROUP BY clause, Hive does not allow this to the best of my knowledge.&lt;/P&gt;&lt;P&gt;Conceptually, GROUP BY processing happens before SELECT list computation, so it would be circular to allow such references.&lt;/P&gt;&lt;P&gt;To understand this better, use the EXPLAIN feature in Hive for your query. That will give you a logical breakdown of your query and will reveal how it is being processed &amp;amp; in what order.&lt;/P&gt;&lt;P&gt;Here is the link from official wiki - &lt;A href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Explain"&gt;https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Explain&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The above link demonstrates group by example and you will see GROUP BY processing happens before SELECT, thereby leading to the error you are facing.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Workaround&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;If you still want to write queries where you want to group by derived column, you can do it using this nifty technique.&lt;/P&gt;&lt;P&gt;Set the following property:&lt;/P&gt;&lt;PRE&gt;SET hive.groupby.orderby.position.alias=true;&lt;/PRE&gt;&lt;P&gt;This will allow you to group by columns based on the position in the select clause.&lt;/P&gt;&lt;P&gt;So instead of writing your query like this:&lt;/P&gt;&lt;PRE&gt;select sum(ordertotal), year(order_date) from orders group by year(order_date)&lt;/PRE&gt;&lt;P&gt;You can write the group by clause using position as shown below:&lt;/P&gt;&lt;PRE&gt;select sum(ordertotal), year(order_date) from orders group by 2&lt;/PRE&gt;&lt;P&gt;This will get you the desired result without having to repeat "year(order_date)" in group by clause.&lt;/P&gt;&lt;P&gt;As always, if this answers helps you, please consider accepting it.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 02:33:13 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Irregularities-in-Select-query/m-p/208684#M62841</guid>
      <dc:creator>dineshc</dc:creator>
      <dc:date>2017-06-15T02:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: Irregularities in Select query</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Irregularities-in-Select-query/m-p/208685#M62842</link>
      <description>&lt;P&gt;Couldnt Agree More with &lt;A rel="user" href="https://community.cloudera.com/users/13511/dineshchitlangia.html" nodeid="13511"&gt;@Dinesh Chitlangia&lt;/A&gt; &lt;/P&gt;&lt;P&gt;Same is the case with WHERE clause. &lt;/P&gt;&lt;P&gt;If you have alias in WHERE clause we 
will facing similarerror. &lt;/P&gt;&lt;P&gt;Reason being here clause is evaluated before the select clause, &lt;/P&gt;&lt;P&gt;select col1 as c1, col2 as c2 from test_table where c1 = "ABC"; &lt;/P&gt;&lt;P&gt;we make it work by re tweaking above query as &lt;/P&gt;&lt;P&gt;
select * from (
  select col1 as c1, col2 as c2 from test_table
) t1 where c1 = "ABC";&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 03:22:42 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Irregularities-in-Select-query/m-p/208685#M62842</guid>
      <dc:creator>sreeviswa_athic</dc:creator>
      <dc:date>2017-06-15T03:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: Irregularities in Select query</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Irregularities-in-Select-query/m-p/208686#M62843</link>
      <description>&lt;P&gt;thank you &lt;A rel="user" href="https://community.cloudera.com/users/13511/dineshchitlangia.html" nodeid="13511"&gt;@Dinesh Chitlangia&lt;/A&gt; &lt;/P&gt;&lt;P&gt;that explains it very well. &lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 14:04:41 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Irregularities-in-Select-query/m-p/208686#M62843</guid>
      <dc:creator>nrbndsdb0509</dc:creator>
      <dc:date>2017-06-15T14:04:41Z</dc:date>
    </item>
  </channel>
</rss>

