Hive Columns to Rows: Explode Function Guide

In Hive, you can use Lateral View operation and explode function to achieve the functionality of transforming columns into rows. The specific steps are as follows:

  1. The Lateral View operation is used to split a single column into multiple rows. For example, if there is a column containing an array, the Lateral View can be used to split the elements of the array into multiple rows of data.
SELECT column1, column2, exploded_column
FROM table_name
LATERAL VIEW explode(array_column) exploded_table AS exploded_column;
  1. Utilize the explode function to split the array into multiple lines. This function is used to break the array into multiple lines, with each line containing one array element.
SELECT column1, column2, exploded_column
FROM table_name
LATERAL VIEW explode(array_column) exploded_table AS exploded_column;

Using the two methods mentioned above, it is possible to achieve the functionality of converting columns to rows in Hive.

bannerAds