<?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: Impala Complex types: position in ARRAY of MAP in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-Complex-types-position-in-ARRAY-of-MAP/m-p/43353#M35901</link>
    <description>Any update on this? Have you created the JIRA?&lt;BR /&gt;thanks&lt;BR /&gt;</description>
    <pubDate>Fri, 29 Jul 2016 09:19:19 GMT</pubDate>
    <dc:creator>Tomas79</dc:creator>
    <dc:date>2016-07-29T09:19:19Z</dc:date>
    <item>
      <title>Impala Complex types: position in ARRAY of MAP</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-Complex-types-position-in-ARRAY-of-MAP/m-p/43207#M35897</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;how can I access the position of the element (in my case of the MAP) in the array column?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TABLE DDL:&lt;/P&gt;&lt;P&gt;CREATE TABLE mytable (&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; id int,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; location ARRAY&amp;lt; MAP&amp;lt; string, string&amp;gt; &amp;gt; )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I query the table with this SQL I got a position of the KEY-VALUE pair INSIDE the MAP, but what I really want to access is the position in the location ARRAY, e.g. 1st location, 2nd location and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select c.id, a.pos, a.key, a.value from mytable c left join c.locations a order by c.id, a.pos;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 10:31:27 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-Complex-types-position-in-ARRAY-of-MAP/m-p/43207#M35897</guid>
      <dc:creator>Tomas79</dc:creator>
      <dc:date>2022-09-16T10:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: Impala Complex types: position in ARRAY of MAP</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-Complex-types-position-in-ARRAY-of-MAP/m-p/43222#M35898</link>
      <description>&lt;P&gt;Hi Thomas,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in your example query the table alias 'a' has a 'pos' pseudo-column that refers to the element-position&amp;nbsp;within the ARRAY, so I think it's indeed what you want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I think there is a bug here that may lead to confusion.&lt;/P&gt;&lt;P&gt;The query you wrote "should" be illegal because you should not be able to access a.key and a.value without referencing the nested map in the FROM clause. I will follow-up with a JIRA, stay tuned.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you try running this and see if you get the expected results?&lt;/P&gt;&lt;P&gt;select c.id, a.pos from mytable c left join c.`location` a order by c.id, a.pos;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternatively try this query&amp;nbsp;if you also want to explode the items within the nested MAP:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;select c.id, a.pos, a.key, a.value from mytable c left join c.`location` a, a.item order by c.id, a.pos;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2016 20:57:09 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-Complex-types-position-in-ARRAY-of-MAP/m-p/43222#M35898</guid>
      <dc:creator>alex.behm</dc:creator>
      <dc:date>2016-07-26T20:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Impala Complex types: position in ARRAY of MAP</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-Complex-types-position-in-ARRAY-of-MAP/m-p/43242#M35899</link>
      <description>&lt;P&gt;Hi, &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; thanks for the response, yes it seems to be a bug. You can test it yourself, here are the scripts to reproduce:&lt;/P&gt;&lt;P&gt;(in Hive, "i" is just a dummy table):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;create table mytable( id int, locations array&amp;lt; map&amp;lt;string,string&amp;gt;&amp;gt;) stored as parquet;

insert into table mytable select 10001, array( map("Location1.City","Bratislava","Location1.Country","SK","Location1.LAT","41"), map("Location2.City","Kosice","Location2.Country","SK","Location2.LAT","42") ) from i limit 1;

