Github user chenghao-intel commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6843#discussion_r32839458
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala
 ---
    @@ -307,9 +307,176 @@ case class StringLength(child: Expression) extends 
UnaryExpression with ExpectsI
         if (string == null) null else string.asInstanceOf[UTF8String].length
       }
     
    -  override def toString: String = s"length($child)"
    +  override def toString: String = s"LENGTH($child)"
     
       override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): 
String = {
         defineCodeGen(ctx, ev, c => s"($c).length()")
       }
     }
    +
    +/**
    + * Returns the numeric value of the first character of str.
    + */
    +case class Ascii(child: Expression) extends UnaryExpression {
    +  override def dataType: DataType = IntegerType
    +  override def checkInputDataTypes(): TypeCheckResult = {
    +    if (child.dataType != StringType) {
    +      TypeCheckResult.TypeCheckFailure(
    +        s"type of child expression in ASCII should be string, not 
${child.dataType}")
    +    } else {
    +      TypeCheckResult.TypeCheckSuccess
    +    }
    +  }
    +
    +  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)"
    --- End diff --
    
    Probably the registered function name will make more sense, than giving the 
user a class name. What do you think?


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