0
点赞
收藏
分享

微信扫一扫

Hive使用中经常用到的SQL

耶也夜 2022-01-09 阅读 67
hivesql

1.表创建

1.1方式1

create table  t1(
org_id int,
banner string,
pv int,
uv int)
partitioned by(day_id string) ##分区
row format delimited fields terminated  by '\t'
stored as textfile;

1.2方式2

create table  t2 as select * from t1;

1.3方式3

create table t2 like t1;

2.表数据导出

hdfs dfs -rm /file1/fqw/*
beeline -e "insert overwrite directory '/file1/fqw/' row format delimited fields terminated by '\t' select * from t1"
hdfs dfs -cat /file1/fqw/ >sichuan.txt

3.表数据导入

hdfs dfs -put /file1/fqw/d1.dat /user/hive/warehouse/表名

4.表重命名

alter table oldname rename to newname;

5.表字段修改

alter table t1 change column  oldcolumn newcolumn 数据类型;

6.增加字段

alter table t1 add columns(fields 数据类型);

7.新增和删除分区

alter table t1 add partition(dt='');
alter table t1 drop partition(dt='');

8.向分区表插入数据

insert into table t1 partition(dt='')
select * from t2;

9.shell脚本中添加hivesql

#加入单条sql语句
beeline -e " "
#加入多条sql语句
beeline <<EOF
EOF
举报

相关推荐

0 条评论