beliefer commented on code in PR #46952:
URL: https://github.com/apache/spark/pull/46952#discussion_r1635945815
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala:
##########
@@ -1036,24 +1036,26 @@ object Hex {
val value = new Array[Byte](length * 2)
var i = 0
while (i < length) {
- value(i * 2) = Hex.hexDigits((bytes(i) & 0xF0) >> 4)
- value(i * 2 + 1) = Hex.hexDigits(bytes(i) & 0x0F)
+ value(i * 2) = hexDigits((bytes(i) & 0xF0) >> 4)
+ value(i * 2 + 1) = hexDigits(bytes(i) & 0x0F)
i += 1
}
UTF8String.fromBytes(value)
}
def hex(num: Long): UTF8String = {
- // Extract the hex digits of num into value[] from right to left
- val value = new Array[Byte](16)
+ val zeros = jl.Long.numberOfLeadingZeros(num)
+ if (zeros == jl.Long.SIZE) return ZERO_UTF8
+ val len = (jl.Long.SIZE - zeros + 3) / 4
Review Comment:
Could you add comments to explain the arithmetic expression ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]