Hive学习二
来源:互联网 发布:linux $$ 编辑:程序博客网 时间:2024/06/01 20:44
Hive学习二
标签(空格分隔): Hive
- Hive学习二
- 二内部表和外部表的区别
- 三分区表的功能创建加载数据和查询
一,hive表的三种创建,应用场景以及练习截图
第一种:
CREATE TABLE IF NOT EXISTS studb.studu_log_001(ip string COMMENT 'remote ip address' ,user string ,reqest_url string) COMMENT 'student1' ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' ;
第二种:
CREATE TABLE IF NOT EXISTS studb.studu_log_002 LIKE studb.studu_log_001;
第三种:
CREATE TABLE IF NOT EXISTS studb.studu_log_003 AS select ip, reqest_url from studb.studu_log_001;
二,内部表和外部表的区别
内部表称之为managed_table,默认存储在/user/hive/warehouse下,也可以通过location指定,删除表示会删除表数据和元数据。
1, 创建内部表并导入数据,查看表信息和表数据
create table if not exists emp_managed like emp;load data local inpath '/opt/datas/emp.txt' into table emp_managed;
2, 删除内部表并查看删除后的相关信息
drop table if exists emp_managed;
外部表称之为external_table,创建表时一般指定目录位置(location),删除表时只会删除元数据不会删除表数据。
1,创建内部表并导入数据,查看表信息和表数据
create external table if not exists emp_external like emp location '/user/xingyunfei/external';load data local inpath '/opt/datas/emp.txt' into table emp_external;
2, 删除内部表并查看删除后的相关信息
drop table if exists emp_external;
三,分区表的功能创建,加载数据和查询
分区表实际上对应一个HDFS文件系统上的独立的文件夹,该文件夹下是该分区所有的数据文件。hive中的的分区就是分目录,把一个大的数据集根据业务分割成更小的数据集。在查询时通过where子句中表达式来选择查询所需要的指定的分区,这样的查询效率会提高很多。
1, 一级分区
创建一级分区表
CREATE TABLE IF NOT EXISTS emp_partition(empno int,ename string,job string,mgr int,hiredate string,sal double,comm double,deptno int) partitioned by (time string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'STORED AS TEXTFILE ;
加载数据
load data local inpath '/opt/datas/emp.txt' into table emp_partition partition(time='20160308');
查询数据:
select * from emp_partition where time='20160308';
2, 二级分区
创建二级分区表:
CREATE TABLE IF NOT EXISTS emp_partition_month_day(empno int,ename string,job string,mgr int,hiredate string,sal double,comm double,deptno int) partitioned by (month string,day string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'STORED AS TEXTFILE ;
加载数据:
load data local inpath '/opt/datas/emp.txt' into table emp_partition_month_day partition(month='201603',day='01');
查询数据:
select * from emp_partition_month_day where month='201603' and day='01';
0 0
- Hive学习二
- Hive 学习笔记 (二)
- hive学习(二)
- Hive学习笔记(二)
- hive学习笔记二:安装
- hive 学习笔记(二)---hive表操作
- Hive入门学习之二:Hive 的部署
- Hive学习笔记(二) Hive源码编译与安装
- hive入门学习:hive的调优(二)
- Hive学习之SELECT语句(二)
- HIVE学习笔记 二 精简版
- Hive学习(二)-数据导入及导出
- 《hive编程指南》学习文档(二)
- 数据库学习纪要(二):hive-2
- hive(二)--hive优化
- hive学习教程(二):hive的数据类型和hive的数据模型
- hive(二)
- hive学习 hive基本功
- Matlab曲面拟合和插值
- redis实例操作
- Java Web开发详解:RequestDispatcher接口
- REST风格
- No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
- Hive学习二
- POJ 3264 Balanced Lineup RMQ
- [从头学数学] 第184节 周游列国拜诸侯(中)
- C#引用传递
- HDU 5666 快速就乘
- 用pipe唤醒异步select的经典场景
- __NSCFNumber isEqualToString:的问题.--[__NSCFNumber isEqualToString:]: unrecognized selector sent to in
- vs下,GBK格式的.h .cpp 编译时,自动转换为UTF-8
- Java学习-11天