mihailom-db commented on code in PR #45693:
URL: https://github.com/apache/spark/pull/45693#discussion_r1537297293


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala:
##########
@@ -1994,17 +1995,26 @@ case class Slice(x: Expression, start: Expression, 
length: Expression)
 case class ArrayJoin(
     array: Expression,
     delimiter: Expression,
-    nullReplacement: Option[Expression]) extends Expression with 
ExpectsInputTypes {
+    nullReplacement: Option[Expression]) extends ImplicitCastInputTypes with 
ExpectsInputTypes {
 
   def this(array: Expression, delimiter: Expression) = this(array, delimiter, 
None)
 
   def this(array: Expression, delimiter: Expression, nullReplacement: 
Expression) =
     this(array, delimiter, Some(nullReplacement))
 
+  private val commonType: DataType = {
+    val elementType = array.dataType.asInstanceOf[ArrayType].elementType
+    val s = nullReplacement match {
+      case Some(replacement) => Seq(elementType, delimiter.dataType, 
replacement.dataType)
+      case _ => Seq(elementType, delimiter.dataType)
+    }
+    TypeCoercion.findWiderCommonType(s).getOrElse(StringType)
+  }
+
   override def inputTypes: Seq[AbstractDataType] = if 
(nullReplacement.isDefined) {
-    Seq(ArrayType(StringType), StringType, StringType)
+    Seq(ArrayType(commonType), commonType, commonType)
   } else {
-    Seq(ArrayType(StringType), StringType)
+    Seq(ArrayType(commonType), commonType)
   }

Review Comment:
   One more thing is. This what you do with findWiderCommonType is not correct. 
If delimiter has explicit collation, we would like to have that collation. In 
your case you would collect two different collations, where 
arrayType.elementType would go first and findWiderCommonType practically does 
not do anything with delimiter's type, but would keep the first element type.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to