Hive- 表
在hive中表的类型:管理表和托管表(外部表)。
内部表也称之为MANAGER_TABLE,默认存储在/user/hive/warehouse下,也可以通过location指定;删除表时,会删除表的数据以及元数据;
外部表称之为EXTERNAL_TABLE。在创建表时可以自己指定目录位置(LOCATION),数据存储所在的目录;删除表时,只会删除元数据不会删除表数据;
创建外部表实例
create external table if not exists default.emp_ext(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int
)
row format delimited fields terminated by '\t'
location '/opt/input/emp';
分区表实际上就是对应一个HDFS文件系统上的独立的文件夹,该文件夹下是该分区所以的数据文件。hive中的分区就是分目录,把一个大的数据集根据业务需要分割成更小的数据集。
在查询时通过WHERE子句中的表达来选择所需要的指定的分区,这样的查询效率会提高很多。
create external table if not exists default.emp_partition(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int
)
partitioned by(month string)
row format delimited fields terminated by '\t';
分区表注意事项:
修复表:msck repair table table_name;
可以写shell脚本
dfs -mkdir -p /user/hive/warehouse/dept_part/day=;
dfs -put /opt/weblog/log.log /user/hive/warehouse/dept_part/day=; alter table dept_part and partition('day=20171025');
查看表的分区数:show partitions dept_part;
导入数据进入hive表
load data [local] inpath 'filepath' [overwrite] into table tablename into tablename [partition (partcol1=val,...)];
参数带local意思是本地文件,不带就是HDFS文件
参数带overwrite意思是覆盖原本文件的内容,不带就追加内容
分区表加载,特殊性partition (partcol1=val,...)
1.加载本地文件到hive表
load data local inpath '/root/emp.txt' into table default.emp
2.加载hdfs文件到hive表中
load data inpath '/root/emp.txt' into table default.emp
3.加载数据覆盖表中已有的数据
load data inpath '/root/emp.txt' overwrite into table default.emp
4.创建表是通过insert加载
create table default.emp_ci like emp;
insert into table default.emp_ci select * from default.emp;
5.创建表的时候通过指定location指定加载
导出hive表数据
insert overwrite local directory '/opt/datas/hive/hive_exp_emp' select * from default.emp row format delimited fields terminated by '\t'; #bin/hive -e "select * from default.emp;" > /opt/datas/hive/exp_res.txt
hive表多重插入
假如有一个需求:
从t_4中筛选出不同的数据,插入另外两张表中;
insert overwrite table t_4_st_lt_200 partition(day='')
select ip,url,staylong from t_4 where staylong<; insert overwrite table t_4_st_gt_200 partition(day='')
select ip,url,staylong from t_4 where staylong>;
但是以上实现方式有一个弊端,两次筛选job,要分别启动两次mr过程,要对同一份源表数据进行两次读取
如果使用多重插入语法,则可以避免上述弊端,提高效率:源表只要读取一次即可
from t_4
insert overwrite table t_4_st_lt_200 partition(day='')
select ip,url,staylong where staylong<
insert overwrite table t_4_st_gt_200 partition(day='')
select ip,url,staylong where staylong>;
Hive- 表的更多相关文章
- hive 表分区操作
hive的数据查询一般会扫描整个表,当表数据太大时,就会消耗些时间,有时候我们只需要对部分数据感兴趣,所以hive引入了分区的概念 hive的表分区区别于一般的分布式分区(hash分区,范围分区 ...
- 如何快速把hdfs数据动态导入到hive表
1. hdfs 文件 {"retCode":1,"retMsg":"Success","data":[{" ...
- HDFS文件和HIVE表的一些操作
1. hadoop fs -ls 可以查看HDFS文件 后面不加目录参数的话,默认当前用户的目录./user/当前用户 $ hadoop fs -ls 16/05/19 10:40:10 WARN ...
- 用puthivestreaming把hdfs里的数据流到hive表
全景图: 1. 创建hive表 CREATE TABLE IF NOT EXISTS newsinfo.test( name STRING ) CLUSTERED BY (name)INTO 3 ...
- spark使用Hive表操作
spark Hive表操作 之前很长一段时间是通过hiveServer操作Hive表的,一旦hiveServer宕掉就无法进行操作. 比如说一个修改表分区的操作 一.使用HiveServer的方式 v ...
- spark+hcatalog操作hive表及其数据
package iie.hadoop.hcatalog.spark; import iie.udps.common.hcatalog.SerHCatInputFormat; import iie.ud ...
- 【原】创建Hive表,分号分隔符“;”引起的异常
[障碍再现] 在创建支持Map数据结构的Hive表时,抛出如下异常 hive> create table tab_map(name string,info map<string,strin ...
- Hive表分区
必须在表定义时创建partition a.单分区建表语句:create table day_table (id int, content string) partitioned by (dt stri ...
- 导hive表项目总结(未完待续)
shell里面对日期的操作 #!/bin/bash THIS_FROM=$(date +%Y%m%d -d "-7 day") THIS_TO=$(date +%Y-%m-%d - ...
- 使用spark对hive表中的多列数据判重
本文处理的场景如下,hive表中的数据,对其中的多列进行判重deduplicate. 1.先解决依赖,spark相关的所有包,pom.xml spark-hive是我们进行hive表spark处理的关 ...
随机推荐
- centos7 中文输入法设置
安装centos7 后,他有自带的中文输入法安装包找到 applications->systemTools->settings->region&language 2:在 in ...
- applicationContext-XXX.xml和XXX-servlet.xml的区别
1.ApplicationContext.xml 是spring 全局配置文件,用来控制spring 特性的 2.dispatcher-servlet.xml 是spring mvc里面的,控制器. ...
- Swift迎来了1.0 GM 版(2014.09.09)
2014年6月2日,swift开发团队将swift语言公之于众.而2014年9月9日迎来了swift的第二个里程碑,swift1.0版本号(GM),这意味着无论你的应用有一部分功能是用swift写的, ...
- JQuery不能加载click事件的问题
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- PHP 学习内容
第一阶段: (PHP+MySQL核心编程) 面向对象编程 MySQL数据库, MySQL的优化细节. HTTP协议,http也是我们web开发的基石.对我们了解PHP底层机制有很大帮助,做到知其然,还 ...
- 那不是Bug,是新需求
原文作者:Jeff Atwood 自从我干上软件开发这一行.而且使用了Bug跟踪系统.我们在每个项目里都会纠结一个主要的问题:你怎么能把Bug与功能需求区分开来? 当然,假设程序崩溃了,这毫无疑问是B ...
- WPF Button TextBox 圆角
<!--圆角button--> <Style TargetType="Button"> <Setter Property="FontSize ...
- Unity中surfaceShader的处理机制和finalColor
http://blog.csdn.net/swj524152416/article/details/52945375
- Ant自己主动编译打包&公布 android项目
Eclipse用起来尽管方便,可是编译打包android项目还是比較慢,尤其将应用打包公布到各个渠道时,用Eclipse手动打包各种渠道包就有点不切实际了,这时候我们用到Ant帮我们自己主动编译打包了 ...
- K.Bro Sorting(思维题)
K.Bro Sorting Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)T ...