批量給hive的表加分割槽

2022-07-16 13:42:16 字數 894 閱讀 3714

要實現如下需求:

批量給hive的表加分割槽,分割槽都是這樣的格式 dt=「2012-07-01」

加分割槽的語句如下:

use test;alter table another_sku_uv add if not exists partition (dt='2012-07-12') location '/user/test/warehouse/mid.db/sku_uv/dt=2012-07-12';

現在在/user/test/warehouse/mid.db/sku_uv/ 下面有從2012-07-01 -- 2012-12-31 的分割槽資料.如何批量新增分割槽呢?

我想到了用shell。

#!/bin/bash 

#set -e

for ((i=0;i<190;i++))

do#d=`date -d "

- 1 day"'

+%y-%m-%d'`

s=`date -d "

2012-07-01

" +%s`

#echo"$s

"let

"t=$s+$i*86400

"m=`date -d "

@$t"

`d=`date -d "$m"

'+%y-%m-%d'`

if [ "

$d" = 2013-01-01 ]; then

exit 0;

else

hive -e "

use default;alter table another_sku_uv add if not exists partition (dt='$d') location '/user/test/warehouse/mid.db/sku_uv/dt=$d'"fi

done

hive 表的分割槽

hive的資料查詢一般會掃瞄整個表,當表資料太大時,就會消耗些時間,有時候我們只需要對部分資料感興趣,所以hive引入了分割槽的概念 hive的表分割槽區別於一般的分布式分割槽 hash分割槽,範圍分割槽,一致性分割槽 hive的分割槽是比較簡單的。他是根據hive的表結構,分割槽的字段設定將資料按...

hive表分割槽

hive對錶有分割槽的功能。hive根據表的列屬性值 諸如日期,城市 部門對錶進行分割槽 使用分割槽,能夠很容易查詢 到資料的一部分。表或分割槽被分為 buckets 桶 以便為資料 提供額外的資料結構,該資料結構被 用於提公升 查詢的有效性。buckets 桶 的工作依賴於表中某個列的 雜湊函式值...

Hive 表分割槽

基本知識 hadoop fs rmr hdfs hdfs hadoop fs put user hive warehouse data.txt hdfs hdfs data.txt 建立分割槽表 外部表 create external table if not exists employee id ...