You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/01/18 08:18:24 UTC

[GitHub] [spark] cloud-fan commented on a change in pull request #31198: [SPARK-33245][SQL] Add built-in UDF - GETBIT

cloud-fan commented on a change in pull request #31198:
URL: https://github.com/apache/spark/pull/31198#discussion_r559383381



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/bitwiseExpressions.scala
##########
@@ -204,3 +205,47 @@ case class BitwiseCount(child: Expression)
     case LongType => java.lang.Long.bitCount(input.asInstanceOf[Long])
   }
 }
+
+object BitwiseGetUtil {
+  def calculate(target: Long, pos: Int): Long = {
+    if (pos < 0) {
+      throw new IllegalArgumentException(s"Invalid bit position: $pos less than zero")
+    } else if (java.lang.Long.SIZE <= pos) {
+      throw new IllegalArgumentException(s"Invalid bit position: $pos exceeds the " +
+        "bit length of the target long")
+    }
+    (target >> pos) & 1
+  }
+}
+
+@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[IntegralType] = Seq(LongType, IntegerType)
+
+  override def dataType: DataType = LongType

Review comment:
       if it only returns 0 or 1, why we use long type? how about other databases?




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org