共用分割槽和分桶

2022-02-25 15:43:28 字數 1389 閱讀 8734

「partitioned by」必須在「clustered by」前面

製作3個檔案:

分為三個去插入

可以測試一下如果分桶在分割槽後面的效果怎麼樣

create table t_bucket_partition(id int)

clustered by (id) into 3 buckets

partitioned by (type string)

row format delimited fields terminated by '\t';

failed: parseexception line 3:0 missing eof at 'partitioned' near 'buckets'

create table t_partition_bucket(id int)

partitioned by (type string)

clustered by (id) into 3 buckets

row format delimited fields terminated by '\t';

說明:「partition (type='test')」需要提前

分為三個檔案,把資料載入到hive中的資料庫中去試一下

partition_bucket112

34partition_bucket256

78partition_bucket3910

1112

然後把資料載入到對應的**中去

load data local inpath '/home/briup/bd1902_hive/partition_bucket1' into table t_partition_bucket partition(type='1');

load data local inpath '/home/briup/bd1902_hive/partition_bucket2' into table t_partition_bucket partition(type='2');

load data local inpath '/home/briup/bd1902_hive/partition_bucket3' into table t_partition_bucket partition(type='3');

載入完後檢視一下資料:

select * from t_partition_bucket;

檢視一下分割槽:

show partitions t_partition_bucket;

然後以分桶形式檢視資料:

select * from t_partition_bucket tablesample(bucket 2 out of 3 on id);

實際意義:這樣做既可以達到分割槽又可以達到分組效果。分割槽方便快速查詢,加快查詢效率,分桶方便做資料和**驗證。

hive的分桶,和分割槽

開啟分桶模式 set hive.enforce.bucketing true 制定reduce個數是4 set mapreduce.job.reduces 4 建立乙個分桶表 create table stu buck sno int,sname string,string,sage int,sde...

Hive分割槽和分桶區別

一.定義上 分割槽 建立分割槽表 create table student id int,name string,age int,address string partitioned by dt string,type string 制定分割槽 row format delimited fields...

Hive 分割槽 和 分桶 的區別

背景 hive使用select語句進行查詢的時候一般會掃瞄整個表內容,會消耗很多時間做沒必要的工作。hive可以在建立表的時候指定分割槽空間,這樣在做查詢的時候就可以很好的提高查詢的效率。分割槽 在hdfs上的表現形式是乙個目錄,分桶 在hdfs上的表現形式是乙個單獨的檔案 建立分割槽表 creat...