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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala:
##########
@@ -3039,3 +3039,100 @@ case class SplitPart (
       partNum = newChildren.apply(2))
   }
 }
+
+/**
+ * Function to check if a given number string is a valid Luhn number. Returns 
true, if the number
+ * string is a valid Luhn number, false otherwise.
+ */
+@ExpressionDescription(
+  usage = """
+    _FUNC_(str ) - Checks that a string of digits is valid according to the 
Luhn algorithm.
+    This checksum function is widely applied on credit card numbers and 
government identification
+    numbers to distinguish valid numbers from mistyped, incorrect numbers.
+  """,
+  examples = """
+    Examples:
+      > SELECT _FUNC_('8112189876');
+       true
+      > SELECT _FUNC_('79927398713');
+       true
+      > SELECT _FUNC_('79927398714');
+       false
+  """,
+  since = "3.5.0",
+  group = "string_funcs")
+case class Luhncheck(child: Expression) extends UnaryExpression with 
ExpectsInputTypes {
+
+  override def nullable: Boolean = false
+
+  override protected def withNewChildInternal(newChild: Expression): Luhncheck 
=
+    copy(child = newChild)
+
+  override def inputTypes: Seq[AbstractDataType] = Seq(StringType)
+
+  override def dataType: DataType = BooleanType
+
+  /**
+   * Default behavior of evaluation according to the default nullability of 
UnaryExpression. If
+   * subclass of UnaryExpression override nullable, probably should also 
override this.
+   */
+  override def eval(input: InternalRow): Any = 
Luhncheck.isLuhnNumber(child.eval(input))

Review Comment:
   Thanks for the review comment. 
   I updated the code



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