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



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
##########
@@ -2734,3 +2734,236 @@ case class Sentences(
     copy(str = newFirst, language = newSecond, country = newThird)
 
 }
+
+/**
+ * Expression that returns the bitwise AND of two byte sequences.
+ * - If the byte lengths of the two input byte sequences are the same, the 
byte length of the
+ *   result if the same as the common byte length of the two inputs.
+ * - If the byte lengths of the two input byte sequences differ, a third 
argument is required
+ *   to determine whether the shorter input byte sequence should be 
semantically padded from the
+ *   left or the right with zero bytes. The valid values for the third 
argument are 'lpad' and
+ *   'rpad' (case insensitive). If 'lpad' is specified, the shorter byte 
sequence is semantically
+ *   left-padded with zeros to match the length of the longer byte sequence. 
If 'rpad' is
+ *   specified, the shorter byte sequence is semantically right-padded with 
zeros to match the
+ *   length of the longer byte sequence. The byte length of the result is the 
maximum of the
+ *   byte lengths of the two input byte sequences.
+ * Specifying the third argument in the case of equal-length byte sequences 
has no effect.
+ */
+@ExpressionDescription(
+  usage = """
+    _FUNC_(bytes1, bytes2[, padding]) - Returns the bitwise AND of two binary 
strings.
+  """,
+  examples = """
+    Examples:
+      > SELECT hex(_FUNC_(unhex('AABB'), unhex('7735')));
+       2231
+      > SELECT hex(_FUNC_(unhex('AABB'), unhex('66773355'), 'lpad'));
+       00002211
+      > SELECT hex(_FUNC_(unhex('AABB'), unhex('66773355'), 'rpad'));
+       22330000
+  """,
+  since = "3.3.0",
+  group = "string_funcs")
+case class BitAnd(bytes1: Expression, bytes2: Expression, padding: Expression, 
numArgs: Int)

Review comment:
       I think it makes more sense to only allow the padding parameter to be a 
string constant, so that we can fail earlier (before execution) if the given 
value is not `lpad` or `rad`.
   
   ```
   private lazy val isLPad = padding.eval().toString.equalsIgnoreCase("lpad")
   private lazy val isRPad = ...
   override def checkInputTypes... = {
     ...
     if (!padding.foldable) TypeCheckResult.Fail... else {
       val value = padding.eval()
       if (value == null) TypeCheckResult.Fail... else {
         if (isLPad || isRPad) TypeCheckResult.Success
         else TypeCheckResult.Fail... 
       }
     }
   }
   ```




-- 
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]

Reply via email to