You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2013/02/26 20:16:01 UTC
svn commit: r1450365 - in
/hive/branches/ptf-windowing/ql/src/java/org/apache/hadoop/hive/ql/parse:
SemanticAnalyzer.java WindowingExprNodeEvaluatorFactory.java
Author: hashutosh
Date: Tue Feb 26 19:16:01 2013
New Revision: 1450365
URL: http://svn.apache.org/r1450365
Log:
HIVE-4076
Summary: Refactor
Test Plan: Existing test cases passed.
Reviewers: hbutani
Differential Revision: https://reviews.facebook.net/D8931
Modified:
hive/branches/ptf-windowing/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
hive/branches/ptf-windowing/ql/src/java/org/apache/hadoop/hive/ql/parse/WindowingExprNodeEvaluatorFactory.java
Modified: hive/branches/ptf-windowing/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hive/branches/ptf-windowing/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java?rev=1450365&r1=1450364&r2=1450365&view=diff
==============================================================================
--- hive/branches/ptf-windowing/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (original)
+++ hive/branches/ptf-windowing/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java Tue Feb 26 19:16:01 2013
@@ -983,7 +983,7 @@ public class SemanticAnalyzer extends Ba
throw new SemanticException(generateErrorMessage(ast,
checkLLFunctions.getErrString()));
}
- hasLLArgs = checkLLFunctions.isHasWindowingExprs();
+ hasLLArgs = checkLLFunctions.hasLeadLagExprs();
// if QB has WindowingClauses and no GroupBy clause
// - associate Having with qb.windowingSpec.
@@ -9915,27 +9915,34 @@ public class SemanticAnalyzer extends Ba
boolean isFunction = ( function.getType() == HiveParser.TOK_FUNCTION ||
function.getType() == HiveParser.TOK_FUNCTIONDI ||
function.getType() == HiveParser.TOK_FUNCTIONSTAR );
- String fnName = isFunction ? function.getChild(0).getText().toLowerCase() : null;
- boolean isWindowFunction = isFunction ?
- FunctionRegistry.isWindowFunction(fnName) : false;
- boolean isRankingOrNavFunction = !isFunction ? false :
- (
- FunctionRegistry.RANKING_FUNCTIONS.contains(fnName) ||
- FunctionRegistry.NAVIGATION_FUNCTIONS.contains(fnName)
- );
-
- boolean hasLLArgs = false;
if ( !isFunction ) {
return false;
}
+ String fnName = function.getChild(0).getText().toLowerCase();
+ if(!FunctionRegistry.isWindowFunction(fnName)) {
+ // Its either UDF, UDTF or lead or lag function.
+ if (hasWindowSpec){
+ // We currently supports windowing only with UDAFs, so if there is a windowing spec
+ // thats the error condition.
+ throw new SemanticException(generateErrorMessage(selectExpr,
+ "Currently windowing Specification can only be associated with a UDAF " +
+ "invocation or navigation functions"));
+ } else {
+ return false;
+ }
+ }
+
+ boolean hasLLArgs = false;
+ boolean isRankingOrNavFunction = FunctionRegistry.RANKING_FUNCTIONS.contains(fnName) ||
+ FunctionRegistry.NAVIGATION_FUNCTIONS.contains(fnName);
/*
- * If this is a Windowing Function and it has LeadLag expression in its args,
+ * If Windowing Function has LeadLag expression in its args,
* then it will be handled by WindowingTabFunc.
*/
- if ( isWindowFunction && !isRankingOrNavFunction ) {
-
+ if (!isRankingOrNavFunction ) {
+ // but lead/lag are not supported as an argument of ranking or navigation function.
TreeWizard tw = new TreeWizard(ParseDriver.adaptor, HiveParser.tokenNames);
CheckLeadLagInSelectExprs checkLLFunctions = new CheckLeadLagInSelectExprs(qb, dest);
for(int i=1; !hasLLArgs && i < function.getChildCount(); i++) {
@@ -9945,21 +9952,11 @@ public class SemanticAnalyzer extends Ba
throw new SemanticException(generateErrorMessage(selectExpr,
checkLLFunctions.getErrString()));
}
- hasLLArgs = checkLLFunctions.isHasWindowingExprs();
+ hasLLArgs = checkLLFunctions.hasLeadLagExprs();
}
}
- if ( hasWindowSpec && !isWindowFunction ) {
- throw new SemanticException(generateErrorMessage(selectExpr,
- "Currently windowing Specification can only be associated with a UDAF " +
- "invocation or navigation functions"));
- }
-
- if (
- (isWindowFunction && hasWindowSpec) ||
- (isRankingOrNavFunction && isWindowFunction) ||
- (isWindowFunction && hasLLArgs)
- ) {
+ if (hasWindowSpec || isRankingOrNavFunction || hasLLArgs) {
/*
* @revisit: what should I do if there are more than 3 children;
* i.e. more than one Identifier.
@@ -9986,7 +9983,7 @@ public class SemanticAnalyzer extends Ba
spec = new WindowingSpec();
qb.addDestToWindowingSpec(dest, spec);
}
- WindowFunctionSpec wFnSpec = processWindowFunction(spec, function,
+ WindowFunctionSpec wFnSpec = processWindowFunction(function,
hasWindowSpec ? windowSpec : null);
wFnSpec.setAlias(alias);
spec.addWindowFunction(wFnSpec);
@@ -10001,7 +9998,7 @@ public class SemanticAnalyzer extends Ba
{
QB qb;
String dest;
- boolean hasWindowingExprs = false;
+ boolean hasLeadLagExprs = false;
boolean error = false;
String errString;
@@ -10010,6 +10007,7 @@ public class SemanticAnalyzer extends Ba
this.dest = dest;
}
+ @Override
public void visit(Object t, Object parent, int childIndex, Map labels)
{
error = false; errString = null;
@@ -10030,7 +10028,7 @@ public class SemanticAnalyzer extends Ba
if (fnName.equals(FunctionRegistry.LEAD_FUNC_NAME)
|| fnName.equals(FunctionRegistry.LAG_FUNC_NAME))
{
- hasWindowingExprs = true;
+ hasLeadLagExprs = true;
}
else if ( FunctionRegistry.NAVIGATION_FUNCTIONS.contains(fnName)) {
error = true;
@@ -10043,8 +10041,8 @@ public class SemanticAnalyzer extends Ba
}
}
- public boolean isHasWindowingExprs() {
- return hasWindowingExprs;
+ public boolean hasLeadLagExprs() {
+ return hasLeadLagExprs;
}
protected boolean isError() {
@@ -10105,7 +10103,7 @@ public class SemanticAnalyzer extends Ba
checkLLFunctions.getErrString()));
}
- hasWindowingExprs = checkLLFunctions.isHasWindowingExprs();
+ hasWindowingExprs = checkLLFunctions.hasLeadLagExprs();
if ( hasWindowingExprs )
{
@@ -10128,8 +10126,7 @@ public class SemanticAnalyzer extends Ba
* - calling getColAlias with a null InputResolver and null defaultName.
* - so includeFunctionName should be true.
*/
- String[] colAlias = getColAlias(expr, null, null, true, -1);
- alias = colAlias[1];
+ alias = getColAlias(expr, null, null, true, -1)[1];
}
else {
alias = selectExpr.getChild(1).getText();
@@ -10226,9 +10223,8 @@ public class SemanticAnalyzer extends Ba
return partitioning;
}
- private WindowFunctionSpec processWindowFunction(WindowingSpec spec,
- ASTNode node,
- ASTNode wsNode) throws SemanticException {
+ private WindowFunctionSpec processWindowFunction(ASTNode node, ASTNode wsNode)
+ throws SemanticException {
WindowFunctionSpec wfSpec = new WindowFunctionSpec();
switch(node.getType()) {
@@ -10501,7 +10497,7 @@ public class SemanticAnalyzer extends Ba
String[] colAlias = getColAlias(expr, null, null, true, -1);
alias = colAlias[1];
}
- WindowFunctionSpec wFn = processWindowFunction(spec, expr, null);
+ WindowFunctionSpec wFn = processWindowFunction(expr, null);
wFn.setAlias(alias);
spec.addWindowFunction(wFn);
currQB.getParseInfo().getAllExprToColumnAlias().remove(expr);
Modified: hive/branches/ptf-windowing/ql/src/java/org/apache/hadoop/hive/ql/parse/WindowingExprNodeEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/hive/branches/ptf-windowing/ql/src/java/org/apache/hadoop/hive/ql/parse/WindowingExprNodeEvaluatorFactory.java?rev=1450365&r1=1450364&r2=1450365&view=diff
==============================================================================
--- hive/branches/ptf-windowing/ql/src/java/org/apache/hadoop/hive/ql/parse/WindowingExprNodeEvaluatorFactory.java (original)
+++ hive/branches/ptf-windowing/ql/src/java/org/apache/hadoop/hive/ql/parse/WindowingExprNodeEvaluatorFactory.java Tue Feb 26 19:16:01 2013
@@ -24,12 +24,8 @@ import org.apache.hadoop.hive.ql.exec.Ex
import org.apache.hadoop.hive.ql.exec.ExprNodeEvaluatorFactory;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.parse.PTFTranslator.LeadLagInfo;
-import org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc;
-import org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc;
import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
-import org.apache.hadoop.hive.ql.plan.ExprNodeFieldDesc;
import org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc;
-import org.apache.hadoop.hive.ql.plan.ExprNodeNullDesc;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDFLeadLag.GenericUDFLag;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDFLeadLag.GenericUDFLead;
@@ -50,7 +46,7 @@ public class WindowingExprNodeEvaluatorF
return ExprNodeEvaluatorFactory.get(desc);
}
- public static class FindLeadLagFuncExprs extends ExprNodeVisitor
+ public static class FindLeadLagFuncExprs
{
ExprNodeDesc topExpr;
LeadLagInfo llInfo;
@@ -61,7 +57,6 @@ public class WindowingExprNodeEvaluatorF
this.topExpr = topExpr;
}
- @Override
public void visit(ExprNodeGenericFuncDesc fnExpr) throws HiveException
{
GenericUDF fn = fnExpr.getGenericUDF();
@@ -72,34 +67,11 @@ public class WindowingExprNodeEvaluatorF
}
}
- static class ExprNodeVisitor
- {
- public void visit(ExprNodeColumnDesc e) throws HiveException
- {
- }
-
- public void visit(ExprNodeConstantDesc e) throws HiveException
- {
- }
-
- public void visit(ExprNodeFieldDesc e) throws HiveException
- {
- }
-
- public void visit(ExprNodeGenericFuncDesc e) throws HiveException
- {
- }
-
- public void visit(ExprNodeNullDesc e) throws HiveException
- {
- }
- }
-
static class ExprNodeWalker
{
- ExprNodeVisitor visitor;
+ FindLeadLagFuncExprs visitor;
- public ExprNodeWalker(ExprNodeVisitor visitor)
+ public ExprNodeWalker(FindLeadLagFuncExprs visitor)
{
super();
this.visitor = visitor;
@@ -119,56 +91,10 @@ public class WindowingExprNodeEvaluatorF
}
}
- if ( e instanceof ExprNodeColumnDesc)
+ if ( e instanceof ExprNodeGenericFuncDesc)
{
- walk((ExprNodeColumnDesc) e);
+ visitor.visit((ExprNodeGenericFuncDesc)e);
}
- else if ( e instanceof ExprNodeConstantDesc)
- {
- walk((ExprNodeConstantDesc) e);
- }
- else if ( e instanceof ExprNodeFieldDesc)
- {
- walk((ExprNodeFieldDesc) e);
- }
- else if ( e instanceof ExprNodeGenericFuncDesc)
- {
- walk((ExprNodeGenericFuncDesc) e);
- }
- else if ( e instanceof ExprNodeNullDesc)
- {
- walk((ExprNodeNullDesc) e);
- }
- else
- {
- throw new HiveException("Unknown Expr Type " + e.getClass().getName());
- }
- }
-
- private void walk(ExprNodeColumnDesc e) throws HiveException
- {
- visitor.visit(e);
- }
-
- private void walk(ExprNodeConstantDesc e) throws HiveException
- {
- visitor.visit(e);
- }
-
- private void walk(ExprNodeFieldDesc e) throws HiveException
- {
- visitor.visit(e);
- }
-
- private void walk(ExprNodeGenericFuncDesc e) throws HiveException
- {
- visitor.visit(e);
- }
-
- private void walk(ExprNodeNullDesc e) throws HiveException
- {
- visitor.visit(e);
}
}
-
}