Hive 数据抽样

Hive 抽样语法

Hive使用tablesample语法对表进行抽样,包含两种抽样方式桶抽样和块抽样

桶抽样

桶抽样语法:tablesample (bucket x out of y [on colname])

  • tablesample可以用在任何表上,不单单是分区表
  • colname用于对表中的行抽样, colname可以是任何非分区字段或者用rand()来表示用整行而非一个单独字段

整个表会以colname打散到y个桶里(编号从1到y),属于x桶的行会被抽出来
例如:

SELECT * FROM source TABLESAMPLE(BUCKET 3 OUT OF 32 ON rand()) s;

source表会按照整行分成32个桶,第三个桶的数据会抽样出来,s是表的别。

块抽样

Block sampling is available starting with Hive 0.8. Addressed under JIRA - https://issues.apache.org/jira/browse/HIVE-2121
block_sample: TABLESAMPLE (n PERCENT)
This will allow Hive to pick up at least n% data size (notice it doesn’t necessarily mean number of rows) as inputs. Only CombineHiveInputFormat is supported and some special compression formats are not handled. If we fail to sample it, the input of MapReduce job will be the whole table/partition. We do it in HDFS block level so that the sampling granularity is block size. For example, if block size is 256MB, even if n% of input size is only 100MB, you get 256MB of data.
In the following example the input size 0.1% or more will be used for the query.

随机抽样

分类随机抽样

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值