hive lateral view 实践记录(Array和Map数据类型)

目录

一、Array

1.建表并插入数据

 2.lateral view explode

二、Map

1、建表并插入数据

2、lateral view explode()

3、查询数据


一、Array

1.建表并插入数据

正确插入数据:

create table tmp.test_lateral_view_movie_230829(movie string,category array<string>);insert into tmp.test_lateral_view_movie_230829 select '《战狼3》',array('战争','动作','剧情');
insert into tmp.test_lateral_view_movie_230829 select '《疑犯追踪》',array('悬疑','动作','科幻','剧情');select * from tmp.test_lateral_view_movie_230829;

原数据

 2.lateral view explode

select movie,cate_name 
from tmp.test_lateral_view_movie_230829 
lateral view explode(category) tmp_view as cate_name

结果:

 --------最开始错误的插入数据法-------

 原数据

create table tmp.test_lateral_view_movie_230828(movie string,category array<string>);select * from tmp.test_lateral_view_movie_230828;insert into tmp.test_lateral_view_movie_230828 select '《疑犯追踪》',array('悬疑,动作,科幻,剧情');
insert into tmp.test_lateral_view_movie_230828 select '《疑犯追踪2》',array('悬疑,动作,科幻,剧情');
insert into tmp.test_lateral_view_movie_230828 select '《战狼》',array('战争,动作,剧情');
insert into tmp.test_lateral_view_movie_230828 select '《战狼2》',array('战争,动作,剧情');
insert into tmp.test_lateral_view_movie_230828 select '《战狼3》',array('战争,动作,剧情');

 step1:

select 
movie
,category_detail
from tmp.test_lateral_view_movie_230828 lateral view explode(category) tmp as category_detail

step2:

select movie,category_detail_name
from 
(select movie,category_detailfrom tmp.test_lateral_view_movie_230828 lateral view explode(category) tmp as category_detail 
) a
lateral view explode(split(category_detail,',')) tmp as category_detail_name

备注:

select a.movie,split(a.category_detail,',') aaa,b.category bbb 
from 
(select movie,category_detailfrom tmp.test_lateral_view_movie_230828 lateral view explode(category) tmp as category_detail 
) a
left join 
(
select * from tmp.test_lateral_view_movie_230828
) b 
on a.movie = b.movie

比原表数据少了 双引号

综上,以上的插入数据是不对的!!!

-----------

注意:

1.array类型数据,建表时怎么插入?

array('悬疑','动作','科幻','剧情')

2.array类型的数据,怎么根据下标获取里面的值?

select movie,category[0] ,category[1] ,category[2] 
from tmp.test_lateral_view_movie_230829 

二、Map

1、建表并插入数据

--map类型测试
create table tmp.test_lateral_view_movie_230830_map(movie string,category map<string,string>);insert into tmp.test_lateral_view_movie_230830_map select '《战狼3》',str_to_map('1:战争,2:动作,3:剧情');
insert into tmp.test_lateral_view_movie_230830_map select '《疑犯追踪》',str_to_map('a:悬疑,b:动作,c:科幻,d:剧情');select * from tmp.test_lateral_view_movie_230830_map;

注:通过str_to_map()函数实现插入数据

2、lateral view explode()

selectmovie,category_id,category_name
from tmp.test_lateral_view_movie_230830_map
lateral view explode(category) tmp_view as category_id,category_name 
;

注:as 后是两个参数

结果

3、查询数据

select movie,category['1'] from tmp.test_lateral_view_movie_230830_map where movie = '《战狼3》';

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/93873.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Doris架构中包含哪些技术?

Doris主要整合了Google Mesa(数据模型)&#xff0c;Apache Impala(MPP Query Engine)和Apache ORCFile (存储格式&#xff0c;编码和压缩)的技术。 为什么要将这三种技术整合? Mesa可以满足我们许多存储需求的需求&#xff0c;但是Mesa本身不提供SQL查询引擎。 Impala是一个…

