You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by Techy Teck <co...@gmail.com> on 2012/08/11 05:04:28 UTC

Exploding Array of String in Hive

Below is the data in *favorite_result (datatype: array<string>) *column.
Its an array of String in hive-

["CARS%20500%2E00","cars","VAN%2C%20Under%20£1%2C000%2E00%20Ending%20within%202%20days","COM%20VE","SNAP%20ON%20-LENS%20-BATTERY%20-BELT%20-PHONE%20-IPHONE","Under%20£100%2E00","","","",""]


How I can explode this above string in hive?

Re: Exploding Array of String in Hive

Posted by Bejoy KS <be...@yahoo.com>.
Hi Raihan

To fetch an element of an Array you can just specify the position of the element in your query.

Say if you have a table like
'test_table' with a field 'arr_clmn Array<STRING>', you can get the first element of the array as

SELECT arr_clmn[0] FROM test_table;

Or if you are looking at exploding the row itself to multiple rows you can do so with

SELECT * FROM test_table LATERAL VIEW explode(arr_clmn) exp_arr AS arr_elmnt;

HTH

Regards
Bejoy KS

Sent from handheld, please excuse typos.

-----Original Message-----
From: Techy Teck <co...@gmail.com>
Date: Fri, 10 Aug 2012 20:22:26 
To: <us...@hive.apache.org>
Reply-To: user@hive.apache.org
Subject: Re: Exploding Array of String in Hive

Basically How can I get each String outside, something like
*favorite_result [3]
should return *"VAN%2C%20Under%20£1%2C000%2E00%20Ending%20within%202%20days",



On Fri, Aug 10, 2012 at 8:04 PM, Techy Teck <co...@gmail.com> wrote:

> Below is the data in *favorite_result (datatype: array<string>) *column.
> Its an array of String in hive-
>
>
> ["CARS%20500%2E00","cars","VAN%2C%20Under%20£1%2C000%2E00%20Ending%20within%202%20days","COM%20VE","SNAP%20ON%20-LENS%20-BATTERY%20-BELT%20-PHONE%20-IPHONE","Under%20£100%2E00","","","",""]
>
>
> How I can explode this above string in hive?
>


Re: Exploding Array of String in Hive

Posted by Techy Teck <co...@gmail.com>.
Basically How can I get each String outside, something like
*favorite_result [3]
should return *"VAN%2C%20Under%20£1%2C000%2E00%20Ending%20within%202%20days",



On Fri, Aug 10, 2012 at 8:04 PM, Techy Teck <co...@gmail.com> wrote:

> Below is the data in *favorite_result (datatype: array<string>) *column.
> Its an array of String in hive-
>
>
> ["CARS%20500%2E00","cars","VAN%2C%20Under%20£1%2C000%2E00%20Ending%20within%202%20days","COM%20VE","SNAP%20ON%20-LENS%20-BATTERY%20-BELT%20-PHONE%20-IPHONE","Under%20£100%2E00","","","",""]
>
>
> How I can explode this above string in hive?
>