Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6843#discussion_r32714235
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala
 ---
    @@ -313,3 +313,131 @@ case class StringLength(child: Expression) extends 
UnaryExpression with ExpectsI
         defineCodeGen(ctx, ev, c => s"($c).length()")
       }
     }
    +
    +/**
    + * Returns the numeric value of the first character of str.
    + */
    +case class Ascii(child: Expression) extends UnaryExpression with 
ExpectsInputTypes {
    +  override def dataType: DataType = IntegerType
    +  override def expectedChildTypes: Seq[DataType] = Seq(StringType)
    +
    +  override def eval(input: InternalRow): Any = {
    +    val string = child.eval(input)
    +    if (string == null) {
    +      null
    +    } else {
    +      val bytes = string.asInstanceOf[UTF8String].getBytes
    +      if (bytes.length > 0) {
    +        bytes(0).asInstanceOf[Int]
    +      } else {
    +        0
    +      }
    +    }
    +  }
    +
    +  override def toString: String = s"ascii($child)"
    +}
    +
    +/**
    + * Converts the argument from binary to a base 64 string.
    + */
    +case class Base64(child: Expression) extends UnaryExpression with 
ExpectsInputTypes {
    +  override def dataType: DataType = StringType
    +  override def expectedChildTypes: Seq[DataType] = Seq(BinaryType)
    --- End diff --
    
    we should override `checkInputTypes` here, as `expectsInputType` won't 
report type check error...


---
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