NVIDIA / spark-rapids

Spark RAPIDS plugin - accelerate Apache Spark with GPUs
https://nvidia.github.io/spark-rapids
Apache License 2.0
822 stars 235 forks source link

[BUG] Parse regular expressions using JDK to make error behavior more consistent between CPU and GPU #11651

Open NVnavkumar opened 4 weeks ago

NVnavkumar commented 4 weeks ago

Describe the bug Some regular expression patterns are invalid in Java, and throw an exception on the CPU but run with no exceptions on the GPU. This is due to the inconsistencies in the regexp parsers in the different systems (in many cases Java being excessively strict).

Steps/Code to reproduce bug

PySpark reproduce:

df = spark.createDataFrame(spark.sparkContext.parallelize([["aaaa"]]), "a string")
df.selectExpr("regexp_replace(a, 'a{', 'bb') as result").show()

When running on CPU, you get a java.util.regex.PatternSyntaxException. On the GPU, this will run without an exception

Suggested fix

I think we should run Pattern.compile(...) on any regular expressions before they hit the transpiler (and even before they hit optimized versions as well) to have consistent behavior between CPU and GPU. That way the same exception will be thrown when the SQL is evaluated.