(1)建student & student1 表:(hive 托管)
create table student(id INT, age INT, name STRING)
partitioned by(stat_date STRING)
clustered by(id) sorted by(age) into 4 buckets
row format delimited fields terminated by ',';

create table studentrc(id INT, age INT, name STRING)
partitioned by(stat_date STRING)
clustered by(id) sorted by(age) into 4 buckets
row format delimited fields terminated by ',' stored as rcfile;

create table studentlzo(id INT, age INT, name STRING)
partitioned by(stat_date STRING)
clustered by(id) sorted by(age) into 4 buckets
row format delimited fields terminated by ',' stored as rcfile;

文件格式 textfile, sequencefile, rcfile
(2)设置环境变量:
set hive.enforce.bucketing = true;
(3)插入数据:
  LOAD DATA local INPATH '/home/hadoop/hivetest1.txt' OVERWRITE INTO TABLE student partition(stat_date="20120802");

(CPU使用率很高)
from student
insert overwrite table student1 partition(stat_date="20120802")
select id,age,name where stat_date="20120802" sort by age;

查看数据
select id, age, name from student  distribute by id ; // distribute相当于mapreduce中的key

抽选数据(一般测试的情况下使用)
select * from student tablesample(bucket 1 out of 2 on id);
TABLESAMPLE(BUCKET x OUT OF y)
其中, x必须比y小, y必须是在创建表的时候bucket on的数量的因子或者倍数, hive会根据y的大小来决定抽样多少, 比如原本分了32分, 当y=16时, 抽取32/16=2分, 这时TABLESAMPLE(BUCKET 3 OUT OF 16) 就意味着要抽取第3和第16+3=19分的样品. 如果y=64, 这要抽取 32/64=1/2份数据, 这时TABLESAMPLE(BUCKET 3 OUT OF 64) 意味着抽取第3份数据的一半来进行.

rcfile操作

// 导入(gzip压缩)
set hive.enforce.bucketing=true;
set hive.exec.compress.output=true;  
set mapred.output.compress=true;  
set mapred.output.compression.codec=org.apache.hadoop.io.compress.GzipCodec;  
set io.compression.codecs=org.apache.hadoop.io.compress.GzipCodec;  
from student
insert overwrite table studentrc partition(stat_date="20120802")  
select id,age,name where stat_date="20120802" sort by age;

// lzo压缩
set hive.io.rcfile.record.buffer.size = 16777216; // 16 * 1024 * 1024
set io.file.buffer.size = 131072; // 缓冲区大小 128 * 1024

set hive.enforce.bucketing=true;
set hive.exec.compress.output=true;  
set mapred.output.compress=true;  
set mapred.output.compression.codec=com.hadoop.compression.lzo.LzoCodec;  
set io.compression.codecs=com.hadoop.compression.lzo.LzoCodec;  
from student
insert overwrite table studentlzo partition(stat_date="20120802")  
select id,age,name where stat_date="20120802" sort by age;

// sequencefile导入
set hive.exec.compress.output=true;  
set mapred.output.compress=true;  
set mapred.output.compression.codec=org.apache.hadoop.io.compress.GzipCodec;  
set io.compression.codecs=org.apache.hadoop.io.compress.GzipCodec;  
insert overwrite table studentseq select * from student;

