hive 的临时统计库 TempStatsStore

原文转载自:http://suanwuxian.com/?p=98

Hive Statistics

  • 一、 社区介绍
* [Hive Statistics](https://cwiki.apache.org/confluence/display/Hive/StatsDev)
* [HIVE-1362](https://issues.apache.org/jira/browse/HIVE-1362)
  • 二、配置方式
*默认使用derby作为临时统计库
1、要保证hadoop的每个slave节点的$HADOOP_HOME/lib下要包含有derby.jar
2、进行如下配置
$HIVE_CONF_DIR/hive-default.xml中使用的默认的derby数据作为临时数据统计库
<property>
<name>hive.stats.dbclass</name>
<value>jdbc:derby</value>
<description>The default database that stores temporary hive statistics.</description>
</property>

<property>
<name>hive.stats.autogather</name>
<value>true</value>
<description>A flag to gather statistics automatically during the INSERT OVERWRITE command.</description>
</property>

<property>
<name>hive.stats.jdbcdriver</name>
<value>org.apache.derby.jdbc.EmbeddedDriver</value>
<description>The JDBC driver for the database that stores temporary hive statistics.</description>
</property>

<property>
<name>hive.stats.dbconnectionstring</name>
<value>jdbc:derby:;databaseName=TempStatsStore;create=true</value>
<description>The default connection string for the database that stores temporary hive statistics.</description>
</property>

使用derby库作为临时统计数据库时,执行时会在当前的目录下创建一个TempStatsStore目录作为数据库。
*使用MySQL作为存放统计信息临时数据库 
1、要保证hadoop的每个slave节点的$HADOOP_HOME/lib下要包含有mysql-jdbc*.jar
2、要为所有的salve节点开发数据库访问权限
mysql> GRANT ALL PRIVILEGES ON  *.*  TO ‘root’@’10.249.197.42′ IDENTIFIED BY ‘root’  WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
3、配置信息如下
$HIVE_CONF_DIR/hive-site.xml
增加如下内容:
<property>
<name>hive.stats.dbconnectionstring</name>
<value>jdbc:mysql://hd17-vm1:3306/hive_stats?createDatabaseIfNotExist=true&amp;user=root&amp;password=root</value>
<description>The default connection string for the database that stores temporary hive statistics.</description>
</property>

<property>
<name>hive.stats.dbclass</name>
<value>jdbc:mysql</value>
<description>The default database that stores temporary hive statistics.</description>
</property>

<property>
<name>hive.stats.jdbcdriver</name>
<value>com.mysql.jdbc.Driver</value>
<description>The JDBC driver for the database that stores temporary hive statistics.</description>
</property>

*使用postgresql作为临时统计信息数据库
1:要求hive客户端端$HIVE_HOME/lib下包含有postgresql-9.1-902.jdbc4.jar
2:要求所有节点$HADOOP_HOME/lib下包含有postgresql-9.1-902.jdbc4.jar
3:修改10.227.8.16机器的pg_hba.conf使集群50个节点以及hive客户端ip都可以连接此pg
例如增加:
host hive_stats   payods   10.227.0.0/16  trust
这句话表示 允许ip地址是10.227.*.*的连接的payods用户连接hive_stats数据库
4:$HIVE_CONF_DIR/hive-site.xml新增如下信息
<property>
<name>hive.stats.dbconnectionstring</name>
<value>jdbc:postgresql://10.227.8.16/hive_stats?createDatabaseIfNotExist=true&amp;user=payods&amp;password=payods123</value>
<description>The default connection string for the database that stores temporary hive statistics.</description>
</property>

<property>
<name>hive.stats.dbclass</name>
<value>jdbc:postgresql</value>
<description>The default database that stores temporary hive statistics.</description>
</property>

<property>
<name>hive.stats.jdbcdriver</name>
<value>org.postgresql.Driver</value>
<description>The JDBC driver for the database that stores temporary hive statistics.</description>
</property>

<property>
<name>hive.stats.retries.max</name>
<value>3</value>
</property>
<property>
<name>hive.stats.jdbc.timeout</name>
<value>0</value>
</property>
需要注意到是这里的 set hive.stats.jdbc.timeout的值必须设置为0,否则会报如下异常
2013-03-01 13:56:41,205 INFO org.apache.hadoop.hive.ql.exec.TableScanOperator: StatsPublishing error: cannot connect to database.

这是因为ostgresql-9.1-902.jdbc4.jar 对jdbc4的支持还有限,有一些方法还没有实现。其中有setQueryTimeout没有实现,但其不是空方法,如果调用就会抛出异常,因此只能设置这项的值为0,避免抛出异常导致错误

  • 三、使用方式
* 非分区表
hive (default)> ANALYZE   TABLE src  COMPUTE STATISTICS;

hive (default)> desc formatted src;

Table Parameters:
last_modified_by         zongren
last_modified_time       1354590992
numFiles                 4
numPartitions            0
numRows                  0
rawDataSize              0
totalSize                41392
transient_lastDdlTime     1358387408
* 分区表
hive (default)> ANALYZE   TABLE srcpart partition (ds,hr)  COMPUTE STATISTICS;
hive(default)> ANALYZE   TABLE srcpart partition (ds=’2008-04-09′,hr=’11′)  COMPUTE STATISTICS;
hive (default)> desc formatted srcpart;

Table Parameters:
numFiles                 6
numPartitions            6
numRows                  0
rawDataSize              0
totalSize                34872

     transient_lastDdlTime     1358387355
hive (default)> desc formatted srcpart partition (ds=’2008-04-09′,hr=’11′);
Partition Parameters:
numFiles                 1
numRows                  0
rawDataSize              0
totalSize                5812
transient_lastDdlTime     1358386808
  • 四、 提供的统计项

numFiles 分区下或表下文件总个数

numPartitions 分区总个数
totalSize  分区下或整个表下的总文件大小
numRows 分区下或表下的总记录行数
rawDataSize  分区下或表下的原始数据大小
后期可以增加的统计项
分区下或表中指定列的排重值(也就是某列的count distinct)
分区下或表中指定列NULL值数量
最大或最小的k个值,k可以由用户指定
数据分布情况:频率以及分布情况
列的平均大小
数值型列的avg/sum等
值所占的百分比(可用于解决数据倾斜问题)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值