Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15703#discussion_r88141492
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveUDAFSuite.scala 
---
    @@ -0,0 +1,152 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive.execution
    +
    +import scala.collection.JavaConverters._
    +
    +import org.apache.hadoop.hive.ql.udf.generic.{AbstractGenericUDAFResolver, 
GenericUDAFEvaluator, GenericUDAFMax}
    +import 
org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator.{AggregationBuffer, 
Mode}
    +import org.apache.hadoop.hive.ql.util.JavaDataModel
    +import org.apache.hadoop.hive.serde2.objectinspector.{ObjectInspector, 
ObjectInspectorFactory}
    +import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory
    +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo
    +
    +import org.apache.spark.sql.{QueryTest, Row}
    +import org.apache.spark.sql.execution.aggregate.ObjectHashAggregateExec
    +import org.apache.spark.sql.hive.test.TestHiveSingleton
    +import org.apache.spark.sql.test.SQLTestUtils
    +
    +class HiveUDAFSuite extends QueryTest with TestHiveSingleton with 
SQLTestUtils {
    +  import testImplicits._
    +
    +  protected override def beforeAll(): Unit = {
    +    sql(s"CREATE TEMPORARY FUNCTION mock AS 
'${classOf[MockUDAF].getName}'")
    +    sql(s"CREATE TEMPORARY FUNCTION hive_max AS 
'${classOf[GenericUDAFMax].getName}'")
    +
    +    Seq(
    +      (0: Integer) -> "val_0",
    +      (1: Integer) -> "val_1",
    +      (2: Integer) -> null,
    +      (3: Integer) -> null
    +    ).toDF("key", "value").repartition(2).createOrReplaceTempView("t")
    +  }
    +
    +  protected override def afterAll(): Unit = {
    +    sql(s"DROP TEMPORARY FUNCTION IF EXISTS mock")
    +    sql(s"DROP TEMPORARY FUNCTION IF EXISTS hive_max")
    +  }
    +
    +  test("built-in Hive UDAF") {
    +    val df = sql("SELECT hive_max(key) FROM t GROUP BY key % 2")
    +
    +    val aggs = df.queryExecution.executedPlan.collect {
    +      case agg: ObjectHashAggregateExec => agg
    +    }
    +
    +    // There should be two aggregate operators, one for partial 
aggregation, and the other for
    +    // global aggregation.
    +    assert(aggs.length == 2)
    +
    +    checkAnswer(df, Seq(
    +      Row(2),
    +      Row(3)
    +    ))
    +  }
    +
    +  test("customized Hive UDAF") {
    +    val df = sql("SELECT mock(value) FROM t GROUP BY key % 2")
    --- End diff --
    
    How about we also keep the key?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to