Skip to content

Commit

Permalink
Add tests for regexp() and regexp_like() [databricks] (NVIDIA#4093)
Browse files Browse the repository at this point in the history
* Add tests for regexp and regexplike (synonyms for RLike)

Signed-off-by: Andy Grove <andygrove@nvidia.com>

* add import
  • Loading branch information
andygrove authored and Chong Gao committed Dec 6, 2021
1 parent 9c2ee54 commit 2ad38e6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions integration_tests/src/main/python/string_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from marks import *
from pyspark.sql.types import *
import pyspark.sql.functions as f
from spark_session import is_before_spark_320

def mk_str_gen(pattern):
return StringGen(pattern).with_special_case('').with_special_pattern('.{0,10}')
Expand Down Expand Up @@ -483,6 +484,28 @@ def test_regexp_replace():
'regexp_replace(a, "a|b|c", "A")'),
conf={'spark.rapids.sql.expression.RegExpReplace': 'true'})

@pytest.mark.skipif(is_before_spark_320(), reason='regexp is synonym for RLike starting in Spark 3.2.0')
def test_regexp():
gen = mk_str_gen('[abcd]{1,3}')
assert_gpu_and_cpu_are_equal_collect(
lambda spark: unary_op_df(spark, gen).selectExpr(
'regexp(a, "a{2}")',
'regexp(a, "a{1,3}")',
'regexp(a, "a{1,}")',
'regexp(a, "a[bc]d")'),
conf={'spark.rapids.sql.expression.RLike': 'true'})

@pytest.mark.skipif(is_before_spark_320(), reason='regexp_like is synonym for RLike starting in Spark 3.2.0')
def test_regexp_like():
gen = mk_str_gen('[abcd]{1,3}')
assert_gpu_and_cpu_are_equal_collect(
lambda spark: unary_op_df(spark, gen).selectExpr(
'regexp_like(a, "a{2}")',
'regexp_like(a, "a{1,3}")',
'regexp_like(a, "a{1,}")',
'regexp_like(a, "a[bc]d")'),
conf={'spark.rapids.sql.expression.RLike': 'true'})

@pytest.mark.skipif(is_databricks_runtime(),
reason='Databricks optimizes out regexp_replace call in this case')
@allow_non_gpu('ProjectExec', 'RegExpReplace')
Expand Down

0 comments on commit 2ad38e6

Please sign in to comment.