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/09/21 17:50:06 UTC

[GitHub] [spark] mkaravel commented on a change in pull request #34056: [SPARK-36811][SQL] Add SQL functions for the BINARY data type for AND, OR, XOR, and NOT

mkaravel commented on a change in pull request #34056:
URL: https://github.com/apache/spark/pull/34056#discussion_r713280761



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
##########
@@ -2649,3 +2649,192 @@ case class Sentences(
     copy(str = newFirst, language = newSecond, country = newThird)
 
 }
+
+/**
+ * A function that returns the bitwise AND of two binary strings.
+ * The byte length of the result is the maximum of the byte lengths of the two input binary
+ * strings. If the two input binary strings are of different byte length they aligned according
+ * to their least significant (right-most) bit.  The shorter binary string is semantically
+ * left-padded with zeros.
+ */
+@ExpressionDescription(
+  usage = """
+    _FUNC_(bytes1, bytes2) - Returns the bitwise AND of two binary strings.
+  """,
+  examples = """
+    Examples:
+      > SELECT hex(_FUNC_(unhex('AABB'), unhex('11223344')));
+       00002200
+  """,
+  since = "3.3.0",
+  group = "string_funcs")
+case class BitAnd(bytes1: Expression, bytes2: Expression)
+  extends BinaryExpression with ExpectsInputTypes with NullIntolerant {
+
+  override def inputTypes: Seq[AbstractDataType] = Seq(BinaryType, BinaryType)
+
+  override def dataType: DataType = BinaryType
+
+  override def left: Expression = bytes1
+  override def right: Expression = bytes2
+
+  override def nullSafeEval(left: Any, right: Any): Any = {
+    bytes1.dataType match {
+      case BinaryType => ByteArray.bitwiseAnd(left.asInstanceOf[Array[Byte]],

Review comment:
       Done.

##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
##########
@@ -2649,3 +2649,192 @@ case class Sentences(
     copy(str = newFirst, language = newSecond, country = newThird)
 
 }
+
+/**
+ * A function that returns the bitwise AND of two binary strings.

Review comment:
       Done. Referring to expressions now.




-- 
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: reviews-unsubscribe@spark.apache.org

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