Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration test for RLike with embedded null in input #3871

Merged
merged 7 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions docs/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -594,13 +594,10 @@ Spark uses `^` and `$` to refer to the start and end of the entire string (equiv

As a workaround, `\A` and `\Z` can be used instead of `^` and `$`.

### Null character in input
jlowe marked this conversation as resolved.
Show resolved Hide resolved
### Null support

The GPU implementation of RLike will not match anything after a null character within a string.

| Pattern | Input | Spark on CPU | Spark on GPU |
|-----------|-----------|--------------|--------------|
| `A` | `\u0000A` | Match | No Match |
The GPU implementation of RLike supports null characters in the input but does not support null characters in
the regular expression and will fall back to the CPU in this case.

### Qualifiers with nothing to repeat

Expand Down
22 changes: 21 additions & 1 deletion integration_tests/src/main/python/string_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import pytest

from asserts import assert_gpu_and_cpu_are_equal_collect, assert_gpu_and_cpu_are_equal_sql, assert_gpu_sql_fallback_collect
from asserts import assert_gpu_and_cpu_are_equal_collect, assert_gpu_and_cpu_are_equal_sql, assert_gpu_sql_fallback_collect, assert_gpu_fallback_collect
from conftest import is_databricks_runtime
from data_gen import *
from marks import *
Expand Down Expand Up @@ -461,6 +461,26 @@ def test_rlike():
'a rlike "a[bc]d"'),
conf={'spark.rapids.sql.expression.RLike': 'true'})

def test_rlike_embedded_null():
gen = mk_str_gen('[abcd]{1,3}')\
.with_special_case('\u0000aaa')
assert_gpu_and_cpu_are_equal_collect(
lambda spark: unary_op_df(spark, gen).selectExpr(
'a rlike "a{2}"',
jlowe marked this conversation as resolved.
Show resolved Hide resolved
'a rlike "a{1,3}"',
'a rlike "a{1,}"',
'a rlike "a[bc]d"'),
conf={'spark.rapids.sql.expression.RLike': 'true'})

@allow_non_gpu('ProjectExec', 'RLike')
def test_rlike_null_pattern():
gen = mk_str_gen('[abcd]{1,3}')
assert_gpu_fallback_collect(
lambda spark: unary_op_df(spark, gen).selectExpr(
'a rlike "a\u0000"'),
'RLike',
conf={'spark.rapids.sql.expression.RLike': 'true'})

def test_rlike_escape():
gen = mk_str_gen('[ab]{0,2}[\\-\\+]{0,2}')
assert_gpu_and_cpu_are_equal_collect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,15 @@ class GpuRLikeMeta(
rule: DataFromReplacementRule) extends BinaryExprMeta[RLike](expr, conf, parent, rule) {

override def tagExprForGpu(): Unit = {
if (!expr.right.isInstanceOf[Literal]) {
willNotWorkOnGpu(s"RLike with non-literal pattern is not supported on GPU")
expr.right match {
case Literal(str: UTF8String, _) =>
if (str.toString.contains("\u0000")) {
// see https://github.com/NVIDIA/spark-rapids/issues/3962
willNotWorkOnGpu("The GPU implementation of RLike does not " +
"support null characters in the pattern")
}
case _ =>
willNotWorkOnGpu(s"RLike with non-literal pattern is not supported on GPU")
}
}

Expand Down