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处理的关 ...
随机推荐
- 查看Android源码和源码布局
一.查看源码 1.https://github.com/android 2.http://grepcode.com/project/repository.grepcode.com/java/ext/c ...
- javascript判断浏览器核心
20 21 22 23 24 /** * 判断浏览器核心 * @return IE6.0/IE7.0/IE8.0/FireFox/Opera/other * @author ypz */ functi ...
- 机器学习12—FP-growth学习笔记
test12.py #-*- coding:utf-8 import sys sys.path.append("fpGrowth.py") import fpGrowth from ...
- vim-colors-config
在vim中,主题是以插件形式存在.其中系统自带的主题,存放在$VIMRUNTIME/colors文件夹下,以*.vim命名.(注:查看$VIMRUNTIME请在vim中执行 :echo $VIMRUN ...
- 【转】利用Python中的mock库对Python代码进行模拟测试
出处 https://www.toptal.com/python/an-introduction-to-mocking-in-python http://www.oschina.net/transla ...
- 多媒体开发之rtp 打包发流---同网段其他机子sdp 播放不了
(1) (2) (3) -------------author:pkf ------------------time:2015-1-6 后面发现是connection 的server 地址是指定的 导 ...
- Swift_4_闭包(Blocks)
import Foundation println("Hello, World!") var arr = [1,2,4,6,74,2] func hasClosure(list:[ ...
- android-support-v4.jar异常解决方法
1.当一个项目引入其他library项目时,会出现android-support-v4.jar冲突问题: 解决:将library项目中的android-support-v4.jar更新到最新,方法右键 ...
- hdu 4902 Nice boat(线段树区间改动,输出终于序列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 Problem Description There is an old country and ...
- 【BZOJ4028】[HEOI2015]公约数数列 分块
[BZOJ4028][HEOI2015]公约数数列 Description 设计一个数据结构. 给定一个正整数数列 a_0, a_1, ..., a_{n - 1},你需要支持以下两种操作: 1. M ...