hive基础知识(二)

 

hive使用场景:

离线数据

处理大数据

延迟高

数据的离线处理;比如:日志分析,海量结构化数据离线分析…

Hive的执行延迟比较高,因此hive常用于数据分析的,对实时性要求不高的场合;

Hive优势在于处理大数据,对于小数据没有优势,因为Hive的执行延迟比较高。

hive优点:

操作接口采用类SQL语法,提供快速开发的能力(简单、容易上手);

避免了去写MapReduce,减少开发人员的学习成本;

统一的元数据管理,可与impala/spark等共享元数据;

易扩展(HDFS+MapReduce:可以扩展集群规模;支持自定义函数);

hive具体操作:

1、查看数据库:

show databases;

2、创建数据库:

create database if not exists a;

3、查看数据库信息:

describe databases a;

hive> describe database a;

OK

a hdfs://host-10-10-10-17:6200/user/hive/warehouse/a.dbhadoopUSER

Time taken: 0.034 seconds, Fetched: 1 row(s)

hive> desc database a;

-------同上面一样

 

4、使用数据库、查看表

 

hive> use a;

OK

Time taken: 0.014 seconds

hive> show tables;

OK

Time taken: 0.058 seconds

5、设置数据库名的显示

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

$ bin/hive --hiveconf hive.cli.print.current.db=true;

6、建表

hive (a)> create table if not exists student(id int,name string) row format delimited fields terminated by '\t' stored as textfile;

OK

Time taken: 0.131 seconds

7、加载数据

cd /home/hadoop/

ls

cd datas

pwd 打印当前目录

rz 上传文件

[hadoop@host-10-10-10-186 datas]$ rz

hive (a)> insert into table student(id,name) values(100,'zhang');

确定文件的位置:

/home/hadoop/datas/student.tsv

hive (a)> load data local inpath '/home/hadoop/datas/student.tsv' into table student;

hive (a)> select * from student;

8、

设置显示表头:

hive (a)> set hive.cli.print.header=true;

hive (a)> select * from student;

不显示表头:

hive (a)> set hive.cli.print.header=false;

9、

查看文件具体信息

$ cat student.tsv

删除:

rm -rf student.tsv

操作流程:

首先建表:

hive (a)>create table if not exists student(id int,name string) row format delimited fields terminated by '\t' stored as textfile;

$ cd /home/hadoop/

$ ls

$ cd datas

$ ls

$ cat student.tsv

(在本地数据上传:$ rz :已上传,不用操作)

$ pwd

显示的结果:

eg:不是绝对的,看你自己的目录就可以了

/home/hadoop/datas

hive (a)>load data local inpath '/usr/local/apache-hive-1.2.1-bin/student.tsv' into table student;

hive (a)> select * from student;

hive (a)> set hive.cli.print.header=true;

可视化工具:hue

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值