Index: ql/src/test/results/clientpositive/query_properties.q.out =================================================================== --- ql/src/test/results/clientpositive/query_properties.q.out (revision 0) +++ ql/src/test/results/clientpositive/query_properties.q.out (revision 0) @@ -0,0 +1,88 @@ +PREHOOK: query: select * from src a join src b on a.key = b.key limit 1 +PREHOOK: type: QUERY +PREHOOK: Input: default@src +PREHOOK: Output: file:/var/folders/Y1/Y1Kf7th8FAawW1lYb6Tt+l+pemQ/-Tmp-/kevinwilfong/hive_2011-09-16_11-54-42_960_5653363332742654251/-mr-10000 +Has Join: true +Has Group By: false +Has Sort By: false +Has Order By: false +Has Group By After Join: false +Uses Script: false +0 val_0 0 val_0 +PREHOOK: query: select * from src group by src.key, src.value limit 1 +PREHOOK: type: QUERY +PREHOOK: Input: default@src +PREHOOK: Output: file:/var/folders/Y1/Y1Kf7th8FAawW1lYb6Tt+l+pemQ/-Tmp-/kevinwilfong/hive_2011-09-16_11-54-49_423_164652702948209165/-mr-10000 +Has Join: false +Has Group By: true +Has Sort By: false +Has Order By: false +Has Group By After Join: false +Uses Script: false +0 val_0 +PREHOOK: query: select * from src order by src.key limit 1 +PREHOOK: type: QUERY +PREHOOK: Input: default@src +PREHOOK: Output: file:/var/folders/Y1/Y1Kf7th8FAawW1lYb6Tt+l+pemQ/-Tmp-/kevinwilfong/hive_2011-09-16_11-54-56_926_2982009198238692420/-mr-10000 +Has Join: false +Has Group By: false +Has Sort By: false +Has Order By: true +Has Group By After Join: false +Uses Script: false +0 val_0 +PREHOOK: query: select * from src sort by src.key limit 1 +PREHOOK: type: QUERY +PREHOOK: Input: default@src +PREHOOK: Output: file:/var/folders/Y1/Y1Kf7th8FAawW1lYb6Tt+l+pemQ/-Tmp-/kevinwilfong/hive_2011-09-16_11-55-01_170_7585562645941452925/-mr-10000 +Has Join: false +Has Group By: false +Has Sort By: true +Has Order By: false +Has Group By After Join: false +Uses Script: false +0 val_0 +PREHOOK: query: select a.key, sum(b.value) from src a join src b on a.key = b.key group by a.key limit 1 +PREHOOK: type: QUERY +PREHOOK: Input: default@src +PREHOOK: Output: file:/var/folders/Y1/Y1Kf7th8FAawW1lYb6Tt+l+pemQ/-Tmp-/kevinwilfong/hive_2011-09-16_11-55-09_427_4884717680516854604/-mr-10000 +Has Join: true +Has Group By: true +Has Sort By: false +Has Order By: false +Has Group By After Join: true +Uses Script: false +0 0.0 +PREHOOK: query: select transform(*) using 'cat' from src limit 1 +PREHOOK: type: QUERY +PREHOOK: Input: default@src +PREHOOK: Output: file:/var/folders/Y1/Y1Kf7th8FAawW1lYb6Tt+l+pemQ/-Tmp-/kevinwilfong/hive_2011-09-16_11-55-18_944_6737962795496307585/-mr-10000 +Has Join: false +Has Group By: false +Has Sort By: false +Has Order By: false +Has Group By After Join: false +Uses Script: true +238 val_238 +PREHOOK: query: select key, sum(value) from (select a.key as key, b.value as value from src a join src b on a.key = b.key) c group by key limit 1 +PREHOOK: type: QUERY +PREHOOK: Input: default@src +PREHOOK: Output: file:/var/folders/Y1/Y1Kf7th8FAawW1lYb6Tt+l+pemQ/-Tmp-/kevinwilfong/hive_2011-09-16_11-55-23_100_2995802865410860252/-mr-10000 +Has Join: true +Has Group By: true +Has Sort By: false +Has Order By: false +Has Group By After Join: false +Uses Script: false +0 0.0 +PREHOOK: query: select * from src a join src b on a.key = b.key order by a.key limit 1 +PREHOOK: type: QUERY +PREHOOK: Input: default@src +PREHOOK: Output: file:/var/folders/Y1/Y1Kf7th8FAawW1lYb6Tt+l+pemQ/-Tmp-/kevinwilfong/hive_2011-09-16_11-55-33_041_9161248061287188895/-mr-10000 +Has Join: true +Has Group By: false +Has Sort By: false +Has Order By: true +Has Group By After Join: false +Uses Script: false +0 val_0 0 val_0 Index: ql/src/test/org/apache/hadoop/hive/ql/hooks/CheckQueryPropertiesHook.java =================================================================== --- ql/src/test/org/apache/hadoop/hive/ql/hooks/CheckQueryPropertiesHook.java (revision 0) +++ ql/src/test/org/apache/hadoop/hive/ql/hooks/CheckQueryPropertiesHook.java (revision 0) @@ -0,0 +1,51 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hive.ql.hooks; + +import org.apache.hadoop.hive.ql.QueryProperties; +import org.apache.hadoop.hive.ql.session.SessionState; +import org.apache.hadoop.hive.ql.session.SessionState.LogHelper; + +/** + * + * CheckQueryPropertiesHook. + * + * This hook prints the values in the QueryProperties object contained in the QueryPlan + * in the HookContext passed to the hook. + */ +public class CheckQueryPropertiesHook implements ExecuteWithHookContext { + + public void run(HookContext hookContext) { + LogHelper console = SessionState.getConsole(); + + if (console == null) { + return; + } + + QueryProperties queryProps = hookContext.getQueryPlan().getQueryProperties(); + + if (queryProps != null) { + console.printError("Has Join: " + queryProps.hasJoin()); + console.printError("Has Group By: " + queryProps.hasGroupBy()); + console.printError("Has Sort By: " + queryProps.hasSortBy()); + console.printError("Has Order By: " + queryProps.hasOrderBy()); + console.printError("Has Group By After Join: " + queryProps.hasJoinFollowedByGroupBy()); + console.printError("Uses Script: " + queryProps.usesScript()); + } + } +} \ No newline at end of file Index: ql/src/test/queries/clientpositive/query_properties.q =================================================================== --- ql/src/test/queries/clientpositive/query_properties.q (revision 0) +++ ql/src/test/queries/clientpositive/query_properties.q (revision 0) @@ -0,0 +1,12 @@ +set hive.exec.post.hooks = org.apache.hadoop.hive.ql.hooks.CheckQueryPropertiesHook; + +select * from src a join src b on a.key = b.key limit 1; +select * from src group by src.key, src.value limit 1; +select * from src order by src.key limit 1; +select * from src sort by src.key limit 1; +select a.key, sum(b.value) from src a join src b on a.key = b.key group by a.key limit 1; +select transform(*) using 'cat' from src limit 1; + +select key, sum(value) from (select a.key as key, b.value as value from src a join src b on a.key = b.key) c group by key limit 1; +select * from src a join src b on a.key = b.key order by a.key limit 1; + Index: ql/src/java/org/apache/hadoop/hive/ql/QueryPlan.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/QueryPlan.java (revision 1170719) +++ ql/src/java/org/apache/hadoop/hive/ql/QueryPlan.java (working copy) @@ -88,6 +88,8 @@ private HashSet done; private HashSet started; + private QueryProperties queryProperties; + public QueryPlan() { } @@ -110,6 +112,7 @@ counters = new HashMap>(); done = new HashSet(); started = new HashSet(); + queryProperties = sem.getQueryProperties(); } public String getQueryStr() { @@ -737,4 +740,8 @@ public void setLineageInfo(LineageInfo linfo) { this.linfo = linfo; } + + public QueryProperties getQueryProperties() { + return queryProperties; + } } Index: ql/src/java/org/apache/hadoop/hive/ql/QueryProperties.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/QueryProperties.java (revision 0) +++ ql/src/java/org/apache/hadoop/hive/ql/QueryProperties.java (revision 0) @@ -0,0 +1,91 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql; + +/** + * + * QueryProperties. + * + * A structure to contain features of a query that are determined + * during parsing and may be useful for categorizing a query type + * + * These inlucde whether the query contains: + * a join clause, a group by clause, an order by clause, a sort by + * clause, a group by clause following a join clause, and whether + * the query uses a script for mapping/reducing + */ +public class QueryProperties { + + boolean hasJoin = false; + boolean hasGroupBy = false; + boolean hasOrderBy = false; + boolean hasSortBy = false; + boolean hasJoinFollowedByGroupBy = false; + + // does the query have a using clause + boolean usesScript = false; + + public boolean hasJoin() { + return hasJoin; + } + + public void setHasJoin(boolean hasJoin) { + this.hasJoin = hasJoin; + } + + public boolean hasGroupBy() { + return hasGroupBy; + } + + public void setHasGroupBy(boolean hasGroupBy) { + this.hasGroupBy = hasGroupBy; + } + + public boolean hasOrderBy() { + return hasOrderBy; + } + + public void setHasOrderBy(boolean hasOrderBy) { + this.hasOrderBy = hasOrderBy; + } + + public boolean hasSortBy() { + return hasSortBy; + } + + public void setHasSortBy(boolean hasSortBy) { + this.hasSortBy = hasSortBy; + } + + public boolean hasJoinFollowedByGroupBy() { + return hasJoinFollowedByGroupBy; + } + + public void setHasJoinFollowedByGroupBy(boolean hasJoinFollowedByGroupBy) { + this.hasJoinFollowedByGroupBy = hasJoinFollowedByGroupBy; + } + + public boolean usesScript() { + return usesScript; + } + + public void setUsesScript(boolean usesScript) { + this.usesScript = usesScript; + } +} Index: ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java (revision 1170719) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java (working copy) @@ -36,6 +36,7 @@ import org.apache.hadoop.hive.metastore.api.FieldSchema; import org.apache.hadoop.hive.metastore.api.Order; import org.apache.hadoop.hive.ql.Context; +import org.apache.hadoop.hive.ql.QueryProperties; import org.apache.hadoop.hive.ql.exec.FetchTask; import org.apache.hadoop.hive.ql.exec.Task; import org.apache.hadoop.hive.ql.exec.Utilities; @@ -71,6 +72,7 @@ protected Context ctx; protected HashMap idToTableNameMap; + protected QueryProperties queryProperties; public static int HIVE_COLUMN_ORDER_ASC = 1; public static int HIVE_COLUMN_ORDER_DESC = 0; @@ -762,4 +764,8 @@ public Hive getDb() { return db; } + + public QueryProperties getQueryProperties() { + return queryProperties; + } } Index: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (revision 1170719) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (working copy) @@ -46,6 +46,7 @@ import org.apache.hadoop.hive.metastore.api.MetaException; import org.apache.hadoop.hive.metastore.api.Order; import org.apache.hadoop.hive.ql.Context; +import org.apache.hadoop.hive.ql.QueryProperties; import org.apache.hadoop.hive.ql.exec.AbstractMapJoinOperator; import org.apache.hadoop.hive.ql.exec.ColumnInfo; import org.apache.hadoop.hive.ql.exec.ConditionalTask; @@ -279,6 +280,7 @@ HiveConf.ConfVars.HIVE_AUTOGEN_COLUMNALIAS_PREFIX_LABEL); autogenColAliasPrfxIncludeFuncName = HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_AUTOGEN_COLUMNALIAS_PREFIX_INCLUDEFUNCNAME); + queryProperties = new QueryProperties(); } @Override @@ -759,6 +761,7 @@ } else if (frm.getToken().getType() == HiveParser.TOK_LATERAL_VIEW) { processLateralView(qb, frm); } else if (isJoinToken(frm)) { + queryProperties.setHasJoin(true); processJoin(qb, frm); qbp.setJoinExpr(frm); } @@ -787,6 +790,7 @@ case HiveParser.TOK_SORTBY: // Get the sort by aliases - these are aliased to the entries in the // select list + queryProperties.setHasSortBy(true); qbp.setSortByExprForClause(ctx_1.dest, ast); if (qbp.getClusterByForClause(ctx_1.dest) != null) { throw new SemanticException(generateErrorMessage(ast, @@ -801,6 +805,7 @@ case HiveParser.TOK_ORDERBY: // Get the order by aliases - these are aliased to the entries in the // select list + queryProperties.setHasOrderBy(true); qbp.setOrderByExprForClause(ctx_1.dest, ast); if (qbp.getClusterByForClause(ctx_1.dest) != null) { throw new SemanticException(generateErrorMessage(ast, @@ -811,6 +816,10 @@ case HiveParser.TOK_GROUPBY: // Get the groupby aliases - these are aliased to the entries in the // select list + queryProperties.setHasGroupBy(true); + if (qbp.getJoinExpr() != null) { + queryProperties.setHasJoinFollowedByGroupBy(true); + } if (qbp.getSelForClause(ctx_1.dest).getToken().getType() == HiveParser.TOK_SELECTDI) { throw new SemanticException(generateErrorMessage(ast, ErrorMsg.SELECT_DISTINCT_WITH_GROUPBY.getMsg())); @@ -2066,6 +2075,7 @@ boolean isInTransform = (selExprList.getChild(posn).getChild(0).getType() == HiveParser.TOK_TRANSFORM); if (isInTransform) { + queryProperties.setUsesScript(true); globalLimitCtx.setHasTransformOrUDTF(true); trfm = (ASTNode) selExprList.getChild(posn).getChild(0); }