Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6970#discussion_r33119563
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala
 ---
    @@ -47,4 +48,69 @@ case class Md5(child: Expression)
           "org.apache.spark.unsafe.types.UTF8String.fromString" +
             s"(org.apache.commons.codec.digest.DigestUtils.md5Hex($c))")
       }
    +
    +}
    +
    +/**
    + * A function that calculates an SHA-1 digest and returns it as a hex 
string
    + * For input of type [[BinaryType]]
    + */
    +case class Sha(child: Expression)
    +  extends UnaryExpression with ExpectsInputTypes {
    +
    +  override def dataType: DataType = StringType
    +
    +  override def expectedChildTypes: Seq[DataType] = Seq(BinaryType, 
StringType)
    --- End diff --
    
    @tarekauel Sorry, I was wrong, didn't figure out the difference between 
`checkInputDataTypes` and `expectedChildTypes`  of `ExpectsInputTypes`.
    
    In order to get better error message, we should use `checkInputDataTypes`.
    
    `expectedChildTypes` is used to widen the types we support.
    
    For this case, we could use `Seq(BinaryType)` as `expectedChildTypes`, 
which means it will also support `StringType`, because `StringType` could be 
casted to BinaryType (which is cheap).
    
    In `eval` and `genCode`, you can expect that child.dataType is BinaryType.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to