diff options
author | Sean Owen <sowen@cloudera.com> | 2016-08-10 10:14:43 +0100 |
---|---|---|
committer | Sean Owen <sowen@cloudera.com> | 2016-08-10 10:14:43 +0100 |
commit | 0578ff9681edbaab4ae68f67272dc3d4d890d53b (patch) | |
tree | d54b571ca32c769dbcfdf116aaf51a178c2785ae /sql/core | |
parent | eca58755fbbc11937b335ad953a3caff89b818e6 (diff) | |
download | spark-0578ff9681edbaab4ae68f67272dc3d4d890d53b.tar.gz spark-0578ff9681edbaab4ae68f67272dc3d4d890d53b.tar.bz2 spark-0578ff9681edbaab4ae68f67272dc3d4d890d53b.zip |
[SPARK-16324][SQL] regexp_extract should doc that it returns empty string when match fails
## What changes were proposed in this pull request?
Doc that regexp_extract returns empty string when regex or group does not match
## How was this patch tested?
Jenkins test, with a few new test cases
Author: Sean Owen <sowen@cloudera.com>
Closes #14525 from srowen/SPARK-16324.
Diffstat (limited to 'sql/core')
-rw-r--r-- | sql/core/src/main/scala/org/apache/spark/sql/functions.scala | 3 | ||||
-rw-r--r-- | sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala | 4 |
2 files changed, 6 insertions, 1 deletions
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala index 81f6ed75e6..18e736ab69 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala @@ -2175,7 +2175,8 @@ object functions { def ltrim(e: Column): Column = withExpr {StringTrimLeft(e.expr) } /** - * Extract a specific(idx) group identified by a java regex, from the specified string column. + * Extract a specific group matched by a Java regex, from the specified string column. + * If the regex did not match, or the specified group did not match, an empty string is returned. * * @group string_funcs * @since 1.5.0 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 64b4718538..1cc77464b9 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 @@ -97,6 +97,10 @@ class StringFunctionsSuite extends QueryTest with SharedSQLContext { test("non-matching optional group") { val df = Seq(Tuple1("aaaac")).toDF("s") checkAnswer( + df.select(regexp_extract($"s", "(foo)", 1)), + Row("") + ) + checkAnswer( df.select(regexp_extract($"s", "(a+)(b)?(c)", 2)), Row("") ) |