Use of split(), expand() and lateral view() functions in hive

chnhbhndchngn 2022-02-13 08:18:19 阅读数:222

use split expand lateral view

Suppose there is a table movie, The data is

split() function

  So use split() The method can category The entire string of the field becomes an array array type , as follows :

> select movie, split(category, ",") from movie;

 explode() function

Use explode() Function can change a row array into a multi row array , as follows :

> select explode(split(category, ",")) from movie;

  If you want to connect with the name of the film , Can we output the following results together ,

Let's try :

> select movie, explode(split(category, ",")) from movie;

It turned out to be wrong , You can't use it like this

  One select You can only get one explode The resulting view , If you want to display multiple columns , You need to merge multiple views .
lateral view That's what I do

lateral  view() function

select movie, tmp_col from movie
lateral view explode(split(category, ",")) tmp_view as tmp_col;

 

copyright:author[chnhbhndchngn],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130818167633.html