cloud-fan commented on code in PR #36066:
URL: https://github.com/apache/spark/pull/36066#discussion_r845082041


##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/StringExpressionsSuite.scala:
##########
@@ -892,169 +892,152 @@ class StringExpressionsSuite extends SparkFunSuite with 
ExpressionEvalHelper {
       Literal.create(null, IntegerType), Literal.create(null, IntegerType)), 
null)
   }
 
-  test("ToNumber") {
-    ToNumber(Literal("454"), Literal("")).checkInputDataTypes() match {
-      case TypeCheckResult.TypeCheckFailure(msg) =>
-        assert(msg.contains("Number format cannot be empty"))
-    }
-    ToNumber(Literal("454"), NonFoldableLiteral.create("999", StringType))
-      .checkInputDataTypes() match {
-      case TypeCheckResult.TypeCheckFailure(msg) =>
-        assert(msg.contains("Format expression must be foldable"))
-    }
-
-    // Test '0' and '9'
-
-    Seq("454", "054", "54", "450").foreach { input =>
-      val invalidFormat1 = 0.until(input.length - 1).map(_ => '0').mkString
-      val invalidFormat2 = 0.until(input.length - 2).map(_ => '0').mkString
-      val invalidFormat3 = 0.until(input.length - 1).map(_ => '9').mkString
-      val invalidFormat4 = 0.until(input.length - 2).map(_ => '9').mkString
-      Seq(invalidFormat1, invalidFormat2, invalidFormat3, invalidFormat4)
-        .filter(_.nonEmpty).foreach { format =>
-        checkExceptionInExpression[IllegalArgumentException](
-          ToNumber(Literal(input), Literal(format)),
-          s"The input string '$input' does not match the given number format: 
'$format'")
-      }
-
-      val format1 = 0.until(input.length).map(_ => '0').mkString
-      val format2 = 0.until(input.length).map(_ => '9').mkString
-      val format3 = 0.until(input.length).map(i => i % 2 * 9).mkString
-      val format4 = 0.until(input.length + 1).map(_ => '0').mkString
-      val format5 = 0.until(input.length + 1).map(_ => '9').mkString
-      val format6 = 0.until(input.length + 1).map(i => i % 2 * 9).mkString
-      Seq(format1, format2, format3, format4, format5, format6).foreach { 
format =>
-        checkEvaluation(ToNumber(Literal(input), Literal(format)), 
Decimal(input))
-      }
-    }
-
-    // Test '.' and 'D'
-    checkExceptionInExpression[IllegalArgumentException](
-      ToNumber(Literal("454.2"), Literal("999")),
-      "The input string '454.2' does not match the given number format: '999'")
-    Seq("999.9", "000.0", "99.99", "00.00", "0000.0", "9999.9", "00.000", 
"99.999")
-      .foreach { format =>
-        checkExceptionInExpression[IllegalArgumentException](
-          ToNumber(Literal("454.23"), Literal(format)),
-          s"The input string '454.23' does not match the given number format: 
'$format'")
-        val format2 = format.replace('.', 'D')
-        checkExceptionInExpression[IllegalArgumentException](
-          ToNumber(Literal("454.23"), Literal(format2)),
-          s"The input string '454.23' does not match the given number format: 
'$format2'")
-    }
-
+  test("ToNumber: positive tests") {
     Seq(
-      ("454.2", "000.0") -> Decimal(454.2),
-      ("454.23", "000.00") -> Decimal(454.23),
-      ("454.2", "000.00") -> Decimal(454.2),
-      ("454.0", "000.0") -> Decimal(454),
-      ("454.00", "000.00") -> Decimal(454),
-      (".4542", ".0000") -> Decimal(0.4542),
-      ("4542.", "0000.") -> Decimal(4542)
-    ).foreach { case ((str, format), expected) =>
-      checkEvaluation(ToNumber(Literal(str), Literal(format)), expected)
-      val format2 = format.replace('.', 'D')
-      checkEvaluation(ToNumber(Literal(str), Literal(format2)), expected)
-      val format3 = format.replace('0', '9')
-      checkEvaluation(ToNumber(Literal(str), Literal(format3)), expected)
-      val format4 = format3.replace('.', 'D')
-      checkEvaluation(ToNumber(Literal(str), Literal(format4)), expected)
+      ("-$12,345.67", "S$999,099.99") -> Decimal(-12345.67),
+      ("454,123", "999,099") -> Decimal(454123),
+      ("$345", "S$999,099.99") -> Decimal(345),
+      ("$045", "S$999,099.99") -> Decimal(45),
+      ("454", "099") -> Decimal(454),
+      ("454.", "099.99") -> Decimal(454.0),
+      ("454.6", "099.99") -> Decimal(454.6),
+      ("454.67", "099.00") -> Decimal(454.67),
+      ("454", "000") -> Decimal(454),
+      ("  454 ", "9099") -> Decimal(454),
+      ("454", "099") -> Decimal(454),
+      ("454.67", "099.99") -> Decimal(454.67),
+      ("$454", "$999") -> Decimal(454),
+      ("  454,123 ", "999G099") -> Decimal(454123),
+      ("$454,123", "$999,099") -> Decimal(454123),
+      ("+$89,1,2,3,45.123", "S$999,0,0,0,999.00000") -> Decimal(8912345.123),

Review Comment:
   how about empty group? e.g. `123,,,456`



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