Skip to content

Commit fee5ab2

Browse files
committed
fix: validate regex pattern at convert time so invalid or null patterns fall back to Spark
When routing RLike through the JVM UDF, reject Literal(null) and patterns that fail Pattern.compile during planning. Both cases now produce withInfo + None, letting Spark evaluate the expression instead of crashing the executor task with PatternSyntaxException or NullPointerException.
1 parent 56327ed commit fee5ab2

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

spark/src/main/scala/org/apache/comet/serde/strings.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,19 @@ object CometRLike extends CometExpressionSerde[RLike] {
316316
inputs: Seq[Attribute],
317317
binding: Boolean): Option[Expr] = {
318318
expr.right match {
319-
case Literal(_, DataTypes.StringType) =>
319+
case Literal(value, DataTypes.StringType) =>
320+
if (value == null) {
321+
withInfo(expr, "Null literal pattern is handled by Spark fallback")
322+
return None
323+
}
324+
val patternStr = value.toString
325+
try {
326+
java.util.regex.Pattern.compile(patternStr)
327+
} catch {
328+
case e: java.util.regex.PatternSyntaxException =>
329+
withInfo(expr, s"Invalid regex pattern: ${e.getDescription}")
330+
return None
331+
}
320332
val subjectProto = exprToProtoInternal(expr.left, inputs, binding)
321333
val patternProto = exprToProtoInternal(expr.right, inputs, binding)
322334
if (subjectProto.isEmpty || patternProto.isEmpty) {

0 commit comments

Comments
 (0)