hive

时间:2015-09-30 16:09:21

标签: hadoop hive sample sampling

“all_members”是hive中有10米行和1列的表:“membership_nbr”。我想抽样3000行。这就是我所做的:

hive>create table sample_members as select * from all_members limit 1;
hive>insert overwrite table sample_members select membership_nbr from all_members tablesample(3000 rows);
hive>select count(*) from sample_members;

确定45000

如果我用300行替换3000行,结果不会改变 我做错了吗?

1 个答案:

答案 0 :(得分:1)

表使用tablesample(3000 rows)进行采样不会从整个表中获取3000行,而是从每个输入拆分中获取3000行。

因此,您的查询可能会运行15个映射器。因此,每个映射器将获取3000行。总计3000 * 15 = 45000行。此外,如果将3000行更改为300行,则在采样后将获得4500行作为输出。

因此,根据您的要求,您必须提供tablesample(200 rows)。结果每个映射器将获取200行。最后,15个映射器将获取3000个采样行。

请参阅以下链接了解各种类型的采样: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Sampling