Hive是什么

学Hive指路《Hive编程指南》

hive:

Apache蜂巢™数据仓库软件便于阅读,写作,和管理大型数据集居住在分布式存储使用SQL。

结构可以投影到已经存储的数据上。提供了一个命令行工具和JDBC驱动程序来将用户连接到Hive。

 

存储元数据需要一个关系型数据库(一般是mysql)     一般存储表的模式和分区信息等

真正的数据存放到hdfs

hive只需要安装到一台机器上,所说的单机、伪分布和分布指的hadoop

 

11.15

数据类型

基本数据类型  P40

集合数据类型  P42

 

写时模式:

数据在写入数据库时对模式进行检查

读时模式:

不在加载时验证,数据而是在查询时验证

 

分区表

提高性能

 

创建库

create database 数据库名;

 

查看库

show databases;

模糊查询

show tablses like '正则';

查看数据库信息

describe database extended '库名';

显示所在数据库

set hive.cli.print.current.db=true

删除库如果存在(前提删除里面的表)

drop database if exists 库名;

删除库(不管里面有没有表)

drop database if exists 库名 cascade;

修改库

alert database 库名 set dbproperties('key'='value')

创建表

create table 库名.表名(

列名1 类型,

列名2 类型,

) location '库存放位置'

查看某个库里面的表

show tables in 库

分区表

create table 库名.表名(

列名1 类型,

列名2 类型,

) partitioned by(列名1 类型,列名2 类型)

禁止没有加分区过滤的任务提交

set hive.mapred.mode=strict

 

删除表(如果表存在删除,不存在也不会报错)

drop table if exists 表名

重命名表

alert table 表名 rename to 新的表名

增加分区

alert table 表名 add if not exists

partition(分区信息) location(存储位置)

删除分区

alert table 表名 drop if exists partition(分区信息)

 

修改列

alert table 表名 change column 旧列名 新列名 新类型 comment 新备注 after 列名

增加列

alert table 表名 add column (列名1 类型,列名2 类型)

 

删除或替换列

alert table 表名 replace column(

现有的列

)

修改表属性

alert table 表名 set tblpropies('key'='value')

向管理表中加载数据

load data location inputpath '原文件位置' overwrite to table 表名

 

通过查询语句向表中插入数据

insert overwrite table 表名 查询子句(select结果集)

 

form 表名

insert overwrite table 表名 查询子句(select结果集)

insert overwrite table 表名 查询子句(select结果集)

insert overwrite table 表名 查询子句(select结果集)

动态分区

insert overwrite table 表名 partition(列名【根据哪些列分区     ,间隔】) 查询子句

动态分区属性 P75

 

单个查询语句中创建表并加载数据

create table 表名 as 查询子句

导出数据

1.如果文件格式和用户需要的一致,可以用hadoop指令直接复制出来

2.insert overwrite local dirctory '本地目录' 查询子句

 

 

视图

使用视图可以降低查询复杂度

索引

使用索引加速查询效率

hive优化

参照hive编程指南第10章

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值