tanelk commented on a change in pull request #31198:
URL: https://github.com/apache/spark/pull/31198#discussion_r559717112
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/bitwiseExpressions.scala
##########
@@ -204,3 +205,60 @@ case class BitwiseCount(child: Expression)
case LongType => java.lang.Long.bitCount(input.asInstanceOf[Long])
}
}
+
+object BitwiseGetUtil {
+ def calculate(target: Any, pos: Int, size: Int): Byte = {
+ if (pos < 0) {
+ throw new IllegalArgumentException(s"Invalid bit position: $pos less
than zero")
+ } else if (size <= pos) {
+ throw new IllegalArgumentException(s"Invalid bit position: $pos exceeds
the bit upper limit")
+ }
+ val longValue = size match {
+ case java.lang.Byte.SIZE => target.asInstanceOf[Byte]
+ case java.lang.Short.SIZE => target.asInstanceOf[Short]
+ case java.lang.Integer.SIZE => target.asInstanceOf[Int]
+ case java.lang.Long.SIZE => target.asInstanceOf[Long]
+ }
+ ((longValue >> pos) & 1).byteValue
+ }
+}
+
+@ExpressionDescription(
+ usage = "_FUNC_(expr, pos) - Returns the value of the bit (0 or 1) at the
specified position.",
+ examples = """
+ Examples:
+ > SELECT _FUNC_(11, 0);
+ 1
+ > SELECT _FUNC_(11, 2);
+ 0
+ """,
+ since = "3.2.0",
+ group = "bitwise_funcs")
+case class BitwiseGet(left: Expression, right: Expression)
+ extends BinaryExpression with ImplicitCastInputTypes with NullIntolerant {
Review comment:
Shouldn't this be `ExpectsInputTypes` instead of
`ImplicitCastInputTypes`?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]