spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davies <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-8227][SQL][WIP]Add function unhex
Date Wed, 01 Jul 2015 06:50:00 GMT
Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7113#discussion_r33652508
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala
---
    @@ -354,6 +356,35 @@ case class Pow(left: Expression, right: Expression)
       }
     }
     
    +/**
    + * Performs the inverse operation of HEX.
    + * Resulting characters are returned as a byte array.
    + */
    +case class UnHex(child: Expression)
    +  extends UnaryExpression with AutoCastInputTypes with Serializable  {
    +
    +  override def expectedChildTypes: Seq[DataType] = Seq(StringType)
    +
    +  override def dataType: DataType = BinaryType
    +
    +  override def eval(input: InternalRow): Any = {
    +    val num = child.eval(input)
    +    if (num == null) {
    +      null
    +    } else {
    +      unhex(num.asInstanceOf[UTF8String])
    +    }
    +  }
    +
    +  private def unhex(utf8Str: UTF8String): Array[Byte] = {
    +    try {
    +      new org.apache.commons.codec.binary.Hex(StandardCharsets.UTF_8).decode(utf8Str.getBytes)
    --- End diff --
    
    `toDigit()` could be implemented by lookup table 
    ```
    val arr = Array[Byte](0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11,
12, 13, 14, 15, -1, ....., 0, 1, 2, 3, 4, 5)
    def toDigit(b: Byte): Byte = {
       if (b >= 48 && b <= (102 - 48)) arr(b) else -1
    }
    ```


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


Mime
View raw message