diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java index 8e1b98b..e067cca 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java @@ -1535,6 +1535,14 @@ public static boolean impliesOrder(String functionName) throws SemanticException return false; } + public static boolean pivotResult(String functionName) throws SemanticException { + WindowFunctionInfo windowInfo = getWindowFunctionInfo(functionName); + if (windowInfo != null) { + return windowInfo.isPivotResult(); + } + return false; + } + public static boolean isTableFunction(String functionName) throws SemanticException { FunctionInfo tFInfo = getFunctionInfo(functionName); diff --git ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/TypeConverter.java ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/TypeConverter.java index c2ff766..13c8c23 100644 --- ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/TypeConverter.java +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/TypeConverter.java @@ -240,7 +240,7 @@ public static TypeInfo convert(RelDataType rType) { } else if (rType.getKeyType() != null) { return convertMapType(rType); } else { - return convertPrimtiveType(rType); + return convertPrimitiveType(rType); } } @@ -271,7 +271,7 @@ public static TypeInfo convertListType(RelDataType rType) { return TypeInfoFactory.getListTypeInfo(convert(rType.getComponentType())); } - public static TypeInfo convertPrimtiveType(RelDataType rType) { + public static TypeInfo convertPrimitiveType(RelDataType rType) { switch (rType.getSqlTypeName()) { case BOOLEAN: return TypeInfoFactory.booleanTypeInfo; diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java index bfd59ea..3b8ade5 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java @@ -1827,7 +1827,11 @@ private AggInfo getHiveAggInfo(ASTNode aggAst, int aggFnLstArgIndx, RowResolver // 3.3.2 Get UDAF Info using UDAF Evaluator GenericUDAFInfo udaf = SemanticAnalyzer.getGenericUDAFInfo(genericUDAFEvaluator, amode, aggParameters); - udafRetType = udaf.returnType; + if (FunctionRegistry.pivotResult(aggName)) { + udafRetType = ((ListTypeInfo)udaf.returnType).getListElementTypeInfo(); + } else { + udafRetType = udaf.returnType; + } } } catch (Exception e) { LOG.debug("CBO: Couldn't Obtain UDAF evaluators for " + aggName