File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -295,6 +295,8 @@ case class Pow(left: Expression, right: Expression)
295295case class Hex (child : Expression )
296296 extends UnaryExpression with Serializable {
297297
298+ private var value = new Array [Byte ](16 )
299+
298300 override def dataType : DataType = StringType
299301
300302 override def checkInputDataTypes (): TypeCheckResult = {
@@ -335,7 +337,9 @@ case class Hex(child: Expression)
335337 }
336338
337339 private def doHex (bytes : Array [Byte ], length : Int ): UTF8String = {
338- val value = new Array [Byte ](length * 2 )
340+ if (value.length < length * 2 ) {
341+ value = new Array [Byte ](length * 2 )
342+ }
339343 var i = 0
340344 while (i < length) {
341345 value(i * 2 ) = Character .toUpperCase(Character .forDigit(
@@ -344,12 +348,11 @@ case class Hex(child: Expression)
344348 bytes(i) & 0x0F , 16 )).toByte
345349 i += 1
346350 }
347- UTF8String .fromBytes(value)
351+ UTF8String .fromBytes(Arrays .copyOfRange( value, 0 , length * 2 ) )
348352 }
349353
350354 private def hex (num : Long ): UTF8String = {
351355 // Extract the hex digits of num into value[] from right to left
352- val value = new Array [Byte ](16 )
353356 var numBuf = num
354357 var len = 0
355358 do {
You can’t perform that action at this time.
0 commit comments