beliefer commented on a change in pull request #31170:
URL: https://github.com/apache/spark/pull/31170#discussion_r557206616
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/bitwiseExpressions.scala
##########
@@ -204,3 +206,51 @@ case class BitwiseCount(child: Expression)
case LongType => java.lang.Long.bitCount(input.asInstanceOf[Long])
}
}
+
+object BitwiseGet {
+ def calculate(target: Int, pos: Int): Int = {
+ val source = target.toBinaryString
+ if (pos < 0) {
+ throw new IllegalArgumentException(s"Invalid bit position: $pos less
than zero")
+ } else if (source.length <= pos) {
+ throw new IllegalArgumentException(s"Invalid bit position: $pos exceeds
the " +
+ "bit length of the target integer")
+ }
+ val subString =
UTF8String.fromString(source).substringSQL(pos.asInstanceOf[Int], 1)
+ val intWrapper = new UTF8String.IntWrapper()
+ subString.toInt(intWrapper)
+ intWrapper.value
+ }
+}
+
+@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 {
+
+ override def inputTypes: Seq[IntegerType] = Seq(IntegerType, IntegerType)
Review comment:
snowflake and impala uses integer type. teradata and yellowbrick uses
long type.
----------------------------------------------------------------
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]