diff options
-rw-r--r-- | sql/core/src/main/scala/org/apache/spark/sql/functions.scala | 10 | ||||
-rw-r--r-- | sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala | 4 |
2 files changed, 13 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 c8782df146..45d5d05d9f 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 @@ -2194,6 +2194,16 @@ object functions { } /** + * Replace all substrings of the specified string value that match regexp with rep. + * + * @group string_funcs + * @since 2.1.0 + */ + def regexp_replace(e: Column, pattern: Column, replacement: Column): Column = withExpr { + RegExpReplace(e.expr, pattern.expr, replacement.expr) + } + + /** * Decodes a BASE64 encoded string column and returns it as a binary column. * This is the reverse of base64. * 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 dff4226051..3edd988496 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 @@ -77,8 +77,10 @@ class StringFunctionsSuite extends QueryTest with SharedSQLContext { checkAnswer( df.select( regexp_replace($"a", "(\\d+)", "num"), + regexp_replace($"a", $"b", $"c"), regexp_extract($"a", "(\\d+)-(\\d+)", 1)), - Row("num-num", "100") :: Row("num-num", "100") :: Row("num-num", "100") :: Nil) + Row("num-num", "300", "100") :: Row("num-num", "400", "100") :: + Row("num-num", "400-400", "100") :: Nil) // for testing the mutable state of the expression in code gen. // This is a hack way to enable the codegen, thus the codegen is enable by default, |