hive操作

数据库的操作

创建数据库并设置存储路径

create database testdb2
location '/user/mydb';

建库的同时,添加注释

create database testdb2
comment 'This is test database';

查看数据库

describe database testdb2;

创建带键值对的数据库

create database testdb4
with dbproperties('creator'='zenggang', 'date'='2020-12-14');

查看带键值对的数据库

describe database extended testdb4;

存在便删除数据库

drop database if exists testdb4;

表的操作

外部表

创建外部表

create external table external_table (dummy string)
location '/user/tom/external_table';

读取hdfs系统文件数据到外部表中

load data inpath '/user/tom/data01.txt' into table external_table;

读取本地文件数据到外部表中

load data local inpath '/home/hadoop/data02.txt' into table external_table
load data local inpath '/home/hadoop/data02.txt' overwrite into table external_table

分区表

创建分区表

create table partition_table (id int, name string, city string)
partitioned by (pt string)
row format delimited fields terminated by '\t';

读取本地文件数据到分区表中

load data local inpath 'data02.txt' overwrite into table partition_table partition(pt='02')

查询分区的方法

show partitions 表名;

修改分区的名称

alter table 表名 partition(partition_column=value)
rename to partition(partition_column=value)

增加表字段

alter table user add columns
(address string,
tel string,
qq string,
birthday date);

修改表的字段(名字以及数据类型)

alter table user change address addr int;

查询结果添加到新表

create table login2(uid string);
insert into overwrite table login2 select id from partition_table;

查询结果输出到文件系统中

from login
insert overwrite local directory '/home/hadoop/login' select *
insert overwrite directory '/tmp/ip' select ip;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值