'Use named_struct function in Hive with all the columns of a table
In Hive, you can use a function named_struct in order to create a list of key value pairs; the keys are usually the column names and the values are the values in the corresponding column. For example,
$hive> select id, named_struct('foo', name, 'address', address) as list from users;
id list
1 {'foo':'Alice', 'address':'Wonderland'}
2 {'foo':'Bob', 'address':'Portland'}
...
However, in order to make the list, I needed to explicitly write each column name. Is there any way to avoid doing this with either named_struct or some other similar function?
I expect to be able to write something like (assuming users has only three columns).
$hive> select id, named_struct(*) as list from users;
Solution 1:[1]
Since you are using all columns you don't need a named_struct. Something like struct("*") will work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Soundararajan |
