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

    https://github.com/apache/spark/pull/6843#discussion_r33894942
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala
 ---
    @@ -298,3 +298,120 @@ case class StringLength(child: Expression) extends 
UnaryExpression with ExpectsI
     
       override def prettyName: String = "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 inputTypes: 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
    +      }
    +    }
    +  }
    +}
    +
    +/**
    + * 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 inputTypes: Seq[DataType] = Seq(BinaryType)
    +
    +  override def eval(input: InternalRow): Any = {
    +    val bytes = child.eval(input)
    +    if (bytes == null) {
    +      null
    +    } else {
    +      UTF8String.fromBytes(
    +        org.apache.commons.codec.binary.Base64.encodeBase64(
    +          bytes.asInstanceOf[Array[Byte]]))
    +    }
    +  }
    +}
    +
    +/**
    + * Converts the argument from a base 64 string to BINARY.
    + */
    +case class UnBase64(child: Expression) extends UnaryExpression with 
ExpectsInputTypes {
    +  override def dataType: DataType = BinaryType
    +  override def inputTypes: Seq[DataType] = Seq(StringType)
    +
    +  override def eval(input: InternalRow): Any = {
    +    val string = child.eval(input)
    +    if (string == null) {
    +      null
    +    } else {
    +      
org.apache.commons.codec.binary.Base64.decodeBase64(string.asInstanceOf[UTF8String].toString)
    +    }
    +  }
    +}
    +
    +/**
    + * Decodes the first argument into a String using the provided character 
set
    + * (one of 'US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 
'UTF-16').
    + * If either argument is null, the result will also be null. (As of Hive 
0.12.0.).
    + */
    +case class Decode(bin: Expression, charset: Expression) extends Expression 
with ExpectsInputTypes {
    --- End diff --
    
    Actually that's my intention, as I think the parameters is asymmetric 
semantically. Not sure if you are thinking the code impovement like #7157?


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