diff options
author | Sean Owen <sowen@cloudera.com> | 2016-08-07 12:20:07 +0100 |
---|---|---|
committer | Sean Owen <sowen@cloudera.com> | 2016-08-07 12:20:07 +0100 |
commit | 8d8725208771a8815a60160a5a30dc6ea87a7e6a (patch) | |
tree | 191042d5279e59aeaadc60f3585c32ebaf5ca3ee /sql/core/src | |
parent | bdfab9f942dcad7c1f3de9b6df5c01dee2392055 (diff) | |
download | spark-8d8725208771a8815a60160a5a30dc6ea87a7e6a.tar.gz spark-8d8725208771a8815a60160a5a30dc6ea87a7e6a.tar.bz2 spark-8d8725208771a8815a60160a5a30dc6ea87a7e6a.zip |
[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 <sowen@cloudera.com>
Closes #14504 from srowen/SPARK-16409.
Diffstat (limited to 'sql/core/src')
-rw-r--r-- | sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala | 8 |
1 files changed, 8 insertions, 0 deletions
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( |