hive中使用rcfile的更多相关文章

  1. hive中rcfile格式(收藏文)

    首先声明,此文是属于纯粹收藏文,感觉讲的很不错. 本文介绍了Facebook公司数据分析系统中的RCFile存储结构,该结构集行存储和列存储的优点于一身,在MapReduce环境下的大规模数据分析中扮 ...

  2. Hive中的数据库(Database)和表(Table)

    在前面的文章中,介绍了可以把Hive当成一个"数据库",它也具备传统数据库的数据单元,数据库(Database/Schema)和表(Table). 本文介绍一下Hive中的数据库( ...

  3. Hive中的HiveServer2、Beeline及数据的压缩和存储

    1.使用HiveServer2及Beeline HiveServer2的作用:将hive变成一种server服务对外开放,多个客户端可以连接. 启动namenode.datanode.resource ...

  4. Hive存储格式之RCFile详解,RCFile的过去现在和未来

    我在整理Hive的存储格式和压缩格式,本来打算一篇发出来,结果其中一小节就有很多内容,于是打算写成Hive存储格式和压缩格式系列. 本节主要讲一下Hive存储格式最早的典型的列式存储格式RCFile. ...

  5. SparkSQL读取Hive中的数据

    由于我Spark采用的是Cloudera公司的CDH,并且安装的时候是在线自动安装和部署的集群.最近在学习SparkSQL,看到SparkSQL on HIVE.下面主要是介绍一下如何通过SparkS ...

  6. hive中分析函数window子句

    hive中有些分析函数功能确实很强大,在和sum,max等聚合函数结合起来能实现不少功能. 直接上代码演示吧 原始数据 channel1 2016-11-10 1 channel1 2016-11-1 ...

  7. hive中的一种假NULL现象

    使用hive时,我们偶尔会遇到这样的问题,当你将结果输出到屏幕时,查出的数据往往显示为null,但是当你将结果输出到文本时,却显示为空(即未填充),这是为什么呢? 在hive中有一种假NULL,它看起 ...

  8. hive中导入json格式的数据(hive分区表)

    hive中建立外部分区表,外部数据格式是json的如何导入呢? json格式的数据表不必含有分区字段,只需要在hdfs目录结构中体现出分区就可以了 This is all according to t ...

  9. sqoop将关系型数据库的表导入hive中

    1.sqoop 将关系型数据库的数据导入hive的参数说明:

随机推荐

  1. 阅读redis源代码的一些体会

    最近在学习redis及阅读redis等程序的源码时,有一些收获,特记录到下面. 1.第一步,阅读源代码借助最好可以跟踪的工具去读,如sourceinsight. 我使用的是windows7环境,又因为 ...

  2. 实用的随机数生成类Random:测试(随机产生100个不重复的正整数)

    实用的随机数生成类Random:测试(使用Random类随机生成100个不重复的正整数) 一.之前我们使用随机数用的是Math类的random()方法: tips: 产生随机数(0~9中任意整数)的方 ...

  3. Scala 知识点掌握2

    Scala 基础知识点巩固2 1.集合中常用的函数 sum / max / min # 定义一个List[Int]val list1 = List(1,3,4,6,8,9)# 取集合中所有元素的和li ...

  4. [LeetCode]29. Divide Two Integers两数相除

    Given two integers dividend and divisor, divide two integers without using multiplication, division ...

  5. 前端之CSS——属性和定位

    一.字体属性 1.font-size(字体大小) p { font-size: 14px; } font-size 属性可设置字体的尺寸. px:像素,稳定和精确 %:把 font-size 设置为基 ...

  6. JavaScirpt(JS)——js介绍及ECMAScript

    一.JavaScript历史发展 JavaScript语言的历史:http://javascript.ruanyifeng.com/introduction/history.html 1994年12月 ...

  7. jQuery源码分析系列(版本1.9 - 1.10)

    jQuery是我们常用的javascript库,我们应该不仅要会用它还要知道它的工作原理. 1.jQuery结构及$方法的工作原理 2.对回调函数操作的Callbacks对象 3.promise规范的 ...

  8. 【PIC单片机】MPLAB X IDE快速入门指南

    引言:近期由于项目实践需要,开始动手学习相关硬件知识.从PIC单片机入手. 单片机学习核心要点:查数据手册 配置寄存器 一.基于MPLAB X IDE配置位设置 MPLAB X IDE和MPLAB I ...

  9. ArcGIS Enterprise 10.5.1 静默安装部署记录(Centos 7.2 minimal)- 1、安装前准备

    安装前准备 上传文件到服务器,x-ftp   xshell登陆Centos 检查机器名 修改机器名为:portal.cloud.local   方法一:零时设置,重启后失效,该方法不可取     方法 ...

  10. dialog和dialogFragment的使用及常用问题

    今天比较懒,只是列举了一些网址 弹窗之一:dialogFragment的使用 https://blog.csdn.net/sinat_31057219/article/details/76979246 ...