Hive数据类型

原生数据类型

准备数据

查看表信息

加载数据

查看数据

复杂数据类型-数组

准备数据

查看数据

​优化

复杂数据类型-map

准备数据

查看数据

复杂数据类型-默认分隔符

准备数据

查看数据


原生数据类型

准备数据

bash 复制代码
-- 1 建库
drop database if exists db_1 cascade;
create database if not exists db_1;
use db_1;

-- 2 建表
create table tb_archer(
    id int comment "ID",
    name string comment "英雄名称",
    hp_max int comment "最大生命",
    mp_max int comment "最大法力",
    attack_max int comment "最高物攻",
    defense_max int comment "最大物防",
    attack_range string comment "攻击范围",
    role_main string comment "主要定位",
    role_assist string comment "次要定位"
)
comment '射手表'
row format delimited fields terminated by '\t'
;

查看表信息

bash 复制代码
-- 查看表的信息
desc db_1.tb_archer;

-- 查看表的详细信息
desc formatted db_1.tb_archer;

加载数据

方式一:从本地加载到hdfs上

方式二:使用load命令将本地文件传到hdfs上

bash 复制代码
load data local inpath '/root/honor_of_kings/01_archer.txt' into table db_1.tb_archer_2;

方式三:使用load命令在hdfs上移动文件

bash 复制代码
-- 方式三:使用load命令将hdfs上的一个文件传到另一个目录下(这个是剪切效果,之前的文件将会没有)
load data inpath '/data/honor_of_kings/01_archer.txt' into table db_1.tb_archer_3;

hdfs没传之前

传之后

查看数据

bash 复制代码
select * from db_1.tb_archer;

复杂数据类型-数组

使用delimited关建字

复制代码
row format delimited fields terminated by ',' :每个列之间分割
collection items terminated by '-':集合之间的元素分割
map keys terminated by ':' :键值对之间分割
lines terminated by '\n':每行数据分割

准备数据

bash 复制代码
-- 创建表
create table db_1.tb_user(
    id int,
    name string,
    hobbys string
)
row format delimited fields terminated by ','
;

-- 加载数据
load data local inpath '/root/users.txt' into table db_1.tb_user;

-- 查看数据-
select * from db_1.tb_user;

查看数据

通过制定分隔符转化成数组

bash 复制代码
-- 节选最后一列的爱好
select
    id,
    name,
    hobbys,
    split(hobbys, '-'),
    split(hobbys, '-')[0],
    split(hobbys, '-')[1],
    split(hobbys, '-')[2]
from db_1.tb_user;
优化

加上delimited关建字,使用row format delimited来处理单分隔符问题

bash 复制代码
-- 创建表
create table db_1.tb_user_2 (
    id int,
    name string,
    hobbys array<string>
)
row format delimited fields terminated by ',' --每列之间用','分割
collection items terminated by '-'  -- 集合之间的元素用','分割
;

-- 加载数据
load data local inpath '/root/users.txt' into table db_1.tb_user_2;

-- 查看数据
select
    id,
    name,
    hobbys,
    hobbys[0],
    hobbys[1],
    hobbys[2]
from db_1.tb_user_2;

复杂数据类型-map

准备数据

bash 复制代码
-- 创建表
create table t_hot_hero_skin_price(
    id int,
    name string,
    win_rate int,
    skin_price map<string,int>
)
row format delimited fields terminated by ','
collection items terminated by '-'
map keys terminated by ':'  -- 键值对之间用':'分割
;

-- 加载数据
load data local inpath '/root/honor_of_kings/02_hot_hero_skin_price.txt' into table t_hot_hero_skin_price;

查看数据

bash 复制代码
-- 查看全部数据
select * from t_hot_hero_skin_price;

指定数据:查看id=1的"大圣娶亲"和"至尊宝"的皮肤价格。

bash 复制代码
select
    *,
    skin_price['大圣娶亲'],
    skin_price['至尊宝']
from t_hot_hero_skin_price
where id=1
;

复杂数据类型-默认分隔符

准备数据

bash 复制代码
-- 创建表
create table tb_team_ace_player(
    id int,
    team_name string,
    ace_player_name string
);

-- 加载数据
load data local inpath '/root/honor_of_kings/03_team_ace_player.txt' into table db_1.tb_team_ace_player;

查看数据

bash 复制代码
select * from db_1.tb_team_ace_player;

默认分隔符是^A

相关推荐
Lx3521 天前
Hadoop数据处理优化:减少Shuffle阶段的性能损耗
大数据·hadoop
Lx3522 天前
Hadoop容错机制深度解析:保障作业稳定运行
大数据·hadoop
IT毕设梦工厂3 天前
大数据毕业设计选题推荐-基于大数据的客户购物订单数据分析与可视化系统-Hadoop-Spark-数据可视化-BigData
大数据·hadoop·数据分析·spark·毕业设计·源码·bigdata
大数据CLUB3 天前
基于spark的澳洲光伏发电站选址预测
大数据·hadoop·分布式·数据分析·spark·数据开发
计算机编程小央姐3 天前
跟上大数据时代步伐:食物营养数据可视化分析系统技术前沿解析
大数据·hadoop·信息可视化·spark·django·课程设计·食物
IT学长编程3 天前
计算机毕业设计 基于Hadoop的健康饮食推荐系统的设计与实现 Java 大数据毕业设计 Hadoop毕业设计选题【附源码+文档报告+安装调试】
java·大数据·hadoop·毕业设计·课程设计·推荐算法·毕业论文
Lx3523 天前
Hadoop数据一致性保障:处理分布式系统常见问题
大数据·hadoop
IT学长编程3 天前
计算机毕业设计 基于Hadoop豆瓣电影数据可视化分析设计与实现 Python 大数据毕业设计 Hadoop毕业设计选题【附源码+文档报告+安装调试
大数据·hadoop·python·django·毕业设计·毕业论文·豆瓣电影数据可视化分析
Dobby_053 天前
【Hadoop】Yarn:Hadoop 生态的资源操作系统
大数据·hadoop·分布式·yarn