Skip to content

Commit

Permalink
Make 'value' as a feild of Hex
Browse files Browse the repository at this point in the history
  • Loading branch information
zhichao-li committed Jun 29, 2015
1 parent 3b2fa13 commit 967ec90
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ case class Pow(left: Expression, right: Expression)
case class Hex(child: Expression)
extends UnaryExpression with Serializable {

private var value = new Array[Byte](16)

override def dataType: DataType = StringType

override def checkInputDataTypes(): TypeCheckResult = {
Expand Down Expand Up @@ -335,7 +337,9 @@ case class Hex(child: Expression)
}

private def doHex(bytes: Array[Byte], length: Int): UTF8String = {
val value = new Array[Byte](length * 2)
if (value.length < length * 2) {
value = new Array[Byte](length * 2)
}
var i = 0
while(i < length) {
value(i * 2) = Character.toUpperCase(Character.forDigit(
Expand All @@ -344,12 +348,11 @@ case class Hex(child: Expression)
bytes(i) & 0x0F, 16)).toByte
i += 1
}
UTF8String.fromBytes(value)
UTF8String.fromBytes(Arrays.copyOfRange(value, 0, length*2))
}

private def hex(num: Long): UTF8String = {
// Extract the hex digits of num into value[] from right to left
val value = new Array[Byte](16)
var numBuf = num
var len = 0
do {
Expand Down

0 comments on commit 967ec90

Please sign in to comment.