Skip to content

Commit cf9c936

Browse files
committed
give separated buffer for each hex method
1 parent 967ec90 commit cf9c936

File tree

1 file changed

+3
-6
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions

1 file changed

+3
-6
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,6 @@ case class Pow(left: Expression, right: Expression)
295295
case class Hex(child: Expression)
296296
extends UnaryExpression with Serializable {
297297

298-
private var value = new Array[Byte](16)
299-
300298
override def dataType: DataType = StringType
301299

302300
override def checkInputDataTypes(): TypeCheckResult = {
@@ -337,9 +335,7 @@ case class Hex(child: Expression)
337335
}
338336

339337
private def doHex(bytes: Array[Byte], length: Int): UTF8String = {
340-
if (value.length < length * 2) {
341-
value = new Array[Byte](length * 2)
342-
}
338+
val value = new Array[Byte](length * 2)
343339
var i = 0
344340
while(i < length) {
345341
value(i * 2) = Character.toUpperCase(Character.forDigit(
@@ -348,11 +344,12 @@ case class Hex(child: Expression)
348344
bytes(i) & 0x0F, 16)).toByte
349345
i += 1
350346
}
351-
UTF8String.fromBytes(Arrays.copyOfRange(value, 0, length*2))
347+
UTF8String.fromBytes(value)
352348
}
353349

354350
private def hex(num: Long): UTF8String = {
355351
// Extract the hex digits of num into value[] from right to left
352+
val value = new Array[Byte](16)
356353
var numBuf = num
357354
var len = 0
358355
do {

0 commit comments

Comments
 (0)