Hive_Hive统计指令analyze table和 describe table

news2024/10/5 15:29:22

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

现在发现这些信息主要是基于 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.coloradmin.cn/o/977625.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Freecycle出现大规模数据泄露事件,影响700万用户

Freecycle是一个致力于交换二手物品的在线论坛,拥有来自全球5300多个地方城镇的近1100万名用户。该论坛近日发生了大规模数据泄露事件,700 多万用户受到影响。 该组织称是在上周三(8月30日)发现这一漏洞的,而在此之前…

Nand Flash的特性及烧录问题

目录 前言 一 Nand flash的特性 1 存储结构 2 OOB区域 3 位翻转 4 坏块及ECC 二 Nand系统裸片量产烧录 1 坏块处理策略 2 分区(Partition) 3 纠错码(Error Correction Codes,ECC) 4. 擦除坏块 🎈个人主页🎈:linux_嵌入式…

LeetCode(力扣)39. 组合总和Python

LeetCode20. 有效的括号 题目链接代码 题目链接 https://leetcode.cn/problems/combination-sum/description/ 代码 class Solution:def backtracking(self, candidates, stratindex, path, target, result, total):if total > target:returnif total target:result.ap…

php://filter协议在任意文件读取漏洞(附例题)

php://filter php://fiter 中文叫 元器封装,咱也不知道为什么这么翻译,目前我的理解是可以通过这个玩意对上面提到的php IO流进行处理,及现在可以对php的 IO流进行一定操作。 过滤器:及通过php://filter 对php 的IO流进行的具体…

React中父子组件参数传递讲解

文章目录 结合案例:github搜索案例1.父容器代码2.搜索Search子模块代码3.展示Lisi子模块代码 父子参数传递分析1.子(Search)传父(App)2.父(App)传子(List) 结合案例:github搜索案例 案例结果展示如下图 1.父容器代码 import React, { Component } fr…

经典浏览器の介绍

经典浏览器,这里给你介绍几款常见的浏览器: Google Chrome:Google Chrome是由Google开发的一款流行的浏览器。它以出色的性能和速度而闻名,能够快速加载网页。Chrome还支持大量的扩展和应用程序,可以个性化定制浏览器功…

二进制安全虚拟机Protostar靶场(2)基础知识讲解,栈溢出覆盖变量 Stack One,Stack Two

前言 Protostar靶场的安装和一些二进制安全的基础介绍在前文已经介绍过了,这里是文章链接 https://blog.csdn.net/qq_45894840/article/details/129490504?spm1001.2014.3001.5501什么是缓冲区溢出 当系统向缓冲区写入的数据多于它可以容纳的数据时,…

算法通关村第十九关——最小路径和

LeetCode64. 给定一个包含非负整数的 m n 网格 grid,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小。 输入:grid[[1,3,1],[1,5,1],[4,2,1]] 输出:7 解释:因为路径1→3→1→1→1的总和最小。 public int minPath…

交叉熵损失函数(Cross-Entropy Loss)

交叉熵损失函数(Cross-Entropy Loss)是在深度学习中常用的损失函数之一,它适用于分类问题。交叉熵损失函数的作用是衡量预测结果与真实标签之间的差距,从而用于模型的优化。 越接近真实标签,损失越小。在交叉熵损失函…

时序预测 | MATLAB实现LSSVM最小二乘支持向量机时间序列预测未来

时序预测 | MATLAB实现LSSVM最小二乘支持向量机时间序列预测未来 目录 时序预测 | MATLAB实现LSSVM最小二乘支持向量机时间序列预测未来预测效果基本介绍程序设计参考资料 预测效果 基本介绍 1.Matlab实现LSSVM时间序列预测未来(最小二乘支持向量机); 2.运行环境Mat…

VIRTIO-BLK代码分析(1)VIRTIO设备的模拟

VIRTIO设备的模拟是由QEMU实现的,它的具现化由函数virtio_device_class_init()实现。 VIRTIO PCI设备包含common/isr/device/notify BAR,QEMU模拟并注册这几个BAR MR,这里同时也注册read/write函数。 VIRTIO-BLK设备的具现化由函数virtio_blk…

974. 和可被 K 整除的子数组

974. 和可被 K 整除的子数组 C代码:滑动窗口 // 1、最长子数组 2、两个单调队列、求最大值-最小值,判断是否满足条件 3、满足记录长度 // 窗口移动条件:int longestSubarray(int* nums, int numsSize, int limit){int queMax[numsSize];in…

【C语言】文件操作(上)

一.什么是文件 文件是磁盘上的文件,文件中存放的数据不随程序的退出而销毁. 二.文件的打开与关闭 1.文件指针 每个被使用的文件都在内存中开辟了一个相应的文件信息区,用来存放文件的相关信息(如文件的名字,文件状态及文件当前的位置等&…

包管理工具--》npm的配置及使用(二)

在阅读本篇文章前请先阅读包管理工具--》npm的配置及使用(一) 目录 🌟语义版本 避免还原的差异 npm的差异版本处理 🌟npm 脚本 (npm scripts) 🌟运行环境配置 在node中读取package.json …

l8-d7 实现TCP通信

一、TCP服务器的实现(理论) #include <sys/types.h> #include <sys/socket.h> int socket(int domain, int type, int protocol); -domain: 指定通信域&#xff08;通信地址族&#xff09;; -type: 指定套接字类型; -protocol: 指定协议; 套接字类型与协议 -type:…

0925hw

1.登录账号密码 void sign_in(FILE *fp)//注册 {char usrname[10];char pwd[12];printf("输入账户:");scanf("%s",usrname);printf("输入密码:");scanf(" %s",pwd);fprintf(fp,"%s %s\n",usrname,pwd);printf("注册成…

postgresql-常用日期函数

postgresql-常用日期函数 简介计算时间间隔获取时间中的信息截断日期/时间创建日期/时间获取系统时间时区转换 简介 PostgreSQL 提供了以下日期和时间运算的算术运算符。 获取当前系统时间 select current_date,current_time,current_timestamp ;-- 当前系统时间一周后的日…

Spring——Spring IOC原理

摘要 IoC 不是一种技术&#xff0c;只是一种思想&#xff0c;一个重要的面向对象编程的法则&#xff0c;它能指导我们如何设计出松耦合、更优良的程序。传统应用程序都是由我们在类内部主动创建依赖对象&#xff0c;从而导致类与类之间高耦合&#xff0c;难于测试&#xff1b;…

电脑dll修复精灵下载,一键修复(win系统)MSVCP100/110/120/140.dll丢失方法

今天&#xff0c;我将为大家分享关于电脑vcruntime140.dll丢失的5种修复方法。在我们的日常生活中&#xff0c;电脑出现问题是常有的事&#xff0c;而vcruntime140.dll丢失则是其中较为常见的一种问题。那么&#xff0c;什么是vcruntime140.dll?它有什么作用&#xff1f;又有多…

如何从任何苹果、Windows或安卓设备访问iCloud照片

本文介绍了如何在各种设备上访问iCloud照片库,包括iPhone和iPad、Mac、Windows PC和Android设备。说明适用于iOS 13及以上版本、iPadOS 13及以上、macOS Big Sur(10.16)和Catalina(10.15)、Windows 10或11以及Android 10。 从iPhone、iPod Touch和iPad访问iCloud照片 照…