Hive_Hive统计指令analyze table和 describe table

之前在公司内部经常会看到表的元信息的一些统计信息,当时非常好奇是如何做实现的。

现在发现这些信息主要是基于 analyze table 去做统计的,分享给大家

实现的效果某一个表中每个列的空值数量,重复值数量等,平均长度

具体的指令还是要看HIVE官网,StatsDev - Apache Hive - Apache Software Foundation

指令简介

analyze table和 describe table 一般是组合使用的,其中analyze table指令可以用于数据表的统计,并且是通过额外的任务对数据表的大小或者分区等进行统计。而describe table 则是将统计好的数据展示出来。

官网对这块儿的介绍

统计数据(如表或分区的行数和特定感兴趣的列的直方图)在许多方面都很重要。统计的一个关键用例是查询优化。统计数据作为优化器的成本函数的输入,以便它可以比较不同的计划并从中进行选择。统计数据有时可以满足用户查询的目的。用户可以通过仅查询存储的统计信息而不是触发长时间运行的执行计划来快速获得某些查询的答案。一些例子是获取用户年龄分布的分位数,人们使用的前10个应用程序,以及不同会话的数量。

Analyze table

analyze table 支持表和分区的统计,支持统计以下几个基本项 

  • 行数
  • 文件数量
  • 字节大小
DescriptionStored inCollected bySince
Number of partition the dataset consists ofFictional metastore property: numPartitionscomputed during displaying the properties of a partitioned tableHive 2.3
Number of files the dataset consists ofMetastore table property: numFilesAutomatically during Metastore operations
Total size of the dataset as its seen at the filesystem levelMetastore table property: totalSize
Uncompressed size of the datasetMetastore table property: rawDataSize

Computed, these are the basic statistics. Calculated automatically when hive.stats.autogather is enabled.
Can be collected manually by: ANALYZE TABLE ... COMPUTE STATISTICS

Hive 0.8
Number of rows the dataset consist ofMetastore table property: numRows

Column level statistics

Metastore; TAB_COL_STATS tableComputed, Calculated automatically when hive.stats.column.autogather is enabled.
Can be collected manually by: ANALYZE TABLE ... COMPUTE STATISTICS FOR COLUMNS

指令详解:

ANALYZE TABLE [db_name.]tablename [PARTITION(partcol1[=val1], partcol2[=val2], ...)]  -- (Note: Fully support qualified table name since Hive 1.2.0, see HIVE-10007.)

  COMPUTE STATISTICS 

  [FOR COLUMNS]          -- (Note: Hive 0.10.0 and later.)

  [CACHE METADATA]       -- (Note: Hive 2.1.0 and later.)

  [NOSCAN];

noscan 参数的作用 

  当使用noscan, 任务不会扫描文件,以便于尽可能的快速,但是不会统计所有项,只会统计以下信息

  • Number of files  (文件量)
  • Physical size in bytes (文件的物理存储空间(hdfs 上的空间))

cache metadata 参数的作用

Feature not implemented

Hive Metastore on HBase was discontinued and removed in Hive 3.0.0. See HBaseMetastoreDevelopmentGuide

该指令主要是把计算的统计信息存储在HBase中,不过之后Hive3.0.0之后不再支持

When Hive metastore is configured to use HBase, this command explicitly caches file metadata in HBase metastore.  

The goal of this feature is to cache file metadata (e.g. ORC file footers) to avoid reading lots of files from HDFS at split generation time, as well as potentially cache some information about splits (e.g. grouping based on location that would be good for some short time) to further speed up the generation and achieve better cache locality with consistent splits.

使用示例 :

Suppose table Table1 has 4 partitions with the following specs:

  • Partition1: (ds='2008-04-08', hr=11)
  • Partition2: (ds='2008-04-08', hr=12)
  • Partition3: (ds='2008-04-09', hr=11)
  • Partition4: (ds='2008-04-09', hr=12)

and you issue the following command:

ANALYZE TABLE Table1 PARTITION(ds='2008-04-09', hr=11) COMPUTE STATISTICS;

then statistics are gathered for partition3 (ds='2008-04-09', hr=11) only.

If you issue the command:

ANALYZE TABLE Table1 PARTITION(ds='2008-04-09', hr=11) COMPUTE STATISTICS FOR COLUMNS;

then column statistics are gathered for all columns for partition3 (ds='2008-04-09', hr=11). This is available in Hive 0.10.0 and later.

If you issue the command:

ANALYZE TABLE Table1 PARTITION(ds='2008-04-09', hr) COMPUTE STATISTICS;

