Skip to content

Commit f0f38ad

Browse files
committed
Add correctness tests for lookahead expressions.
Signed-off-by: Igor Peshansky <ipeshansky@nvidia.com>
1 parent 5477e23 commit f0f38ad

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

integration_tests/src/main/python/regexp_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,16 @@ def test_rlike_fallback_possessive_quantifier():
10401040
'RLike',
10411041
conf=_regexp_conf)
10421042

1043+
@allow_non_gpu('ProjectExec', 'RLike')
1044+
def test_rlike_fallback_lookaheads():
1045+
gen = mk_str_gen('(\u20ac|\\w){0,3}a[|b*.$\r\n]{0,2}c\\w{0,3}')
1046+
for pattern in ['a(?=a*)', 'a(?!a*)']:
1047+
assert_gpu_fallback_collect(
1048+
lambda spark, pattern=pattern: unary_op_df(spark, gen).selectExpr(
1049+
f'a rlike "{pattern}"'),
1050+
'RLike',
1051+
conf=_regexp_conf)
1052+
10431053
def test_regexp_extract_all_idx_zero():
10441054
gen = mk_str_gen('[abcd]{0,3}[0-9]{0,3}-[0-9]{0,3}[abcd]{1,3}')
10451055
assert_gpu_and_cpu_are_equal_collect(

tests/src/test/scala/com/nvidia/spark/rapids/RegularExpressionParserSuite.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,15 @@ class RegularExpressionParserSuite extends AnyFunSuite {
248248
RegexRepetition(RegexChar('a'), SimpleQuantifier('?')))), None))))
249249
}
250250

251+
test("group not starting with ? is a capturing group") {
252+
assert(parse("(=a)") === RegexSequence(ListBuffer(
253+
RegexGroup(true, RegexSequence(ListBuffer(
254+
RegexChar('='), RegexChar('a'))), None)))
255+
assert(parse("(!a)") === RegexSequence(ListBuffer(
256+
RegexGroup(true, RegexSequence(ListBuffer(
257+
RegexChar('!'), RegexChar('a'))), None)))
258+
}
259+
251260
test("complex expression") {
252261
val ast = parse(
253262
"^" + // start of line

tests/src/test/scala/com/nvidia/spark/rapids/RegularExpressionTranspilerSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ class RegularExpressionTranspilerSuite extends AnyFunSuite {
159159
}
160160

161161
test("cuDF does not support positive or negative lookahead") {
162-
val negPatterns = Seq("a(!b)", "a(!b)c?")
162+
val negPatterns = Seq("a(?!b)", "a(?!b)c?")
163163
negPatterns.foreach(pattern =>
164164
assertUnsupported(pattern, RegexFindMode,
165165
"Negative lookahead groups are not supported")
166166
)
167167

168-
val posPatterns = Seq("a(=b)", "a(=b)c?")
168+
val posPatterns = Seq("a(?=b)", "a(?=b)c?")
169169
posPatterns.foreach(pattern =>
170170
assertUnsupported(pattern, RegexFindMode,
171171
"Positive lookahead groups are not supported")

0 commit comments

Comments
 (0)