@@ -19,14 +19,15 @@ package org.apache.spark.sql.hive.execution
1919
2020import scala .collection .JavaConverters ._
2121
22+ import org .apache .hadoop .hive .ql .udf .UDAFPercentile
2223import org .apache .hadoop .hive .ql .udf .generic .{AbstractGenericUDAFResolver , GenericUDAFEvaluator , GenericUDAFMax }
2324import org .apache .hadoop .hive .ql .udf .generic .GenericUDAFEvaluator .{AggregationBuffer , Mode }
2425import org .apache .hadoop .hive .ql .util .JavaDataModel
2526import org .apache .hadoop .hive .serde2 .objectinspector .{ObjectInspector , ObjectInspectorFactory }
2627import org .apache .hadoop .hive .serde2 .objectinspector .primitive .PrimitiveObjectInspectorFactory
2728import org .apache .hadoop .hive .serde2 .typeinfo .TypeInfo
2829
29- import org .apache .spark .sql .{QueryTest , Row }
30+ import org .apache .spark .sql .{AnalysisException , QueryTest , Row }
3031import org .apache .spark .sql .execution .aggregate .ObjectHashAggregateExec
3132import org .apache .spark .sql .hive .test .TestHiveSingleton
3233import org .apache .spark .sql .test .SQLTestUtils
@@ -84,6 +85,21 @@ class HiveUDAFSuite extends QueryTest with TestHiveSingleton with SQLTestUtils {
8485 Row (1 , Row (1 , 1 ))
8586 ))
8687 }
88+
89+ test(" non-deterministic children expressions of UDAF" ) {
90+ withTempView(" view1" ) {
91+ spark.range(1 ).selectExpr(" id as x" , " id as y" ).createTempView(" view1" )
92+ withUserDefinedFunction(" testUDAFPercentile" -> true , " testMock" -> true ) {
93+ // non-deterministic children of Hive UDAF
94+ sql(s " CREATE TEMPORARY FUNCTION testUDAFPercentile AS ' ${classOf [UDAFPercentile ].getName}' " )
95+ val e1 = intercept[AnalysisException ] {
96+ sql(" SELECT testUDAFPercentile(x, rand()) from view1 group by y" )
97+ }.getMessage
98+ assert(Seq (" nondeterministic expression" ,
99+ " should not appear in the arguments of an aggregate function" ).forall(e1.contains))
100+ }
101+ }
102+ }
87103}
88104
89105/**
0 commit comments