beliefer commented on a change in pull request #27507:
URL: https://github.com/apache/spark/pull/27507#discussion_r463962090



##########
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/RegexpExpressionsSuite.scala
##########
@@ -322,6 +322,48 @@ class RegexpExpressionsSuite extends SparkFunSuite with 
ExpressionEvalHelper {
       RegExpExtract(Literal("\"quote"), Literal("\"quote"), Literal(1)) :: Nil)
   }
 
+  test("RegexExtractAll") {
+    val row1 = create_row("100-200,300-400,500-600", "(\\d+)-(\\d+)", 1)
+    val row2 = create_row("100-200,300-400,500-600", "(\\d+)-(\\d+)", 2)
+    val row3 = create_row("100-200,300-400,500-600", "(\\d+).*", 1)
+    val row4 = create_row("100-200,300-400,500-600", "([a-z])", 1)
+    val row5 = create_row(null, "([a-z])", 1)
+    val row6 = create_row("100-200,300-400,500-600", null, 1)
+    val row7 = create_row("100-200,300-400,500-600", "([a-z])", null)
+
+    val s = 's.string.at(0)
+    val p = 'p.string.at(1)
+    val r = 'r.int.at(2)
+
+    val expr = RegExpExtractAll(s, p, r)
+    checkEvaluation(expr, Seq("100", "300", "500"), row1)
+    checkEvaluation(expr, Seq("200", "400", "600"), row2)
+    checkEvaluation(expr, Seq("100"), row3)
+    checkEvaluation(expr, Seq(), row4)
+    checkEvaluation(expr, null, row5)
+    checkEvaluation(expr, null, row6)
+    checkEvaluation(expr, null, row7)
+
+    val expr1 = new RegExpExtractAll(s, p)
+    checkEvaluation(expr1, Seq("100", "300", "500"), row1)
+
+    val nonNullExpr = RegExpExtractAll(Literal("100-200,300-400,500-600"),
+      Literal("(\\d+)-(\\d+)"), Literal(1))
+    checkEvaluation(nonNullExpr, Seq("100", "300", "500"), row1)
+
+    // invalid group index
+    val row8 = create_row("100-200,300-400,500-600", "(\\d+)-(\\d+)", 3)
+    val row9 = create_row("100-200,300-400,500-600", "(\\d+).*", 2)
+    val row10 = create_row("100-200,300-400,500-600", "\\d+", 1)

Review comment:
       OK




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

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