insert into table mytable select 10002, array( map("Location1.City","Wien","Location1.Country","AT","Location1.LAT","40"), map("Location2.City","Graz","Location2.Country","AT","Location2.LAT","40") ) from i limit 1;&lt;/PRE&gt;&lt;P&gt;Query results in Impala:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sql1.PNG" style="width: 600px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/1947i1E7CDA2A6B347023/image-size/large?v=v2&amp;amp;px=999" role="button" title="sql1.PNG" alt="sql1.PNG" /&gt;&lt;/span&gt;﻿&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sql2.PNG" style="width: 600px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/1948i23EA8B90EF23037A/image-size/large?v=v2&amp;amp;px=999" role="button" title="sql2.PNG" alt="sql2.PNG" /&gt;&lt;/span&gt;﻿&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sql3.PNG" style="width: 600px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/1949i767A6C8A9947672C/image-size/large?v=v2&amp;amp;px=999" role="button" title="sql3.PNG" alt="sql3.PNG" /&gt;&lt;/span&gt;﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These results are wrond, what I need is a location_number -&lt;/P&gt;&lt;P&gt;0 for Location1.City&lt;/P&gt;&lt;P&gt;0 for Location1.Country&lt;/P&gt;&lt;P&gt;0 for Location1.LAT&lt;/P&gt;&lt;P&gt;1 for Location2.City&lt;/P&gt;&lt;P&gt;1 for Location2.Country&lt;/P&gt;&lt;P&gt;1 for Location2.LAT&lt;/P&gt;&lt;P&gt;... and so on&amp;nbsp;for every ID in the table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What you suggested (adding l.item), returned a wrong result set, because City in the result set is twice, but LAT is missing - this seems to be definitely a BUG:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sql4.PNG" style="width: 600px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/1950iED4DC06A82D2A6C3/image-size/large?v=v2&amp;amp;px=999" role="button" title="sql4.PNG" alt="sql4.PNG" /&gt;&lt;/span&gt;﻿&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2016 07:43:53 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-Complex-types-position-in-ARRAY-of-MAP/m-p/43242#M35899</guid>
      <dc:creator>Tomas79</dc:creator>
      <dc:date>2016-07-27T07:43:53Z</dc:date>
    </item>
    <item>
      <title>Re: Impala Complex types: position in ARRAY of MAP</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-Complex-types-position-in-ARRAY-of-MAP/m-p/43246#M35900</link>
      <description>&lt;P&gt;In Hive the solution is:&lt;/P&gt;&lt;PRE&gt;select id, ix, locations.key, locations.val from ( select id, ix, locs from mytable lateral view posexplode( locations ) x as ix,locs ) tab lateral view explode( locs ) locations as key,val;&lt;/PRE&gt;&lt;P&gt;which returns the correct result set:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sql5.PNG" style="width: 471px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/1951i78D267A7332E98E5/image-size/large?v=v2&amp;amp;px=999" role="button" title="sql5.PNG" alt="sql5.PNG" /&gt;&lt;/span&gt;﻿&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2016 08:34:28 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-Complex-types-position-in-ARRAY-of-MAP/m-p/43246#M35900</guid>
      <dc:creator>Tomas79</dc:creator>
      <dc:date>2016-07-27T08:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: Impala Complex types: position in ARRAY of MAP</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-Complex-types-position-in-ARRAY-of-MAP/m-p/43353#M35901</link>
      <description>Any update on this? Have you created the JIRA?&lt;BR /&gt;thanks&lt;BR /&gt;</description>
      <pubDate>Fri, 29 Jul 2016 09:19:19 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-Complex-types-position-in-ARRAY-of-MAP/m-p/43353#M35901</guid>
      <dc:creator>Tomas79</dc:creator>
      <dc:date>2016-07-29T09:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: Impala Complex types: position in ARRAY of MAP</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-Complex-types-position-in-ARRAY-of-MAP/m-p/43369#M35902</link>
      <description>&lt;P&gt;Still investigating and working on the JIRA. In the meantimg, I think the query that you mean is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select t.id, l.pos as location_number, m.key, m.value from mytable t join t.locations l join l.item m order by id, l.pos;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The bug is that those queries returning wrong results are not semantically correct but Impala runs them anyway and gives "arbitrary" results.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2016 18:57:18 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-Complex-types-position-in-ARRAY-of-MAP/m-p/43369#M35902</guid>
      <dc:creator>alex.behm</dc:creator>
      <dc:date>2016-07-29T18:57:18Z</dc:date>
    </item>
    <item>
      <title>Re: Impala Complex types: position in ARRAY of MAP</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-Complex-types-position-in-ARRAY-of-MAP/m-p/43372#M35903</link>
      <description>&lt;P&gt;Filed the JIRA:&amp;nbsp;&lt;A href="https://issues.cloudera.org/browse/IMPALA-3938" target="_blank"&gt;https://issues.cloudera.org/browse/IMPALA-3938&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for your detailed report and easy reproduction!&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2016 19:09:15 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Impala-Complex-types-position-in-ARRAY-of-MAP/m-p/43372#M35903</guid>
      <dc:creator>alex.behm</dc:creator>
      <dc:date>2016-07-29T19:09:15Z</dc:date>
    </item>
  </channel>
</rss>

