索引是hive0.7之后才有的功能,创建索引需要评估其合理性,因为创建索引也是要磁盘空间,维护起来也是需要代价的

创建索引
hive> create index [index_studentid] on table student_3(studentid)
> as 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler'
> with deferred rebuild
> IN TABLE index_table_student_3;
OK
Time taken: 12.219 seconds
hive>
org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler :创建索引需要的实现类
index_studentid:索引名称
student_3:表名
index_table_student_3:创建索引后的表名
 
 
查看索引表(index_table_student_3)没有数据
1
2
3
hive> select*from index_table_student_3;
OK
Time taken: 0.295 seconds

  

加载索引数据
hive> alter index index_studentid on student_3 rebuild;
WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. tez, spark) or using Hive 1.X releases.
Query ID = root_20161226235345_5b3fcc2b-7f90-4b10-861f-31cbaed8eb73
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks not specified. Estimated from input data size: 1
In order to change the average load for a reducer (in bytes):
set hive.exec.reducers.bytes.per.reducer=<number>
In order to limit the maximum number of reducers:
set hive.exec.reducers.max=<number>
In order to set a constant number of reducers:
set mapreduce.job.reduces=<number>
Starting Job = job_1482824475750_0001, Tracking URL = http://hadoop-node4.com:8088/proxy/application_1482824475750_0001/
Kill Command = /usr/local/development/hadoop-2.6.4/bin/hadoop job -kill job_1482824475750_0001
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 1
2016-12-26 23:55:40,317 Stage-1 map = 0%, reduce = 0%
2016-12-26 23:56:40,757 Stage-1 map = 0%, reduce = 0%
2016-12-26 23:56:48,768 Stage-1 map = 100%, reduce = 0%, Cumulative CPU 2.08 sec
2016-12-26 23:57:34,981 Stage-1 map = 100%, reduce = 67%, Cumulative CPU 3.66 sec
2016-12-26 23:57:40,716 Stage-1 map = 100%, reduce = 100%, Cumulative CPU 4.68 sec
MapReduce Total cumulative CPU time: 4 seconds 680 msec
Ended Job = job_1482824475750_0001
Loading data to table default.index_table_student_3
MapReduce Jobs Launched:
Stage-Stage-1: Map: 1 Reduce: 1 Cumulative CPU: 4.68 sec HDFS Read: 10282 HDFS Write: 537 SUCCESS
Total MapReduce CPU Time Spent: 4 seconds 680 msec
OK
Time taken: 280.693 seconds
查询索引表中数据
hive> select*from index_table_student_3;
OK
1 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/student_3/sutdent.txt [0]
2 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/student_3/sutdent.txt [28]
3 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/student_3/sutdent.txt [56]
4 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/student_3/sutdent.txt [85]
5 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/student_3/sutdent.txt [113]
6 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/student_3/sutdent.txt [143]
Time taken: 2.055 seconds, Fetched: 6 row(s)
hive>
查看hdfs://hadoop-node4.com:8020/opt/hive/warehouse/student_3/sutdent.txt
[root@node4 node4]# hdfs dfs -text /opt/hive/warehouse/student_3/sutdent.txt;
001 0 BeiJing xinlang@.com
002 1 ShangHaixinlang@.com
003 0 ShegZhen xinlang@.com
004 1 NanJing xinlang@.com
005 0 GuangDong xinlang@.com
006 1 HaiNan xinlang@.com[root@node4 node4]#

删除索引

DROP INDEX index_studentid on student_3;

查看索引

hive> SHOW INDEX on student_3;
OK
index_studentid student_3 studentid index_table_student_3 compact
Time taken: 0.487 seconds, Fetched: 1 row(s)
hive>

