1 解压到目录
2 配置文件修改元数据保存到mysql
3 创建表,就是在hdfs中创建一个文件夹,load数据就是将数据文件拷贝到hdfs表对应的目录下面。
4 创建表(默认为表类型为MANAGED_TABLE,数据是在表的目录下面):
数据就是文件,它可以一次插入一个文件数据,但不能插入一条数据。
CREATE TABLE page_vie (viewTime int ,useid BIGINT,
page_url STRING,referrer_url STRING,
ip STRING COMMENT 'IP Address of the User')
COMMENT 'This is the page view table'
PARTITIONED BY (dt STRING,country STRING) //分区
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001' //数据是用什么来分割
STORED AS SEQUENCEFILE; //这个可以不加,默认是文本格式
创建内部表:
CREATE table t_order(id int ,name string ,rongliang string,price double )
row format delimited fields terminated by '\t'
5 创建External表 (1 数据可以在hdfs中任何地方,不必要放到表的文件夹中,创建的时候要指定文件夹)
CREATE external table t_order_ex(id int ,name string ,rongliang string,price double )
row format delimited fields terminated by '\t'
location '/hive_ext'
6 MANAGED_TABLE 删除的时候会删除表的目录以及目录中的内容,和表的元数据
External表 删除的时候只会删除表的元数据,文件不会变。
create table t_order_2 (id int ,name string ,rongliang string ,price double)
row format delimited
fields terminated by '\t'
8 数据导入
将本地文件导入到表中:
load data local inpath '/web/test_hive_data/phone.txt' into table t_order_2
将hdfs中的文件移动到到表中:
load data inpath '/phone3.txt' into table t_order_2 ;
9 用一个表创建另一个表,查询结果会单独存储 (会执行mapreduce,比较慢,内部表和外部表都会创建文件)
1)用于创建临时表,存储中间结果
create table t_order_s as
select id ,name ,price from t_order ;
2)创建一个表,和另一个表一样(表复制)
create table t_order_2 like t_order ;
3)表中添加查询出来的数据,表中以前的数据会清除掉(就是将查询出来的数据弄成文件放到文件夹下面)
insert overwrite table t_order_ow
select * from t_order ;
4)查询出来的数据添加到表中,数据追加(查询结果可以直接放到本地文件或者hdfs文件中)
insert into table t_order_ow
select * from t_order ;
10 分区使用:分区字段可以是表中没有的字段 (数据保存就是在表下面有个分区的文件夹,然后里面放内容)
create table t_order_pt(id int ,name string ,rongliang string,price double )
partitioned by (month string)
row format delimited fields terminated by '\t' ;
分区数据加载:
load data local inpath '/web/test_hive_data/phone.txt' into table t_order_pt partition(month='20150115') ;
针对分区做查询与统计的时候,可以把分区作为字段直接where 如:
select count(*) from t_order_pt where month='201502' //month是分区字段
可以动态增加分区 ,
11 数据支持数组
//array
数据:
tony,wang,xiaoming 189,123,456,123
abc,lili,maya 7823,123,34
create table tab_array(a array<int>,b array<string>)
row format delimited
fields terminated by '\t'
collection items terminated by ',';
12 支持Map数据
wang age:17;size:12A;addr:usr
tony age:23;size:32A;addr:bd
//map
create table tab_map(name string,info map<string,string>)
row format delimited
fields terminated by '\t'
collection items terminated by ','
map keys terminated by ':';
13 结构类型:
create table tab_struct(name string,info struct<age:int,tel:string,addr:string>)
row format delimited
fields terminated by '\t'
collection items terminated by ','
14 hive脚本语言执行sql(pathon,shell等) ;
hive -S -e 'select * from db_test.t_order' ;
15 自定义hive函数(JAVA)
1 写Java类,定义函数逻辑
2 打成jar包,上传到hive的lib中
3 在hive中创建函数 getArea,跟jar包
1)创建java工程,实现UDF类,重写evaluate方法打成jar包,引入hive中lib下面的包
2)自定义的jar包加入到classpath中:
add jar /web/hive-0.12.0/lib/hive_area.jar
3) 创建函数与jar包关联:
create TEMPORARY FUNCTION my_area AS 'jar类的全名称'
如: create TEMPORARY FUNCTION get_area AS 'com.wzt.func.PoneToArea'
4)创建表,并且准备数据:
执行sql:select get_area(phone) ,upflow,dflow from t_flow ;
相关推荐
大数据技术基础实验报告-Hive安装配置与应用
hive安装
HIVE安装及详解,及测试,该文档版本是1.2+的。。。。。
hive的安装与使用过程,是你不敢相当于还能修复好的哈人家还能够充分股份都是
内容包括hive如何安装与启动,以及如何使用python访问hive,希望对大家有帮助。
Hive安装与配置
大数据教程-Hive的安装与配置,详细细节安装、部署步骤
基于hadoop,进行hive客户端安装与使用
Hadoop集群搭建及Hive的安装与使用
这是安装hive的手册指南,安装hive服务端和hive客户端的详细步骤。
以下是一个详细的Hive安装与配置指南Hive的安装与配置是一个相对复杂的过程,涉及多个步骤和细节。以下是一个详细的Hive安装与配置指南Hive的安装与配置是一个相对复杂的过程,涉及多个步骤和细节。以下是一个详细的...
apache-hive-1.2.1-bin.tar.gz mysql-connector-java-5.1.6-bin 用于安装Hive并使用MySQL作为元数据库
cdh5.5.0下的hive的安装部署详细操作。hive的安装其实有两部分组成,一个是Server端、一个是客户端,所谓服务端其实就是Hive管理Meta的那个Hive,服务端可以装在任何节点上,当hive服务并发量不高时推荐部署在数据...
Hadoop伪分布下的hive安装及错误的更改
Hive安装部署及运维使用
hadoop集群配置之———hive安装与配置(超详细)
电商数仓项目(十) Hive安装与配置
hive安装依赖以及启动脚本 文件包含如下: 01_mysql-community-common-5.7.29-1.el7.x86_64.rpm 02_mysql-community-libs-5.7.29-1.el7.x86_64.rpm 03_mysql-community-libs-compat-5.7.29-1.el7.x86_64.rpm 04_...
Hive1.2.1安装指南