Hive入门详解(二)

本文详细介绍了Hive的DDL和DML操作,包括创建内部表、外部表、分区表和桶表,修改表,加载数据,插入数据,选择、排序、去重、分组以及JOIN操作。此外,还探讨了Hive的排序、去重、虚拟列以及不同类型的JOIN操作的实现原理和注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

个人博客原文链接

Hive的DDL操作

创建表(四种表)
  1. 内部表
    创建产品表
create table t_product(id int,name string,price double,category string)
row format delimited
fields terminated by ','
stored as textfile;

导入数据(从本地)
load data local inpath '/home/hadoop/product_data' into table t_product;
导入数据(从hdfs)
load data inpath '/data/hive/test/product_data' into table t_product;
查看表数据
select * from t_product;
删除表
drop table t_product;

  1. 外部表
    创建手机表
create external table t_phone(id int,name string,price double)
row format delimited
fields terminated by ','
stored as textfile
location '/hive/test/'; 
注:在hdfs的指定位置上创建表

导入数据
load data local inpath '/home/hadoop/phone_data' into table t_phone;
  1. 分区表
创建表(分区表)
根据月份分区
create table t_order(id int,name string,cost double)
partitioned by (month string)
row format delimited 
fields terminated by ',';

导入数据到分区6
load data local inpath '/home/hadoop/phone_data' into table t_order
partition(month='6');

查看所有订单的分区
show partitions t_order;
  1. 桶表
创建表(桶表)
create table t_product_bucket(id int,name string ,price string,category string)
clustered by(id) into 3 buckets
row format delimited 
fields terminated by ',';

桶表汇中的数据,只能从其他表中用子查询进行插入
set hive.enforce.bucketing=true;
insert into table t_product_bucket select * from t_product;

查询2上的数据
select * from t_product_bucket tablesample(bucket 2 out of 3 on id);
创建表(其它常用表)
  1. 子查询创建表
create table t
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值