015-HQL中级5-hive创建索引的更多相关文章

  1. hive创建索引

    索引是hive0.7之后才有的功能,创建索引需要评估其合理性,因为创建索引也是要磁盘空间,维护起来也是需要代价的 创建索引 hive> create index [index_studentid ...

  2. Hadoop Hive概念学习系列之hive的索引及案例(八)

    hive里的索引是什么? 索引是标准的数据库技术,hive 0.7版本之后支持索引.Hive提供有限的索引功能,这不像传统的关系型数据库那样有“键(key)”的概念,用户可以在某些列上创建索引来加速某 ...

  3. hive:创建索引

    hive也是支持索引的使用,但是如果表中已经有数据的情况下,创建索引的过程不是特别快. 已经拥有表: create table if not exists llcfpd_withgroupbykey( ...

  4. SQL语句-创建索引

    语法:CREATE [索引类型] INDEX 索引名称ON 表名(列名)WITH FILLFACTOR = 填充因子值0~100 GO USE 库名GO IF EXISTS (SELECT * FRO ...

  5. *使用while循环遍历数组创建索引和自增索引值

    package com.chongrui.test;/* *使用while循环遍历数组 *  *  * */public class test {    public static void main ...

  6. 程序员眼中的 SQL Server-执行计划教会我如何创建索引?

    先说点废话 以前有 DBA 在身边的时候,从来不曾考虑过数据库性能的问题,但是,当一个应用程序从头到脚都由自己完成,而且数据库面对的是接近百万的数据,看着一个页面加载速度像乌龟一样,自己心里真是有种挫 ...

  7. SQL Server创建索引(转)

    什么是索引 拿汉语字典的目录页(索引)打比方:正如汉语字典中的汉字按页存放一样,SQL Server中的数据记录也是按页存放的,每页容量一般为4K .为了加快查找的速度,汉语字(词)典一般都有按拼音. ...

  8. MongoDB性能篇之创建索引,组合索引,唯一索引,删除索引和explain执行计划

    这篇文章主要介绍了MongoDB性能篇之创建索引,组合索引,唯一索引,删除索引和explain执行计划的相关资料,需要的朋友可以参考下 一.索引 MongoDB 提供了多样性的索引支持,索引信息被保存 ...

  9. mysql 创建索引和删除索引

    索引的创建可以在CREATE TABLE语句中进行,也可以单独用CREATE INDEX或ALTER TABLE来给表增加索引.删除索引可以利用ALTER TABLE或DROP INDEX语句来实现. ...

随机推荐

  1. PHP——数组2(数组函数,二维数组,正则表达式)

    <body> <?php //数组函数 $arr=array(1,2,3,4,5,6); print_r($arr); echo "<br />"; ...

  2. 从文件/文件流的头字节中得到mime信息

    在写网络爬虫的时候,需要根据链接来获取文件类型,将内容正确存储.之前我都是根据链接的后缀来判断的,比如: http://img12.360buyimg.com/da/20120330/88_31_Zy ...

  3. easyui datagrid columns 如何取得json 内嵌对象(many-to-one POJO class)

    http://www.iteye.com/problems/44119 http://hi.baidu.com/lapson_85/item/7733586e60b08500a1cf0f8d ———— ...

  4. LigerUI 树状列表折叠显示

    http://blog.csdn.net/haojuntu/article/details/8626040 —————————————————————————————————————————————— ...

  5. [android] AndroidManifest.xml - 【 manifest -> Application -> activity 】

    <activity android:allowTaskReparenting=["true" | "false"] android:alwaysRetai ...

  6. C++ c++与C语言的区别(空结构体)

    //区别⑨:空结构体声明(C++版本) #include<iostream> using namespace std; struct A{}; class B{}; void main() ...

  7. 关于Unity中的transform组件(二)

    在Scene视图中的蓝色网格,每一格默认是1米 一.沿着Z轴每秒移动10米 Transform cube_trans; void start(){ this.cube_trans=this.trans ...

  8. hrbustoj 1306:再遇攻击(计算几何,判断点是否在多边形内,水题)

    再遇攻击 Time Limit: 1000 MS    Memory Limit: 65536 K Total Submit: 253(37 users)   Total Accepted: 56(2 ...

  9. maven 完整的settings.xml

    maven 完整的settings.xml <?xml version="1.0" encoding="UTF-8"?> <!-- Licen ...

  10. 关于ie中实现弹性盒模型-我的css

    css3中的弹性盒模型大家都不陌生,但是能否在ie6中实现呢?第三方库中涉及到的页少之又少,也有一部分css框架中支持各种布局,下面给出我用的盒模型样式(为了以后copy方便而已): /******* ...