maropu commented on a change in pull request #25172: [SPARK-28412][SQL] ANSI 
SQL: OVERLAY function support byte array
URL: https://github.com/apache/spark/pull/25172#discussion_r317593758
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
 ##########
 @@ -496,19 +511,38 @@ case class Overlay(input: Expression, replace: 
Expression, pos: Expression, len:
     this(str, replace, pos, Literal.create(-1, IntegerType))
   }
 
-  override def dataType: DataType = StringType
+  override def dataType: DataType = input.dataType
 
-  override def inputTypes: Seq[AbstractDataType] =
-    Seq(StringType, StringType, IntegerType, IntegerType)
+  override def inputTypes: Seq[AbstractDataType] = 
Seq(TypeCollection(StringType, BinaryType),
+    TypeCollection(StringType, BinaryType), IntegerType, IntegerType)
 
   override def children: Seq[Expression] = input :: replace :: pos :: len :: 
Nil
 
+  override def checkInputDataTypes(): TypeCheckResult = {
+    val (inputType, replaceType, posType, lenType) =
+      (input.dataType, replace.dataType, pos.dataType, len.dataType)
+    (inputType, replaceType) match {
+      case (StringType, StringType) | (BinaryType, BinaryType) =>
 
 Review comment:
   I forgot add the default type check;
   ```
   
     override def checkInputDataTypes(): TypeCheckResult = {
       val inputTypeCheck = super.checkInputDataTypes()
       if (inputTypeCheck.isSuccess) {
         TypeUtils.checkForSameTypeInputExpr(
           input.dataType :: replace.dataType :: Nil, s"function $prettyName")
       } else {
         inputTypeCheck
       }
     }
   ```
   I think overlay(int, int) and overlay(long, long) are valid queries for 
overlay because their types can be implictly casted to strings.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to