Skip to content

Commit 53184ce

Browse files
dilipbiswalyhuai
authored andcommitted
[SPARK-12558][FOLLOW-UP] AnalysisException when multiple functions applied in GROUP BY clause
Addresses the comments from Yin. #10520 Author: Dilip Biswal <[email protected]> Closes #10758 from dilipbiswal/spark-12558-followup. (cherry picked from commit db9a860) Signed-off-by: Yin Huai <[email protected]> Conflicts: sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveUDFSuite.scala
1 parent 5803fce commit 53184ce

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import java.util.{ArrayList, Arrays, Properties}
2222

2323
import org.apache.hadoop.conf.Configuration
2424
import org.apache.hadoop.hive.ql.udf.UDAFPercentile
25-
import org.apache.hadoop.hive.ql.udf.generic.{GenericUDFOPAnd, GenericUDTFExplode, GenericUDAFAverage, GenericUDF}
25+
import org.apache.hadoop.hive.ql.udf.generic._
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}
@@ -351,10 +351,14 @@ class HiveUDFSuite extends QueryTest with TestHiveSingleton with SQLTestUtils {
351351
}
352352

353353
test("Hive UDF in group by") {
354-
Seq(Tuple1(1451400761)).toDF("test_date").registerTempTable("tab1")
355-
val count = sql("select date(cast(test_date as timestamp))" +
356-
" from tab1 group by date(cast(test_date as timestamp))").count()
357-
assert(count == 1)
354+
withTempTable("tab1") {
355+
Seq(Tuple1(1451400761)).toDF("test_date").registerTempTable("tab1")
356+
sql(s"CREATE TEMPORARY FUNCTION testUDFToDate AS '${classOf[GenericUDFToDate].getName}'")
357+
val count = sql("select testUDFToDate(cast(test_date as timestamp))" +
358+
" from tab1 group by testUDFToDate(cast(test_date as timestamp))").count()
359+
sql("DROP TEMPORARY FUNCTION IF EXISTS testUDFToDate")
360+
assert(count == 1)
361+
}
358362
}
359363

360364
test("SPARK-11522 select input_file_name from non-parquet table"){

0 commit comments

Comments
 (0)