-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Regexp_replace support regexp [databricks] (#4063)
* Integrate regex parser and transpiler with regexp_replace Signed-off-by: Andy Grove <andygrove@nvidia.com> * revert change * fix shim builds * fix regression in qa_nightly_test * update compatibility docs * fix compilation error in 31xdb shim * attempt to fix 312db compilation error * Restore legacy behavior of using GpuStringReplace if the regex pattern is a literal string * fix typo * fix import in 301db shim * Update docs/compatibility.md Co-authored-by: Jason Lowe <jlowe@nvidia.com> * Update docs/compatibility.md Co-authored-by: Jason Lowe <jlowe@nvidia.com> * Improve willNotWorkOnGpu messages * Improve willNotWorkOnGpu messages * Improve willNotWorkOnGpu messages * update generated docs * fix regression * remove unused imports * remove unused imports * remove unused imports * remove unused imports * remove unused imports Co-authored-by: Jason Lowe <jlowe@nvidia.com>
- Loading branch information
Showing
20 changed files
with
665 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
sql-plugin/src/main/301db/scala/com/nvidia/spark/rapids/shims/v2/GpuRegExpReplaceExec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2021, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.nvidia.spark.rapids.shims.v2 | ||
|
||
import com.nvidia.spark.rapids.{CudfRegexTranspiler, DataFromReplacementRule, GpuExpression, GpuOverrides, RapidsConf, RapidsMeta, RegexUnsupportedException, TernaryExprMeta} | ||
|
||
import org.apache.spark.sql.catalyst.expressions.{Expression, Literal, RegExpReplace} | ||
import org.apache.spark.sql.rapids.{GpuRegExpReplace, GpuStringReplace} | ||
import org.apache.spark.sql.types.DataTypes | ||
import org.apache.spark.unsafe.types.UTF8String | ||
|
||
class GpuRegExpReplaceMeta( | ||
expr: RegExpReplace, | ||
conf: RapidsConf, | ||
parent: Option[RapidsMeta[_, _, _]], | ||
rule: DataFromReplacementRule) | ||
extends TernaryExprMeta[RegExpReplace](expr, conf, parent, rule) { | ||
|
||
override def tagExprForGpu(): Unit = { | ||
expr.regexp match { | ||
case Literal(null, _) => | ||
willNotWorkOnGpu(s"null pattern is not supported on GPU") | ||
case Literal(s: UTF8String, DataTypes.StringType) => | ||
val pattern = s.toString | ||
if (pattern.isEmpty) { | ||
willNotWorkOnGpu(s"empty pattern is not supported on GPU") | ||
} | ||
|
||
if (GpuOverrides.isSupportedStringReplacePattern(expr.regexp)) { | ||
// use GpuStringReplace | ||
} else { | ||
try { | ||
new CudfRegexTranspiler(replace = true).transpile(pattern) | ||
} catch { | ||
case e: RegexUnsupportedException => | ||
willNotWorkOnGpu(e.getMessage) | ||
} | ||
} | ||
|
||
case _ => | ||
willNotWorkOnGpu(s"non-literal pattern is not supported on GPU") | ||
} | ||
} | ||
|
||
override def convertToGpu( | ||
lhs: Expression, | ||
regexp: Expression, | ||
rep: Expression): GpuExpression = { | ||
if (GpuOverrides.isSupportedStringReplacePattern(expr.regexp)) { | ||
GpuStringReplace(lhs, regexp, rep) | ||
} else { | ||
GpuRegExpReplace(lhs, regexp, rep) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
.../main/301until310-nondb/scala/com/nvidia/spark/rapids/shims/v2/GpuRegExpReplaceMeta.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2021, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.nvidia.spark.rapids.shims.v2 | ||
|
||
import com.nvidia.spark.rapids._ | ||
|
||
import org.apache.spark.sql.catalyst.expressions.{Expression, Literal, RegExpReplace} | ||
import org.apache.spark.sql.rapids.{GpuRegExpReplace, GpuStringReplace} | ||
import org.apache.spark.sql.types.DataTypes | ||
import org.apache.spark.unsafe.types.UTF8String | ||
|
||
class GpuRegExpReplaceMeta( | ||
expr: RegExpReplace, | ||
conf: RapidsConf, | ||
parent: Option[RapidsMeta[_, _, _]], | ||
rule: DataFromReplacementRule) | ||
extends TernaryExprMeta[RegExpReplace](expr, conf, parent, rule) { | ||
|
||
override def tagExprForGpu(): Unit = { | ||
expr.regexp match { | ||
case Literal(null, _) => | ||
willNotWorkOnGpu(s"null pattern is not supported on GPU") | ||
case Literal(s: UTF8String, DataTypes.StringType) => | ||
val pattern = s.toString | ||
if (pattern.isEmpty) { | ||
willNotWorkOnGpu(s"empty pattern is not supported on GPU") | ||
} | ||
|
||
if (GpuOverrides.isSupportedStringReplacePattern(expr.regexp)) { | ||
// use GpuStringReplace | ||
} else { | ||
try { | ||
new CudfRegexTranspiler(replace = true).transpile(pattern) | ||
} catch { | ||
case e: RegexUnsupportedException => | ||
willNotWorkOnGpu(e.getMessage) | ||
} | ||
} | ||
|
||
case _ => | ||
willNotWorkOnGpu(s"non-literal pattern is not supported on GPU") | ||
} | ||
} | ||
|
||
override def convertToGpu( | ||
lhs: Expression, | ||
regexp: Expression, | ||
rep: Expression): GpuExpression = { | ||
if (GpuOverrides.isSupportedStringReplacePattern(expr.regexp)) { | ||
GpuStringReplace(lhs, regexp, rep) | ||
} else { | ||
GpuRegExpReplace(lhs, regexp, rep) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.