<?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: Hierarchy in Hive in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Hierarchy-in-Hive/m-p/405903#M252516</link>
    <description>&lt;P&gt;To provide the exact HQL query, Please share the following :&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;DDL for both the tables&lt;/LI&gt;&lt;LI&gt;Sample records from each table&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;The expected output based on the sample data.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;The above information will help to understand the problem statement better and validate the solution.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 11 Apr 2025 05:44:23 GMT</pubDate>
    <dc:creator>ggangadharan</dc:creator>
    <dc:date>2025-04-11T05:44:23Z</dc:date>
    <item>
      <title>Hierarchy in Hive</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hierarchy-in-Hive/m-p/405891#M252513</link>
      <description>&lt;P&gt;Hi, new to Hive and SQL. So please be patient.&lt;/P&gt;&lt;P&gt;I've got a dataset with 2 tables:&lt;/P&gt;&lt;P&gt;1. organisations - contains names of the organisations and an id&lt;BR /&gt;2. relationships -&amp;nbsp;contains id of the organisations which organisation is it related to, ie a superior&lt;/P&gt;&lt;P&gt;i've got a query to show the immediate relationship next to each other:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SELECT sub.organisation_id, sub.organisation_name, sup.organisation_id, sup.organisation_name
FROM organisation sup
JOIN relationship
ON sup.organisation_id = relationship_id
JOIN organisation sub
ON organisation_id = relationship_orgid&lt;/LI-CODE&gt;&lt;P&gt;How do I query this using Hive (or Impala) to display all the organisations in the ancestry? E.g.,&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;baby -&amp;gt; mother -&amp;gt; grandmother -&amp;gt; great-grandmother -&amp;gt; great-great-grandmother -&amp;gt; etc.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Apr 2025 22:28:52 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hierarchy-in-Hive/m-p/405891#M252513</guid>
      <dc:creator>JediBrooker</dc:creator>
      <dc:date>2025-04-10T22:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: Hierarchy in Hive</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hierarchy-in-Hive/m-p/405895#M252514</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/125617"&gt;@JediBrooker&lt;/a&gt;&amp;nbsp;Welcome to the Cloudera Community!&lt;BR /&gt;&lt;BR /&gt;To help you get the best possible solution, I have tagged our Hive experts &lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/92016"&gt;@ggangadharan&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/70785"&gt;@Shmoo&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/45798"&gt;@james_jones&lt;/a&gt;&amp;nbsp;who may be able to assist you further.&lt;BR /&gt;&lt;BR /&gt;Please keep us updated on your post, and we hope you find a satisfactory solution to your query.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Apr 2025 22:59:04 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hierarchy-in-Hive/m-p/405895#M252514</guid>
      <dc:creator>DianaTorres</dc:creator>
      <dc:date>2025-04-10T22:59:04Z</dc:date>
    </item>
    <item>
      <title>Re: Hierarchy in Hive</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hierarchy-in-Hive/m-p/405896#M252515</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/125617"&gt;@JediBrooker&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;The query that you could use should be something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;   WITH org_hierarchy_anchor AS (
     SELECT 
       sup.organisation_id AS sup_id,
       sup.organisation_name AS sup_name,
       sub.organisation_id AS sub_id,
       sub.organisation_name AS sub_name,
       CAST(sub.organisation_name AS STRING) AS hierarchy_path
     FROM organisation sup
     JOIN relationship r ON sup.organisation_id = r.relationship_id
     JOIN organisation sub ON r.relationship_orgid = sub.organisation_id
   ),
   org_hierarchy_recursive AS (
     SELECT 
       sup_id,
       sup_name,
       sub_id,
       sub_name,
       hierarchy_path
     FROM org_hierarchy_anchor
     UNION ALL
     SELECT 
       oh.sup_id,
       oh.sup_name,
       s.organisation_id AS sub_id,
       s.organisation_name AS sub_name,
       CONCAT(oh.hierarchy_path, '-&amp;gt;', s.organisation_name) AS hierarchy_path
     FROM org_hierarchy_recursive oh
     JOIN relationship r ON oh.sub_id = r.relationship_id
     JOIN organisation s ON r.relationship_orgid = s.organisation_id
     WHERE INSTR(oh.hierarchy_path, CAST(s.organisation_name AS STRING)) = 0
   )
   SELECT sup_id, sup_name, sub_id, sub_name, hierarchy_path
   FROM org_hierarchy_recursive
   ORDER BY sup_id, sub_id;&lt;/LI-CODE&gt;&lt;P&gt;Please, check the column names and table names, I just used what you have provided here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Cristian Barrueco&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Apr 2025 00:16:06 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hierarchy-in-Hive/m-p/405896#M252515</guid>
      <dc:creator>Shmoo</dc:creator>
      <dc:date>2025-04-11T00:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: Hierarchy in Hive</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Hierarchy-in-Hive/m-p/405903#M252516</link>
      <description>&lt;P&gt;To provide the exact HQL query, Please share the following :&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;DDL for both the tables&lt;/LI&gt;&lt;LI&gt;Sample records from each table&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;The expected output based on the sample data.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;The above information will help to understand the problem statement better and validate the solution.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Apr 2025 05:44:23 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Hierarchy-in-Hive/m-p/405903#M252516</guid>
      <dc:creator>ggangadharan</dc:creator>
      <dc:date>2025-04-11T05:44:23Z</dc:date>
    </item>
  </channel>
</rss>

