Hive数据类型(基本数据类型+集合数据类型)

本文通过一个实例展示了在Hive中如何创建和操作包含基本数据类型的表,包括STRING、ARRAY、MAP和STRUCT。具体操作涉及创建测试表、导入数据及查询ARRAY、MAP和STRUCT字段的详细步骤,适合大数据处理初学者理解Hive集合数据类型的使用。
摘要由CSDN通过智能技术生成

基本数据类型

在这里插入图片描述

集合数据类型

在这里插入图片描述

案例实操

1.Hive 上创建测试表 test

create table test(
name string,
friends array<string>,
children map<string, int>,
address struct<street:string, city:string>
)
row format delimited fields terminated by ','
collection items terminated by '_'
map keys terminated by ':'
lines terminated by '\n';

2.创建本地测试文件 test.txt

songsong,bingbing_lili,xiao song:18_xiaoxiao song:19,hui long
guan_beijing
yangyang,caicai_susu,xiao yang:18_xiaoxiao yang:19,chao yang_beijing

3.导入文本数据到测试表

load data local inpath '/opt/module/hive/datas/test.txt' into table test;

4.访问三种集合列里的数据,以下分别是 ARRAY,MAP,STRUCT 的访问方式

hive (default)> select friends[1],children['xiao song'],address.city from test
where name="songsong";
OK
_c0 _c1 city
lili 18 beijing
Time taken: 0.076 seconds, Fetched: 1 row(s)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值