Github user ueshin commented on a diff in the pull request:
https://github.com/apache/spark/pull/22408#discussion_r217269231
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
---
@@ -1331,26 +1331,31 @@ case class ArrayContains(left: Expression, right:
Expression)
@transient private lazy val ordering: Ordering[Any] =
TypeUtils.getInterpretedOrdering(right.dataType)
- override def inputTypes: Seq[AbstractDataType] = right.dataType match {
- case NullType => Seq.empty
- case _ => left.dataType match {
- case n @ ArrayType(element, _) => Seq(n, element)
+ override def inputTypes: Seq[AbstractDataType] = {
+ (left.dataType, right.dataType) match {
+ case (_, NullType) => Seq.empty
+ case (ArrayType(e1, hasNull), e2) =>
+ TypeCoercion.findTightestCommonType(e1, e2) match {
+ case Some(dt) => Seq(ArrayType(dt, hasNull), dt)
+ case _ => Seq.empty
+ }
case _ => Seq.empty
}
}
override def checkInputDataTypes(): TypeCheckResult = {
- if (right.dataType == NullType) {
- TypeCheckResult.TypeCheckFailure("Null typed values cannot be used
as arguments")
- } else if (!left.dataType.isInstanceOf[ArrayType]
- ||
!left.dataType.asInstanceOf[ArrayType].elementType.sameType(right.dataType)) {
- TypeCheckResult.TypeCheckFailure(
- "Arguments must be an array followed by a value of same type as
the array members")
- } else {
- TypeUtils.checkForOrderingExpr(right.dataType, s"function
$prettyName")
+ (left.dataType, right.dataType) match {
+ case (_, NullType) =>
+ TypeCheckResult.TypeCheckFailure("Null typed values cannot be used
as arguments")
+ case (ArrayType(e1, _), e2) if e1.sameType(e2) =>
+ TypeUtils.checkForOrderingExpr(right.dataType, s"function
$prettyName")
+ case _ => TypeCheckResult.TypeCheckFailure(s"Input to function
$prettyName should have " +
+ s"been ${ArrayType.simpleString} followed by a value with same
element type, but it's " +
+ s"[${left.dataType.catalogString},
${right.dataType.catalogString}].")
}
}
+
--- End diff --
nit: can you revert this change?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]