srowen commented on code in PR #39747:
URL: https://github.com/apache/spark/pull/39747#discussion_r1091441853


##########
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/ExpressionImplUtils.java:
##########
@@ -35,6 +35,39 @@ public class ExpressionImplUtils {
   private static final int GCM_IV_LEN = 12;
   private static final int GCM_TAG_LEN = 128;
 
+  /**
+   * Function to check if a given number string is a valid Luhn number
+   * @param numberString
+   *  the number string to check
+   * @return
+   *  true if the number string is a valid Luhn number, false otherwise.
+   */
+  public static boolean isLuhnNumber(UTF8String numberString) {
+    String digits = numberString.toString();
+    // Check if all characters in the input string are digits.
+    java.util.function.Predicate<Character> isDigit = c -> 
Character.isDigit(c);
+    java.util.function.Predicate<Character> isNotWhitespace = c -> 
!Character.isWhitespace(c);
+    if (!digits.isEmpty() &&
+            digits.chars().allMatch(
+                    c -> Character.isDigit(c) && 
!Character.isWhitespace((char) c))) {

Review Comment:
   (It does not)
   
   BTW, I think using allMatch is going to be non-trivial overhead. You're 
already iterating over chars, just check in the loop below and short-circuit if 
something isn't a digit



-- 
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-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to