Skip to content

Commit 4efa6c5

Browse files
pzzsmarmbrus
authored andcommitted
[SPARK-6409][SQL] It is not necessary that avoid old inteface of hive, because this will make some UDAF can not work.
spark avoid old inteface of hive, then some udaf can not work like "org.apache.hadoop.hive.ql.udf.generic.GenericUDAFAverage" Author: DoingDone9 <[email protected]> Closes apache#5131 from DoingDone9/udaf and squashes the following commits: 9de08d0 [DoingDone9] Update HiveUdfSuite.scala 49c62dc [DoingDone9] Update hiveUdfs.scala 98b134f [DoingDone9] Merge pull request apache#5 from apache/master 161cae3 [DoingDone9] Merge pull request apache#4 from apache/master c87e8b6 [DoingDone9] Merge pull request #3 from apache/master cb1852d [DoingDone9] Merge pull request #2 from apache/master c3f046f [DoingDone9] Merge pull request #1 from apache/master (cherry picked from commit 968408b) Signed-off-by: Michael Armbrust <[email protected]>
1 parent 6791f42 commit 4efa6c5

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/hiveUdfs.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,8 @@ private[hive] case class HiveUdafFunction(
373373

374374
private val returnInspector = function.init(GenericUDAFEvaluator.Mode.COMPLETE, inspectors)
375375

376-
// Cast required to avoid type inference selecting a deprecated Hive API.
377376
private val buffer =
378-
function.getNewAggregationBuffer.asInstanceOf[GenericUDAFEvaluator.AbstractAggregationBuffer]
377+
function.getNewAggregationBuffer
379378

380379
override def eval(input: Row): Any = unwrap(function.evaluate(buffer), returnInspector)
381380

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveUdfSuite.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import java.util
2222
import java.util.Properties
2323

2424
import org.apache.hadoop.conf.Configuration
25-
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF
25+
import org.apache.hadoop.hive.ql.udf.generic.{GenericUDAFAverage, GenericUDF}
2626
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject
2727
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory
2828
import org.apache.hadoop.hive.serde2.objectinspector.{ObjectInspector, ObjectInspectorFactory}
@@ -93,6 +93,15 @@ class HiveUdfSuite extends QueryTest {
9393
sql("DROP TEMPORARY FUNCTION IF EXISTS testUdf")
9494
}
9595

96+
test("SPARK-6409 UDAFAverage test") {
97+
sql(s"CREATE TEMPORARY FUNCTION test_avg AS '${classOf[GenericUDAFAverage].getName}'")
98+
checkAnswer(
99+
sql("SELECT test_avg(1), test_avg(substr(value,5)) FROM src"),
100+
Seq(Row(1.0, 260.182)))
101+
sql("DROP TEMPORARY FUNCTION IF EXISTS test_avg")
102+
TestHive.reset()
103+
}
104+
96105
test("SPARK-2693 udaf aggregates test") {
97106
checkAnswer(sql("SELECT percentile(key, 1) FROM src LIMIT 1"),
98107
sql("SELECT max(key) FROM src").collect().toSeq)

0 commit comments

Comments
 (0)