You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "mihailom-db (via GitHub)" <gi...@apache.org> on 2024/04/02 19:46:46 UTC

Re: [PR] [SPARK-47541][SQL] Collated strings in complex types supporting operations reverse, array_join, concat, map [spark]

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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala:
##########
@@ -1994,17 +1995,23 @@ 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 {
 
   def this(array: Expression, delimiter: Expression) = this(array, delimiter, None)
 
   def this(array: Expression, delimiter: Expression, nullReplacement: Expression) =
     this(array, delimiter, Some(nullReplacement))
 
-  override def inputTypes: Seq[AbstractDataType] = if (nullReplacement.isDefined) {
-    Seq(ArrayType(StringType), StringType, StringType)
-  } else {
-    Seq(ArrayType(StringType), StringType)
+  override def inputTypes: Seq[AbstractDataType] = {
+    val arrayType = array.dataType.asInstanceOf[ArrayType].elementType match {
+      case _: StringType => array.dataType
+      case _ => ArrayType(StringType)
+    }
+    if (nullReplacement.isDefined) {
+      Seq(arrayType, StringTypeAnyCollation, StringTypeAnyCollation)
+    } else {
+      Seq(arrayType, StringTypeAnyCollation)
+    }

Review Comment:
   ArrayJoin should be fine with only ArrayType. This is because TypeCoercion rules in FunctionArgumentConversion cast this argument to ArrayType(StringType) and catalyst rules will loop over this and cast it to proper collation if necessary. 



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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