03分布式数据仓库 HIVE -- 数据的相关操作

本文介绍了Hive的基本命令和数据操作方法,包括通过不同方式执行Hive SQL语句、创建内部表和外部表的方法,以及如何向表中插入数据。此外,还详细解释了分区表的使用场景和具体操作步骤。

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

执行hive语句的方式

1:cli(command line interface)

2:jdbc

3:beeline

4:hwi


1 hive -命令(和hql执行有关)


hive -V(-S) -e "select * from user" > /home/data;              //  -e 在linux下直接运行hql


hive -f "/home/hql.txt";                    //-f 执行hql的文件。


-命令,主要用于shell 脚本开发。

#!/bin/base

name='liguozhong';

hive -e "select * from user where name = &{name}";


sh user.sh

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

2 hive --命令(和服务,程序有关)



------------------------------------------------------------------------------------------------------------------------------------------------------------------------

3 hive进入hivecli界面

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

往表里面插数据

1内部表

1.1 :

create table user as select name,age form student;     //从student加载数据,同时拷贝表结构。

1.2:

create table user(

name string,

sex int,

age int

)

row format delimited fields terminated by '\t' as textfile location ‘/home/data.txt’;

1.3:

load data local inpath '/home/data/user.txt' overwrite into table user;     //overwrite覆盖原始文件。非overwrite

1.4:

load data inpath '/home/data/user.txt' overwrite into table user;     //剪切过去,不是复制过去。

1.5:

hadoop fs -copyFromLocal /home/local /hd/data;

1.6:

insert into(overwrite) table user

select name,age from student

where sex = 1;


2外部表

2.1:

create table user(

name string,

sex int,

age int

)

row format delimited fields terminated by '\t' as textfile location ‘/home/data.txt’; //指定目录就可以加载了。


2.2:

insert into(overwrite) table user

select name,age from student

where sex = 1;


3分区表(企业中实际使用,就是用这种。)


3.1:

load data local inpath '/home/data/user.txt' overwrite into table user partition(dt='20140405');     //overwrite覆盖原始文件。非overwrite

3.2:

load data inpath '/home/data/user.txt' overwrite into table userr partition(dt='20140405');    //剪切过去,不是复制过去。

3.3

insert into(overwrite) table user partition(dt='20140405')

select name,age from student

where sex = 1;







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值