Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, SubqueryAlias}
import org.apache.spark.sql.catalyst.rules.Rule
import org.apache.spark.sql.hive.HiveShim.HiveFunctionWrapper
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.{DecimalType, DoubleType}
import org.apache.spark.sql.types.{ArrayType, DecimalType, DoubleType}
import org.apache.spark.util.Utils


Expand Down Expand Up @@ -166,8 +166,13 @@ private[sql] class HiveSessionCatalog(
} catch {
case NonFatal(_) =>
// SPARK-16228 ExternalCatalog may recognize `double`-type only.
// SPARK-18527 Percentile needs explicit cast to array<double>
val newChildren = children.map { child =>
if (child.dataType.isInstanceOf[DecimalType]) Cast(child, DoubleType) else child
child.dataType match {
case ArrayType(DecimalType(), nullable) => Cast(child, ArrayType(DoubleType, nullable))
case DecimalType() => Cast(child, DoubleType)
case _ => child
}
}
lookupFunction0(name, newChildren)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ class HiveUDFSuite extends QueryTest with TestHiveSingleton with SQLTestUtils {
sql("select percentile_approx(value, 0.5) from values 1.0,2.0,3.0 T(value)")
}

test("SPARK-18527 Percentile needs explicit cast to array<double>") {
sql("select percentile(value, cast(array(0.1, 0.5) as array<double>))" +
"from values 1,2,3 T(value)")
sql("select percentile(value, array(0.1, 0.5)) from values 1,2,3 T(value)")
}

test("Generic UDAF aggregates") {

checkAnswer(sql(
Expand Down