【云计算】hive的基本概念和常用操作
小标 2019-02-11 来源 : 阅读 1459 评论 0

摘要:本文主要向大家介绍了【云计算】hive的基本概念和常用操作,通过具体的内容向大家展现,希望对大家学习云计算有所帮助。

本文主要向大家介绍了【云计算】hive的基本概念和常用操作,通过具体的内容向大家展现,希望对大家学习云计算有所帮助。

一,认识hive



 

1,hive介绍


 

The Apache Hive data warehouse software facilitates reading,writing, and managing large datasets residing in distributed storage using SQL.Structure can be projected onto data already in storage.A command line tool and JDBC driver are provided to connect users to Hive.


 

简单解释一下: Apache下的hive数据仓库软件便于读写和使用sql管理大型分布式存储的数据集。结构可以投影到存储的数据上。提供一个命令行工具和jdbc驱动程序来将用户连接到hive


 

2,什么是OLAP和OLTP


 

OLAP //on line analyze process,在线分析处理


 

OLTP //on line transaction process,在线事务处理


 

3, 什么是sql 和 nosql 和 hql


 

nosql : 很多人会认为不是sql,然而并不是这样 notonly sql : 不仅仅是SQL、不是关系型数据库(RDBMS)、类似文档型 的数据库(如hbase,mongdb,redis等等)


 

sql :structuredquery language (结构化查询语言)sql数据库都必须是RDBMS(关系型数据库管理系统) 这样的数据库我 们一般都是很常用的(mysql,oracle,sql server等等)


 

hql :hive query langrage (hive 查询语言)


 

1,hive支持的三种数据结构(table(表) + paritition(分区) + bucket(分桶))


 

2,缺陷


 

不是关系型数据库(RDMRS)


 

不是OLTP也就是说他是OLAP(在线分析数据)


 

不适合实时查询和行级更新


 

3,特性


 

schema存储在数据库中,处理hdfs的数据


 

OLAP


 

HQL


 

伸缩性、可扩展、批处理大量数据速度很快


 

4,hive构架


 

client : webui(web访问)和CLI(命令行)和JDBC/ODBC连接


 

hive : meta store(元数据)+Hive 处理引擎(以及执行引擎)


 

底层:hadoop(hdfs+mr)


 

 


 

5,hive组件


 

1,metadata,存放在RDMRS中的(元数据:table + basebase + colum)


 

2, HQL处理引擎:


 

写查询语句用于MR作业


 

3,execute engine


 

执行引擎,执行查询工作,得到结果


 

4,HDFS/HBase


 

存储数据


 

6,hive执行过程图:


 

 



二,hive的操作


1,hive的基本类型:


1,数字类型:tinyint 相当于java的 byte 占用 1个字节


smallint sort 2个字节


int int 4个字节


bigint long 8个字节


2,字符串类型:他们用' '和""都可以


varchar char string


3,TImestamp //YYYY-MM-DD hh:mm:ss.ffffffff 精确到纳秒


data //YYYY-MM-DD


4,浮点型


double


float


decimal //常量,decimal(10,0)=(刻度,精度)


(还用比如一下集合类型,array集合,map集合,struct集合)


2,hive的基本hql语句(hive的语法和mysql几乎一样所以会sql的学hive真的太简单了)


create database myhive; //对应创建 hdfs://t124:8020/user/hive/warehouse/myhive.db


select * from hive.dbs ; //在mysql查看数据库中的使用记录


select * from hive.tabs ; //在mysql查看表的使用记录


select * from hive.colmuns_v2;//在mysql查看字段的使用记录


show databases; //显示数据库信息


drop database myhive; //删除数据库信息


use myhive; 使用数据库


desc formatted usertalbes; //显示格式化的表信息,(带库的信息)



 

建表的简单格式


 

create table usertables(


 

id int,name string,money double,


 

subjectarray,sorce map,


 

address struct(street:string,city:string,state:string)


 


 

建立表的标准格式:


 

create table usertables(


 

id int, name string ,age int


 

)row format delimited


 

fields terminated by "\t"


 

lines terminated by "\n"


 

stored as textfile;


 

建表高级格式:(主要介绍)


 

create table usertables(


 

id int,name string,money double,


 

subjectarray,sorce map,


 

address struct(street:string,city:string,state:string)


 

) row format delimited // 这个必须写在前面(除了 stored as ***)这行代表一个下面的条件的一个规定 ( 除了stored as ***)


 

fields terminated by " " // 相当于row format delimitedfields terminated by " "表示字段以空格分隔


 

lines terminated by "\n" // 相当于row format delimitedlines terminated by "\n"表示行以制表符/n分隔


 

事实上lines terminated by 只能以/n分隔默认也是以/n分隔


 

collection items terminated by "," // 相当于row format delimitedcollection items terminated by "," 表示集合以,分隔


 

map keys terminated by ":" // 相当于row format delimitedmap keys terminated by ":" 表示map以:分隔


 

stored as textfile; //使用文本格式来加载文件



3,使用load命令加载本地文件hive(hadoop)


语法:


load data [local] inpath 'filepath' [overwirte] into table tablename (partcol1=val1,partcol2=val2.......)


local //指定本地文件,如果不指定会使用hdfs上的文件路径


overwrite //覆盖表数据(全部表数据)


partition //分区表


4,修改表结构


alter table t1rename to t2 //表的重命名


alter table t1 add columns (name string) //添加列


alter table t1 drop column name; //删除列


alter table t1 change name name1 int; //修改列(可以改列名)


alter table t1 replace name int; //替换列(全部替换)


5, hive脚本命令(就是不开起hive命令行等执行hql语句)


hive --hlep //hive帮助文档


hive -e "show databases" //一次性命令


hive -S -e "show databases" //执行静态信息


hive -f "xx.sql" //执行脚本


hive -i .hiverc //-i在启动hive时,执行指定文件


hive>tab键 //查看帮助帮助命令


hive>!cmd xx //执行shell命令如: !echo "hello world"


hive>dfs -lsr /; //执行dfs命令


hive>set hive.cli.print.header=true ; //动态设置头信息


hive>show databases like 'my*' //统配符


hive>create database myhive location '/x/x/x' //指定数据库在hdfs的位置


hive>drop database myhive cascde //级联删除数据库


          

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标大数据云计算大数据安全频道!


本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved