博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hive索引
阅读量:4159 次
发布时间:2019-05-26

本文共 1661 字,大约阅读时间需要 5 分钟。

创建索引

hive> create index [index_studentid] on table st(studentid)

 as 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler'

 with deferred rebuild

 IN TABLE index_table_st;

OK Time taken: 12.219 seconds

 

org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler :创建索引需要的实现类

index_studentid:索引名称

st:表名

index_table_st:创建索引后的表名

查看索引表(index_table_st)没有数据

hive> select*from index_table_st;

OK
Time taken: 0.295 seconds
  

加载索引数据

hive> alter index index_studentid on st rebuild;

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_st;

OK

1 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/st/sutdent.txt [0]

2 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/st/sutdent.txt [28]

3 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/st/sutdent.txt [56]

4 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/st/sutdent.txt [85]

5 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/st/sutdent.txt [113]

6 hdfs://hadoop-node4.com:8020/opt/hive/warehouse/st/sutdent.txt [143]

Time taken: 2.055 seconds, Fetched: 6 row(s)

查看hdfs://hadoop-node4.com:8020/opt/hive/warehouse/st/sutdent.txt

[root@node4 node4]# hdfs dfs -text /opt/hive/warehouse/st/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

 

删除索引

DROP INDEX index_studentid on st;

查看索引hive> SHOW INDEX on st;

OK
index_studentid         st               studentid               index_table_st    compact                 
Time taken: 0.487 seconds, Fetched: 1 row(s)

转载地址:http://nrjxi.baihongyu.com/

你可能感兴趣的文章
【Python基础1】变量和字符串定义
查看>>
【Python基础2】python字符串方法及格式设置
查看>>
【Python】random生成随机数
查看>>
【Python基础3】数字类型与常用运算
查看>>
【Python基础4】for循环、while循环与if分支
查看>>
【Python基础6】格式化字符串
查看>>
【Python基础7】字典
查看>>
【Python基础8】函数参数
查看>>
【Python基础9】浅谈深浅拷贝及变量赋值
查看>>
Jenkins定制一个具有筛选功能的列表视图
查看>>
【Python基础10】探索模块
查看>>
【Python】将txt文件转换为html
查看>>
[Linux]Shell脚本实现按照模块信息拆分文件内容
查看>>
idea添加gradle模块报错The project is already registered
查看>>
在C++中如何实现模板函数的外部调用
查看>>
在C++中,关键字explicit有什么作用
查看>>
C++中异常的处理方法以及使用了哪些关键字
查看>>
内存分配的形式有哪些? C++
查看>>
什么是内存泄露,如何避免内存泄露 C++
查看>>
栈和堆的空间大小 C++
查看>>