<?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: Help converting Teradata SQL to Hive in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Help-converting-Teradata-SQL-to-Hive/m-p/94530#M7835</link>
    <description>&lt;P&gt;Without knowing your schema, here is a rough take:&lt;/P&gt;&lt;PRE&gt;(SELECT
S.Calendar_Date Calendar_Date
,S.Foll_Monday Foll_Monday
,W.Week_Id Snapshot_Id
FROM
(
SELECT calendar_date,
(
CASE day_of_week
  WHEN 1 THEN calendar_date + 1
  WHEN 3 THEN calendar_date + 6
  WHEN 4 THEN calendar_date + 5
  WHEN 5 THEN calendar_date + 4
  WHEN 6 THEN calendar_date + 3
  WHEN 7 THEN calendar_date + 2
  ELSE calendar_date
END
) Foll_Monday
FROM td_etl.calendar )
S LEFT JOIN td_etl.dim_cal W
ON S.Foll_Monday BETWEEN W.Week_Start AND W.Week_End) FM
&lt;/PRE&gt;</description>
    <pubDate>Wed, 30 Sep 2015 00:48:40 GMT</pubDate>
    <dc:creator>deepesh1</dc:creator>
    <dc:date>2015-09-30T00:48:40Z</dc:date>
    <item>
      <title>Help converting Teradata SQL to Hive</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Help-converting-Teradata-SQL-to-Hive/m-p/94529#M7834</link>
      <description>&lt;P&gt;Can anyone help converting this Teradata SQL to something that will run in Hive? Currently it fails with the error "SemanticException Line 0:-1 Both left and right aliases encountered in JOIN 'Week_End'" and my understanding of SQL is too limited to understand how to refactor the query.&lt;/P&gt;&lt;PRE&gt;(SELECT
S.Calendar_Date Calendar_Date
,S.Foll_Monday Foll_Monday
,W.Week_Id Snapshot_Id
FROM
(
SELECT calendar_date
,CASE WHEN day_of_week = 1 THEN calendar_date + 1
WHEN day_of_week = 3 THEN calendar_date + 6
WHEN day_of_week = 4 THEN calendar_date + 5
WHEN day_of_week = 5 THEN calendar_date + 4
WHEN day_of_week = 6 THEN calendar_date + 3
WHEN day_of_week = 7 THEN calendar_date + 2
ELSE calendar_date END AS Foll_Monday
FROM td_etl.calendar )
S LEFT JOIN td_etl.dim_cal W
ON S.Foll_Monday BETWEEN W.Week_Start AND W.Week_End) FM &lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2015 23:44:07 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Help-converting-Teradata-SQL-to-Hive/m-p/94529#M7834</guid>
      <dc:creator>tstebbens</dc:creator>
      <dc:date>2015-09-29T23:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: Help converting Teradata SQL to Hive</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Help-converting-Teradata-SQL-to-Hive/m-p/94530#M7835</link>
      <description>&lt;P&gt;Without knowing your schema, here is a rough take:&lt;/P&gt;&lt;PRE&gt;(SELECT
S.Calendar_Date Calendar_Date
,S.Foll_Monday Foll_Monday
,W.Week_Id Snapshot_Id
FROM
(
SELECT calendar_date,
(
CASE day_of_week
  WHEN 1 THEN calendar_date + 1
  WHEN 3 THEN calendar_date + 6
  WHEN 4 THEN calendar_date + 5
  WHEN 5 THEN calendar_date + 4
  WHEN 6 THEN calendar_date + 3
  WHEN 7 THEN calendar_date + 2
  ELSE calendar_date
END
) Foll_Monday
FROM td_etl.calendar )
S LEFT JOIN td_etl.dim_cal W
ON S.Foll_Monday BETWEEN W.Week_Start AND W.Week_End) FM
&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2015 00:48:40 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Help-converting-Teradata-SQL-to-Hive/m-p/94530#M7835</guid>
      <dc:creator>deepesh1</dc:creator>
      <dc:date>2015-09-30T00:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: Help converting Teradata SQL to Hive</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Help-converting-Teradata-SQL-to-Hive/m-p/94531#M7836</link>
      <description>&lt;P&gt;I don't think this left join with a non equi condition will work with Hive.&lt;/P&gt;&lt;P&gt;Check the documentation I wrote for a workaround:&lt;/P&gt;&lt;P&gt;&lt;A href="https://wiki.hortonworks.com/display/IK/Hive+non+equi+left+join" target="_blank"&gt;https://wiki.hortonworks.com/display/IK/Hive+non+equi+left+join&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2015 16:48:27 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Help-converting-Teradata-SQL-to-Hive/m-p/94531#M7836</guid>
      <dc:creator>sluangsay</dc:creator>
      <dc:date>2015-09-30T16:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: Help converting Teradata SQL to Hive</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Help-converting-Teradata-SQL-to-Hive/m-p/94532#M7837</link>
      <description>&lt;P&gt;agree with Sourygna. Deepesh, did you try this.? I dont think hive currently supports non equi joins.&lt;/P&gt;&lt;P&gt;Sourygna workaround should work here.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2015 18:31:24 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Help-converting-Teradata-SQL-to-Hive/m-p/94532#M7837</guid>
      <dc:creator>mmadan</dc:creator>
      <dc:date>2015-09-30T18:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: Help converting Teradata SQL to Hive</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Help-converting-Teradata-SQL-to-Hive/m-p/94533#M7838</link>
      <description>&lt;P&gt;No, I did not test this. I basically just converted the case statement. Sourygna's point is right, the non-equi join will have to be transformed in order for this to work in Hive.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2015 22:15:18 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Help-converting-Teradata-SQL-to-Hive/m-p/94533#M7838</guid>
      <dc:creator>deepesh1</dc:creator>
      <dc:date>2015-09-30T22:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: Help converting Teradata SQL to Hive</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Help-converting-Teradata-SQL-to-Hive/m-p/94534#M7839</link>
      <description>&lt;P&gt;In this case, if we look at the &amp;lt;intent&amp;gt; of the query it is possible that it can be rewritten to not need a non-equi-join.  &lt;/P&gt;&lt;P&gt;If you can make this Assumption about the Date Dimension:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;A Date Value in the date dimension (such as 'Foll_Monday' in the query) will always be between the Week_Start and the Week_End values.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Then you should be able to rewrite the query to not use a non-equi join. The second table in the join would become: &lt;/P&gt;&lt;PRE&gt;(SELECT
S.Calendar_DateCalendar_Date
,S.Foll_MondayFoll_Monday
,W.Week_Id, Snapshot_Id
FROM
(
SELECT calendar_date,
(
CASE day_of_week
WHEN 1 THEN calendar_date +1
WHEN 3 THEN calendar_date +6
WHEN 4 THEN calendar_date +5
WHEN 5 THEN calendar_date +4
WHEN 6 THEN calendar_date +3
WHEN 7 THEN calendar_date +2
ELSE calendar_date
END
) Foll_Monday
FROM td_etl.calendar)  S 
   inner join ( 
       select &amp;lt;NaturalDateValue&amp;gt;, Week_Id, week_Start, Week_End from td_etl.dim_cal ) W
    on S.foll_monday = W.&amp;lt;NaturalDateValue&amp;gt;&lt;/PRE&gt;&lt;P&gt;Give that a try. &lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2015 00:18:08 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Help-converting-Teradata-SQL-to-Hive/m-p/94534#M7839</guid>
      <dc:creator>bpreachuk</dc:creator>
      <dc:date>2015-10-02T00:18:08Z</dc:date>
    </item>
  </channel>
</rss>