then statistics are gathered for partitions 3 and 4 only (hr=11 and hr=12).

If you issue the command:

ANALYZE TABLE Table1 PARTITION(ds='2008-04-09', hr) COMPUTE STATISTICS FOR COLUMNS;

then column statistics for all columns are gathered for partitions 3 and 4 only (Hive 0.10.0 and later).

If you issue the command:

ANALYZE TABLE Table1 PARTITION(ds, hr) COMPUTE STATISTICS;

then statistics are gathered for all four partitions.

If you issue the command:

ANALYZE TABLE Table1 PARTITION(ds, hr) COMPUTE STATISTICS FOR COLUMNS;

then column statistics for all columns are gathered for all four partitions (Hive 0.10.0 and later).

For a non-partitioned table, you can issue the command:

ANALYZE TABLE Table1 COMPUTE STATISTICS;

to gather statistics of the table.

For a non-partitioned table, you can issue the command:

ANALYZE TABLE Table1 COMPUTE STATISTICS FOR COLUMNS;

to gather column statistics of the table (Hive 0.10.0 and later).

Describe table 

当我们使用analyze table 统计相应数据的时候,我们可以调用 descirbe table 查看相关的统计数据,

使用示例

DESCRIBE EXTENDED TABLE1;

then among the output, the following would be displayed:

... , parameters:{numPartitions=4, numFiles=16, numRows=2000, totalSize=16384, ...}, ....

If you issue the command:

DESCRIBE EXTENDED TABLE1 PARTITION(ds='2008-04-09', hr=11);

then among the output, the following would be displayed:

... , parameters:{numFiles=4, numRows=500, totalSize=4096, ...}, ....

If you issue the command:

desc formatted concurrent_delete_different partition(ds='tomorrow') name;

the output would look like this:

+-----------------+--------------------+-------+-------+------------+-----------------+--------------+--------------+------------+-------------+------------+----------+

|    col_name     |     data_type      |  min  |  max  | num_nulls  | distinct_count  | avg_col_len  | max_col_len  | num_trues  | num_falses  | bitvector  | comment  |

+-----------------+--------------------+-------+-------+------------+-----------------+--------------+--------------+------------+-------------+------------+----------+

| col_name        | name               | NULL  | NULL  | NULL       | NULL            | NULL         | NULL         | NULL       | NULL        | NULL       | NULL     |

| data_type       | varchar(50)        | NULL  | NULL  | NULL       | NULL            | NULL         | NULL         | NULL       | NULL        | NULL       | NULL     |

| min             |                    | NULL  | NULL  | NULL       | NULL            | NULL         | NULL         | NULL       | NULL        | NULL       | NULL     |

| max             |                    | NULL  | NULL  | NULL       | NULL            | NULL         | NULL         | NULL       | NULL        | NULL       | NULL     |

| num_nulls       | 0                  | NULL  | NULL  | NULL       | NULL            | NULL         | NULL         | NULL       | NULL        | NULL       | NULL     |

| distinct_count  | 2                  | NULL  | NULL  | NULL       | NULL            | NULL         | NULL         | NULL       | NULL        | NULL       | NULL     |

| avg_col_len     | 5.0                | NULL  | NULL  | NULL       | NULL            | NULL         | NULL         | NULL       | NULL        | NULL       | NULL     |

| max_col_len     | 5                  | NULL  | NULL  | NULL       | NULL            | NULL         | NULL         | NULL       | NULL        | NULL       | NULL     |

| num_trues       |                    | NULL  | NULL  | NULL       | NULL            | NULL         | NULL         | NULL       | NULL        | NULL       | NULL     |

| num_falses      |                    | NULL  | NULL  | NULL       | NULL            | NULL         | NULL         | NULL       | NULL        | NULL       | NULL     |

| bitVector       |                    | NULL  | NULL  | NULL       | NULL            | NULL         | NULL         | NULL       | NULL        | NULL       | NULL     |

| comment         | from deserializer  | NULL  | NULL  | NULL       | NULL            | NULL         | NULL         | NULL       | NULL        | NULL       | NULL     |

+-----------------+--------------------+-------+-------+------------+-----------------+--------------+--------------+------------+-------------+------------+----------+

注意事项

  • analyze table 会额外启动一个mapreduce job用于数据统计

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/100711.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

通俗易懂讲解大模型:Tokenizer

