Hive 基本语法操练(二):视图和索引操作

Hive 基本语法操练(二):视图和索引操作

大家好,又见面了,我是你们的朋友全栈君。

1. 视图操作 -------  1) 创建一个测试表。  ``` hive> create table test(id int,name string); OK Time taken: 0.385 seconds hive> desc test; OK id int  name string  Time taken: 0.261 seconds, Fetched: 2 row(s) ```  2) 基于表 test 创建一个 test_view 视图。  ``` hive> create view test_view(id,name_length) as select id,length(name) from test; ```  3) 查看 test_view 视图属性。  ``` hive> desc test_view; OK id int  name_length int  Time taken: 0.071 seconds, Fetched: 2 row(s)  ```  4) 查看视图结果。  ``` hive> select * from test_view; ```  2. 索引操作 ------- 1) Hive 创建索引。  ``` hive> create table user like group_test; OK Time taken: 0.232 seconds hive> create index user_index on table user(uid) as 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler' with deferred rebuild IN TABLE user_index_table; OK Time taken: 0.183 seconds  ```  2) 更新数据。  ``` hive> alter index user_index on user rebuild; Query ID = hadoop_20180518043232_ebdf97bd-5984-4310-a3c8-6befef328133 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_1526553207632_0018, Tracking URL = http://master:8088/proxy/application_1526553207632_0018/ Kill Command = /opt/modules/hadoop-2.6.0/bin/hadoop job -kill job_1526553207632_0018 Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 1 2018-05-18 04:32:55,632 Stage-1 map = 0%, reduce = 0% 2018-05-18 04:33:04,400 Stage-1 map = 100%, reduce = 0%, Cumulative CPU 1.65 sec 2018-05-18 04:33:12,406 Stage-1 map = 100%, reduce = 100%, Cumulative CPU 2.93 sec MapReduce Total cumulative CPU time: 2 seconds 930 msec Ended Job = job_1526553207632_0018 Loading data to table default.user_index_table Table default.user_index_table stats: [numFiles=1, numRows=0, totalSize=0, rawDataSize=0] MapReduce Jobs Launched:  Stage-Stage-1: Map: 1 Reduce: 1 Cumulative CPU: 2.93 sec HDFS Read: 290 HDFS Write: 50 SUCCESS Total MapReduce CPU Time Spent: 2 seconds 930 msec OK Time taken: 25.609 seconds  ``` 3) 查看索引 ``` hive> show index on user; OK user_index user uid user_index_table compact  Time taken: 0.046 seconds, Fetched: 1 row(s)  ```  4) 删除索引  ``` hive> drop index user_index on user; OK  Time taken: 0.094 seconds hive> show index on user;  OK Time taken: 0.036 seconds  ```  5) 创建表和索引案例  ``` hive> create table index_test(id INT,name STRING) PARTITIONED BY (dt STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY ','; ```  创建一个索引测试表 index_test,dt作为分区属性,“ROW FORMAT DELIMITED FIELDS TERMINATED BY ','” 表示用逗号分割字符串。  6) 创建一个临时索引表 index_tmp。  ``` hive> create table index_tmp(id INT,name STRING,dt STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY ','; ```  7) 加载本地数据到 index_tmp 表中。  ``` [hadoop@master test]$ sudo vim test.txt 02,female,192.168.1.3 01,male,192.168.1.26 03,male,192.168.1.5 08,female,192.168.1.62 04,male,192.168.1.9 hive> load data local inpath '/home/hadoop/test/test.txt' into table index_tmp; Loading data to table default.index_tmp Table default.index_tmp stats: [numFiles=1, totalSize=106] OK Time taken: 0.224 seconds hive> select * from index_tmp; OK 2 female 192.168.1.3 1 male 192.168.1.26 3 male 192.168.1.5 8 female 192.168.1.62 4 male 192.168.1.9  ```  设置 Hive 的索引属性来优化索引查询,命令如下。  ``` hive> set hive.exec.dynamic.partition.mode=nonstrict;----设置所有列为 dynamic partition hive> set hive.exec.dynamic.partition=true;----使用动态分区 ```  8) 查询index_tmp 表中的数据,插入 table_test 表中。  ``` hive> insert overwrite table index_test partition(dt) select id,name,dt from index_tmp; Query ID = hadoop_20180518044343_97e7fe67-a5a1-408b-be8e-e9dadb2f9e48 Total jobs = 3 Launching Job 1 out of 3 Number of reduce tasks is set to 0 since there's no reduce operator Starting Job = job_1526553207632_0019, Tracking URL = http://master:8088/proxy/application_1526553207632_0019/ Kill Command = /opt/modules/hadoop-2.6.0/bin/hadoop job -kill job_1526553207632_0019 Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0 2018-05-18 04:43:42,621 Stage-1 map = 0%, reduce = 0% 2018-05-18 04:43:48,835 Stage-1 map = 100%, reduce = 0%, Cumulative CPU 0.87 sec MapReduce Total cumulative CPU time: 870 msec Ended Job = job_1526553207632_0019 Stage-4 is selected by condition resolver. Stage-3 is filtered out by condition resolver. Stage-5 is filtered out by condition resolver. Moving data to: hdfs://ns/tmp/hive/hadoop/9f7dd0d3-a14c-4535-9291-557b9cb6259b/hive_2018-05-18_04-43-36_337_559705388802402645-1/-ext-10000 Loading data to table default.index_test partition (dt=null) Time taken for load dynamic partitions : 278 Loading partition {dt=192.168.1.62} Loading partition {dt=192.168.1.3} Loading partition {dt=192.168.1.5} Loading partition {dt=192.168.1.26} Loading partition {dt=192.168.1.9}

转载于:https://www.cnblogs.com/zimo-jing/p/9059550.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/107504.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • TK-MyBatis 分页查询「建议收藏」

    TK-MyBatis 分页查询「建议收藏」记tkMybatis查询出一个 List集合该集合已经做好了一层分页Page封装即查询出的list使用类型判断instanceofPage为true但是,中途不明白这是一个带分页的集合,把查询出的结果集又做了一层封装需要返回的对象类型为GoodsCategoryDTO,代码如下:   //商品集合        List&lt;GoodsCategory…

    2022年6月1日
    200
  • 关于力矩单位的理解

    关于力矩单位的理解电机转矩,简单的说,就是指转动的力量的大小。但电动机的转矩与旋转磁场的强弱和转子笼条中的电流成正比,和电源电压的平方成正比所以转矩是由电流和电压的因素所决定的。转矩是一种力矩,力矩在物理中的定义是:力矩=力×力臂电机的“扭矩”,单位是N·m(牛米)。电磁转矩的计算公式没有涉及力臂的概念,单位为什么也是N.m?电磁转矩是机电能量转换的桥梁。从电角度看T=CT*Φ*Ia;从机

    2022年5月14日
    53
  • Android 基于TCP的 Socket 编程实现(结合 okio)

    Android 基于TCP的 Socket 编程实现(结合 okio)两个进程如果要进行通讯最基本的一个前提就是能够唯一的标识一个进程,在本地进程通讯中我们可以使用PID来唯一标识一个进程,但PID只在本地是唯一的,网络中两个进程PID冲突几率很大,这时我们就需要通过其他手段来唯一标识网络中的进程了,我们知道IP层的ip地址可以唯一标示主机,而TCP层协议和端口号结合就可以唯一标示主机的一个进程了。

    2022年6月7日
    44
  • Mqtt开发笔记:Mqtt服务器搭建

    Mqtt开发笔记:Mqtt服务器搭建若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/article/details/102478062本文章博客地址:各位读者,知识无穷而人力有穷,要么改需求,要么找专业人士,要么自己研究红胖子(红模仿)的博文大全:开发技术集合(包含Qt实用技术、树莓派、三维、OpenCV、OpenGL、ffmpeg、OSG、单片机、软硬结合等等)持续更新中…(点击传送门

    2022年4月29日
    107
  • 传奇ce刷元宝教程_ce修改器传奇刀速

    传奇ce刷元宝教程_ce修改器传奇刀速我們一把在打野怪的時候,多多少少都能夠在這個野怪的身上爆到許多的東西,其中有很小的幾率打到裝備,如果你爆到了裝備是一件非常幸運的事情呢,所以我們在玩传奇私服這款游戲的時候一定要多去野外刷怪。傳奇游戲其實本身就應該是一個獨來獨往的游戲,但是需要指出的是,在傳奇游戲當中真正獨來獨往的玩家其實并不多,除非說你的實力非常強大了。要不然的話,在傳奇游戲當中,如果是獨來獨往的話,那么想要做很多事情其實都是做不…

    2025年7月17日
    2
  • cdr9导出对话框遮挡怎么办_sldprt文件ug怎么打开

    cdr9导出对话框遮挡怎么办_sldprt文件ug怎么打开说明因为之前旧项目采用的是MFC+BCG界面库的方法实现的。维护旧项目过程中,遇到选择文件对话框没有从默认位置选择的问题,学习和思考后,问题得到解决,特此记录。原来的BCG中配置选择的方法是这样的: lpszDefExt=_T(“DAT”); lpszFilter=_T(“文件|*.dat|\ 文件|*.bln|\ 文件|*.xyz|\ 文件|*.txt||”); m_editDataName.EnableFileBrowseButton(

    2022年10月8日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号