hive刪除partition遇到的編碼、轉義問題

來源:互聯網
上載者:User

問題:

線上出現垃圾資料,由於資料進hive採用的是dynamic partition,這些垃圾資料有些是partiition欄位

like:
>show partitions dpdw_traffic_base;

hp_stat_time=234123417234719237491/hp_log_type=0/hp_host=__HIVE_DEFAULT_PARTITION__/hp_from_type=__HIVE_DEFAULT_PARTITION__
hp_stat_time=r_ready%3D407;r_load%3D641/hp_log_type=0/hp_host=__HIVE_DEFAULT_PARTITION__/hp_from_type=__HIVE_DEFAULT_PARTITION__
hp_stat_time=r_ready%3D438;r_load%3D797/hp_log_type=0/hp_host=__HIVE_DEFAULT_PARTITION__/hp_from_type=__HIVE_DEFAULT_PARTITION__
.......

寫了一個指令碼清除垃圾資料:

#!/bin/shpname=`hadoop fs -ls /user/hive/warehouse/bi.db/dpdw_traffic_base | awk '{print $NF}' | awk  '{gsub(/\/user\/hive\/warehouse\/bi.db\/dpdw_traffic_base\/hp_stat_time=/,"",$0); print $0}'`for i in $pnamedo         len=`expr length $i`        if [ $len -ne 10 -a $i != '__HIVE_DEFAULT_PARTITION__' -a $i != 'items' ]        then                 name="hdfs://10.2.6.102/user/hive/warehouse/bi.db/dpdw_traffic_base/hp_stat_time="$i                hadoop fs -rmr $name                hive -e "use bi; alter table dpdw_traffic_base drop partition(hp_stat_time='$i')"        fidone

出現問題,類似於:

hp_stat_time=r_ready%3D407;r_load%3D641

的partition無法刪除

跟進後發現hive會自動對一些字元進行UTF-8編碼,此處%3D解碼後是'='

另外‘;’ 需要被轉義

so:

dpdw_traffic_base的partition:
hp_stat_time=r_ready%3D91;r_load%3D351/hp_log_type=0/hp_host=http%3A%2F%2Fwww.dianping.com%2Fsearch%2Fkeyword%2F10%2F0_%25E9%259B%2581%25E8%258D%25A1%25E6%2583%2585/hp_from_type=__HIVE_DEFAULT_PARTITION__

正確的刪除語句是:

> alter table dpdw_traffic_base drop partition(hp_stat_time='r_ready=91\;r_load=351');   
Dropping the partition hp_stat_time=r_ready%3D91;r_load%3D351/hp_log_type=0/hp_host=http%3A%2F%2Fwww.dianping.com%2Fsearch%2Fkeyword%2F10%2F0_%25E9%259B%2581%25E8%258D%25A1%25E6%2583%2585/hp_from_type=__HIVE_DEFAULT_PARTITION__
OK

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.