cloud-fan commented on code in PR #39747:
URL: https://github.com/apache/spark/pull/39747#discussion_r1090377071
##########
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/ExpressionImplUtils.java:
##########
@@ -35,6 +35,35 @@ 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.
+ if (!digits.trim().isEmpty() &&
digits.chars().allMatch(Character::isDigit)) {
+ int checkSum = 0;
+ boolean isSecond = false;
+ for (int i = digits.length() - 1; i >= 0; i--) {
+ int digit = Character.getNumericValue(digits.charAt(i));
Review Comment:
shall we handle space here? Or we should trim at the beginning: `String
digits = numberString.toString().trim();`
--
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]