jamborta
jamborta

Reputation: 5210

project array to columns in hive

Is it possible to project an array into separate columns in hive in one step?

I have this query

select split(activity_data,":") as ad from log_table 

where the column ad contains 10 separate fields which I would like to project into 10 columns.

Upvotes: 5

Views: 17593

Answers (2)

RPaul
RPaul

Reputation: 179

I did it this way: By directly using array indexes to create separate columns in Hive:

sample table columns datatype: tbl_name(eid bigint, array<double> as spendings)

select eid, spendings[0] as spendings_1, spendings[1] as spendings_2...
from tbl_name;

Upvotes: 3

dino.keco
dino.keco

Reputation: 1401

Yes it is possible. I know there are two ways to do this:

  1. Use indices to access array elements:

    select split(activity_data,":")[0] as col1, split(activity_data,":")[1] as col2 ... from mpod_audit_log

  2. explained on this post. Explode the Array of Struct in Hive

Upvotes: 5

Related Questions