From 8d8725208771a8815a60160a5a30dc6ea87a7e6a Mon Sep 17 00:00:00 2001 From: Sean Owen Date: Sun, 7 Aug 2016 12:20:07 +0100 Subject: [SPARK-16409][SQL] regexp_extract with optional groups causes NPE ## What changes were proposed in this pull request? regexp_extract actually returns null when it shouldn't when a regex matches but the requested optional group did not. This makes it return an empty string, as apparently designed. ## How was this patch tested? Additional unit test Author: Sean Owen Closes #14504 from srowen/SPARK-16409. --- .../test/scala/org/apache/spark/sql/StringFunctionsSuite.scala | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'sql/core/src') diff --git a/sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala index 57ca5d9c4d..3b76aaf7d0 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala @@ -94,6 +94,14 @@ class StringFunctionsSuite extends QueryTest with SharedSQLContext { Row("300", "100") :: Row("400", "100") :: Row("400-400", "100") :: Nil) } + test("non-matching optional group") { + val df = Seq("aaaac").toDF("s") + checkAnswer( + df.select(regexp_extract($"s", "(a+)(b)?(c)", 2)), + Row("") + ) + } + test("string ascii function") { val df = Seq(("abc", "")).toDF("a", "b") checkAnswer( -- cgit v1.2.3