對於很是大的數據集,有時用戶須要使用的是一個具備表明性的查詢結果而不是所有結果。Hive能夠經過對錶進行抽樣來知足這個需求。spa
查詢表stu_buck中的數據。code
hive (default)> select * from stu_buck tablesample(bucket 1 out of 4 on id);
注:tablesample是抽樣語句,語法:TABLESAMPLE(BUCKET x OUT OF y) 。blog
y必須是table總bucket數的倍數或者因子。hive根據y的大小,決定抽樣的比例。io
例如,table總共分了4份,當y=2時,抽取(4/2=)2個bucket的數據,當y=8時,抽取(4/8=)1/2個bucket的數據。table
x表示從哪一個bucket開始抽取,若是須要取多個分區,之後的分區號爲當前分區號加上y。class
例如,table總bucket數爲4,tablesample(bucket 1 out of 2),表示總共抽取(4/2=)2個bucket的數據,抽取第1(x)個和第3(x+y)個bucket的數據。select
注意:x的值必須小於等於y的值,不然語法
FAILED: SemanticException [Error 10061]: Numerator should not be bigger than denominator in sample clause for table stu_buck數據