【配置环境】Visual Studio 配置 OpenCV

目录 一&#xff0c;环境 二&#xff0c;下载和配置 OpenCV 三&#xff0c;创建一个 Visual Studio 项目 四&#xff0c;配置 Visual Studio 项目 五&#xff0c;编写并编译 OpenCV 程序 一&#xff0c;环境 Windows 11 家庭中文版Microsoft Visual Studio Community 2022…

avalonia、WPF使用ScottPlot动态显示ECG心电图

文章目录 avalonia、WPF使用ScottPlot动态显示ECG心电图实现效果&#xff0c;动态效果懒得录视频了安装代码部分UpdateData方法就是用来更新心电图表的方法&#xff0c; 根据消息队列数据去更新是视图中的ScottPlot 图表 avalonia、WPF使用ScottPlot动态显示ECG心电图 avalonia…

图解 STP

网络环路 现在我们的生活已经离不开网络&#xff0c;如果我家断网&#xff0c;我会抱怨这什么破网络&#xff0c;影响到我刷抖音、打游戏&#xff1b;如果公司断网&#xff0c;那老板估计会骂娘&#xff0c;因为会影响到公司正常运转&#xff0c;直接造成经济损失。网络通信中&…

MQTT,如何在SpringBoot中使用MQTT实现消息的订阅和发布

一、MQTT介绍 1.1 什么是MQTT&#xff1f; MQTT&#xff08;Message Queuing Telemetry Transport&#xff0c;消息队列遥测传输协议&#xff09;&#xff0c;是一种基于发布/订阅&#xff08;publish/subscribe&#xff09;模式的“轻量级”通讯协议&#xff0c;该协议构建于…

使用boost::geometry::union_ 合并边界(内、外):方案二

使用boost::geometry::union_ 合并边界&#xff08;内、外&#xff09;&#xff1a;方案二 typedef boost::geometry::model::d2::point_xy<double> boost_point; typedef boost::geometry::model::polygon<boost_point> boost_Polygon;struct Point {float x;floa…

解决:burpsuite——Connection refused: no further information

出现该问题的原因是开启了SOCKS proxy&#xff1b;关闭该选项即可正常抓包。 具体操作&#xff1a;

C# PaddleDetection yolo 印章检测

效果 项目 代码 using OpenCvSharp; using OpenCvSharp.Extensions; using Sdcb.PaddleDetection; using Sdcb.PaddleInference; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq…

C语言——多文件编程

多文件编程 把函数声明放在头文件xxx.h中&#xff0c;在主函数中包含相应头文件在头文件对应的xxx.c中实现xxx.h声明的函数 防止头文件重复包含 当一个项目比较大时&#xff0c;往往都是分文件&#xff0c;这时候有可能不小心把同一个头文件 include 多次&#xff0c;或者头…

C# WPF监听USB插入拨出

可以全部监听。好用 private void FormF100WriteCortexLicense_Load(object sender, EventArgs e){this.Text this.Text " " FT_Tools.Program.version;USB USBWatcher new USB();USBWatcher.AddUSBEventWatcher(USBEventHandler, USBEventHandler, new TimeSpa…

【iOS】折叠cell

文章目录 前言一、实现效果二、折叠cell的实现原理三、实现折叠cell的高度变化四、实现选中点击的单元格总结 前言 在暑假的3GShare中用到了折叠cell控件&#xff0c;特此总结博客记录 一、实现效果 二、折叠cell的实现原理 首先我们需要知道ScrollView的是TableView的父类&a…

pytest---添加自定义命令行参数(pytest_addoption )

前言 在目前互联网公司中&#xff0c;都会存在多个测试环境&#xff0c;那么当我们编写的自动化想要在多套测试环境下进行运行时&#xff0c;如何使用&#xff1f;大多数人想到的可能是通过将我们自动化代码中的地址修改成不同环境&#xff0c;但是这时候就会增加一些工作量&am…