Tokenizer Tokenizer 是 NLP pipeline 的核心组件之一。Tokenizer 的目标是:将文本转换为模型可以处理的数据。模型只能处理数字,因此 Tokenizer 需要将文本输入转换为数字输入。 通常而言有三种类型的 Tokenizer :Word-based Tokenizer、Cha…

SpringMVC_SSM整合

一、回顾SpringMVC访问接口流程 1.容器加载分析 容器分析 手动注册WebApplicationContext public class ServletConfig extends AbstractDispatcherServletInitializer {Overrideprotected WebApplicationContext createServletApplicationContext() {//获取SpringMVC容器An…

9.3.3网络原理(网络层IP)

一.报文: 1.4位版本号:IPv4和IPv6(其它可能是实验室版本). 2.4位首部长度:和TCP一样,可变长,带选项,单位是4字节. 3.8位服务类型 4.16位总长度:IP报头 IP载荷 传输层是不知道载荷长度的,需要网络层来计算. IP报文 - IP报头 IP载荷 TCP报文 TCP载荷 IP载荷(TCP报文) …

AlmaLinux 经济收益增加,红帽 RHEL 源码限制不成威胁

导读红帽在两个月前发布公告表示,将限制对 Red Hat Enterprise Linux (RHEL) 源代码的访问,未来 CentOS Stream 将成为公共 RHEL 相关源代码发布的唯一仓库。对于这一决策,AlmaLinux OS Foundation 主席 Benny Vasquez 则向 SiliconANGLE 表示…

【Cisco Packet Tracer】管理方式,命令,接口trunk,VLAN

💐 🌸 🌷 🍀 🌹 🌻 🌺 🍁 🍃 🍂 🌿 🍄🍝 🍛 🍤 📃个人主页 :阿然成长日记 …

力扣(LeetCode)算法_C++——稀疏矩阵的乘法

给定两个 稀疏矩阵 :大小为 m x k 的稀疏矩阵 mat1 和大小为 k x n 的稀疏矩阵 mat2 ,返回 mat1 x mat2 的结果。你可以假设乘法总是可能的。 示例 1: 输入:mat1 [[1,0,0],[-1,0,3]], mat2 [[7,0,0],[0,0,0],[0,0,1]] 输出&am…

9、补充视频

改进后的dijkstra算法 利用小根堆 将小根堆特定位置更改,再改成小根堆 nodeHeap.addOrUpdateOrIgnore(edge.to, edge.weight + distance);//改进后的dijkstra算法 //从head出发,所有head能到达的节点,生成到达每个节点的最小路径记录并返回 public static HashMap<No…

Nginx教程

Nginx教程 01-Nginx简介02-windows安装Nginx03-Nginx目录结构04-Linux安装Nginx05-linux下源码安装nginx06-linux下nginx配置07-在docker中安装nginx08-源码安装和yum安装的区别09-Nginx运行组和运行用户10-卸载nginx11-nginx的基本原理和架构12-nginx是如何处理请求的13-nginx…

UDP协议结构及其注意事项

UDP报文结构 UDP报文结构主要是由两个部分组成的&#xff1a;UDP头部和数据部分。 UDP头部 源端口号&#xff1a;16位字段&#xff0c;指示数据发送方的端口号。目的端口号&#xff1a;16位字段&#xff0c;指示数据接收方端口号。UDP报文长度&#xff1a;16位字段&#xff0…

蓝牙协议栈BLE

前言 这阵子用到蓝牙比较多&#xff0c;想写一个专栏专门讲解蓝牙协议及其应用&#xff0c;本篇是第一篇文章&#xff0c;讲解低功耗蓝牙和蓝牙协议栈。 参考网上各大神文章&#xff0c;及瑞萨的文章&#xff0c;参考GPT&#xff0c;并且加入了一些本人的理解。 图片部分源自…

Linux常用命令——cpio命令

在线Linux命令查询工具 cpio 用来建立、还原备份档的工具程序 补充说明 cpio命令主要是用来建立或者还原备份档的工具程序&#xff0c;cpio命令可以复制文件到归档包中&#xff0c;或者从归档包中复制文件。 语法 cpio(选项)选项 -0或--null&#xff1a;接受新增列控制字…

SpringBoot项目--电脑商城【上传头像】

一、易错点 1.错误写法&#xff1a; 把文件存到数据库中,需要图片时访问数据库,数据库将文件解析为字节流返回,最后写到本地的某一个文件.这种方法太耗费资源和时间了 2.正确写法&#xff1a; 将对应的文件保存在操作系统上,然后再把这个文件路径记录下来,因为在记录路径的…