Hive 強制指定分區鍵

來源:互聯網
上載者:User

最近在做Hive的查詢平台,需要考慮的比較多,其中一點就是對於分區表要限制使用者的查詢量,主要是要使用者必須指定分區鍵.一開始的想法步子比較大就是做HQL解析,不過由於項目周期壓力暫緩,這時發現了一個參數:hive.partition.pruninghttps://issues.apache.org/jira/browse/HADOOP-4345)不過不能高興的太早,CDH4.2.0的Hive並沒有merge進來,不過還好有另外一個參數:hive.mapred.mode
當mode=strict時做什麼項目官方文檔別沒看到詳細的說明,看代碼吧後結論如下:
最後使用這個參數,並對異常捕獲進行使用者提示.
1.不準對分區表不加分區鍵查詢

if (tab.isPartitioned()) {

if ("strict".equalsIgnoreCase(HiveConf.getVar(conf,

HiveConf.ConfVars.HIVEMAPREDMODE))){

if (!hasColumnExpr(prunerExpr)){

thrownewSemanticException(ErrorMsg.NO_PARTITION_PREDICATE

.getMsg("for Alias \"" + alias + "\" Table \""

+ tab.getTableName() + "\""));

}

    }
2.不準笛卡爾積

if (reduceKeys.size() ==0) {

numReds = 1;

if (conf.getVar(HiveConf.ConfVars.HIVEMAPREDMODE).equalsIgnoreCase(

"strict")){

thrownewSemanticException(ErrorMsg.NO_CARTESIAN_PRODUCT.getMsg());

}

  }
3.不準order by 不加limit

if (sortExprs == null) {

sortExprs =qb.getParseInfo().getOrderByForClause(dest);

if (sortExprs != null) {

assert numReducers == 1;

Integerlimit = qb.getParseInfo().getDestLimit(dest);

if (conf.getVar(HiveConf.ConfVars.HIVEMAPREDMODE).equalsIgnoreCase(

"strict")

&& limit == null) {

thrownew SemanticException(generateErrorMessage(sortExprs,

ErrorMsg.NO_LIMIT_WITH_ORDERBY.getMsg()));

}

}

  }



本文出自 “MIKE老畢的部落格” 部落格,請務必保留此出處http://boylook.blog.51cto.com/7934327/1302067

相關文章

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.