use of org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver in project flink by apache.
the class HiveParserSubQueryUtils method checkAggOrWindowing.
/*
* is this expr a UDAF invocation; does it imply windowing
* @return
* 0 if implies neither
* 1 if implies aggregation
* 2 if implies count
* 3 if implies windowing
*/
static int checkAggOrWindowing(HiveParserASTNode expressionTree) throws SemanticException {
int exprTokenType = expressionTree.getToken().getType();
if (exprTokenType == HiveASTParser.TOK_FUNCTION || exprTokenType == HiveASTParser.TOK_FUNCTIONDI || exprTokenType == HiveASTParser.TOK_FUNCTIONSTAR) {
assert (expressionTree.getChildCount() != 0);
if (expressionTree.getChild(expressionTree.getChildCount() - 1).getType() == HiveASTParser.TOK_WINDOWSPEC) {
return 3;
}
if (expressionTree.getChild(0).getType() == HiveASTParser.Identifier) {
String functionName = HiveParserBaseSemanticAnalyzer.unescapeIdentifier(expressionTree.getChild(0).getText());
GenericUDAFResolver udafResolver = FunctionRegistry.getGenericUDAFResolver(functionName);
if (udafResolver != null) {
// corr subqueries.
if (udafResolver instanceof GenericUDAFCount) {
return 2;
}
return 1;
}
}
}
int r = 0;
for (int i = 0; i < expressionTree.getChildCount(); i++) {
int c = checkAggOrWindowing((HiveParserASTNode) expressionTree.getChild(i));
r = Math.max(r, c);
}
return r;
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver in project hive by apache.
the class SubQueryUtils method checkAggOrWindowing.
/*
* is this expr a UDAF invocation; does it imply windowing
* @return
* 0 if implies neither
* 1 if implies aggregation
* 2 if implies count
* 3 if implies windowing
*/
static int checkAggOrWindowing(ASTNode expressionTree) throws SemanticException {
int exprTokenType = expressionTree.getToken().getType();
if (exprTokenType == HiveParser.TOK_FUNCTION || exprTokenType == HiveParser.TOK_FUNCTIONDI || exprTokenType == HiveParser.TOK_FUNCTIONSTAR) {
assert (expressionTree.getChildCount() != 0);
if (expressionTree.getChild(expressionTree.getChildCount() - 1).getType() == HiveParser.TOK_WINDOWSPEC) {
return 3;
}
if (expressionTree.getChild(0).getType() == HiveParser.Identifier) {
String functionName = SemanticAnalyzer.unescapeIdentifier(expressionTree.getChild(0).getText());
GenericUDAFResolver udafResolver = FunctionRegistry.getGenericUDAFResolver(functionName);
if (udafResolver != null) {
// corr subqueries.
if (udafResolver instanceof GenericUDAFCount) {
return 2;
}
return 1;
}
}
}
int r = 0;
for (int i = 0; i < expressionTree.getChildCount(); i++) {
int c = checkAggOrWindowing((ASTNode) expressionTree.getChild(i));
r = Math.max(r, c);
}
return r;
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver in project hive by apache.
the class SubQueryUtils method checkForSubqueries.
static void checkForSubqueries(ASTNode node, boolean disallow) throws SemanticException {
// allow NOT but throw an error for rest
if (node.getType() == HiveParser.TOK_SUBQUERY_EXPR && disallow) {
throw new CalciteSubquerySemanticException(ErrorMsg.UNSUPPORTED_SUBQUERY_EXPRESSION.getMsg("Invalid subquery. Subquery in UDAF is not allowed."));
}
if (node.getType() == HiveParser.TOK_FUNCTION || node.getType() == HiveParser.TOK_FUNCTIONDI || node.getType() == HiveParser.TOK_FUNCTIONSTAR) {
if (node.getChild(0).getType() == HiveParser.Identifier) {
String functionName = SemanticAnalyzer.unescapeIdentifier(node.getChild(0).getText());
GenericUDAFResolver udafResolver = FunctionRegistry.getGenericUDAFResolver(functionName);
if (udafResolver != null) {
disallow = disallow || true;
}
}
}
for (int i = 0; i < node.getChildCount(); i++) {
checkForSubqueries((ASTNode) node.getChild(i), disallow);
}
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver in project hive by apache.
the class AggregationBase method getEvaluator.
public static GenericUDAFEvaluator getEvaluator(String aggregationFunctionName, TypeInfo typeInfo) throws SemanticException {
GenericUDAFResolver resolver = FunctionRegistry.getGenericUDAFResolver(aggregationFunctionName);
TypeInfo[] parameters = new TypeInfo[] { typeInfo };
GenericUDAFEvaluator evaluator = resolver.getEvaluator(parameters);
return evaluator;
}
use of org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver in project hive by apache.
the class Registry method getGenericWindowingEvaluator.
public GenericUDAFEvaluator getGenericWindowingEvaluator(String functionName, List<ObjectInspector> argumentOIs, boolean isDistinct, boolean isAllColumns, boolean respectNulls) throws SemanticException {
functionName = functionName.toLowerCase();
WindowFunctionInfo info = getWindowFunctionInfo(functionName);
if (info == null) {
return null;
}
if (!functionName.equals(FunctionRegistry.LEAD_FUNC_NAME) && !functionName.equals(FunctionRegistry.LAG_FUNC_NAME)) {
return getGenericUDAFEvaluator(functionName, argumentOIs, true, isDistinct, isAllColumns, respectNulls);
}
// this must be lead/lag UDAF
ObjectInspector[] args = new ObjectInspector[argumentOIs.size()];
GenericUDAFResolver udafResolver = info.getGenericUDAFResolver();
GenericUDAFParameterInfo paramInfo = new SimpleGenericUDAFParameterInfo(argumentOIs.toArray(args), true, isDistinct, isAllColumns);
return ((GenericUDAFResolver2) udafResolver).getEvaluator(paramInfo);
}
Aggregations