Skip to content

Commit

Permalink
improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove committed May 24, 2024
1 parent b3f47b7 commit 7979634
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/src/execution/datafusion/expressions/regexp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ impl PhysicalExpr for RLike {
)
}
} else {
// this should be unreachable because Spark will evaluate regex expressions against
// literal strings as part of query planning
Err(CometError::Internal("Only columnar inputs are supported".to_string()).into())
}
}
Expand Down
10 changes: 10 additions & 0 deletions spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,16 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde with CometExprShim
// in Rust, or even transpile the pattern to work around differences between the JVM
// and Rust regular expression engines
if (CometConf.COMET_REGEXP_ALLOW_INCOMPATIBLE.get()) {

// we currently only support scalar regex patterns
right match {
case Literal(_, DataTypes.StringType) =>
// supported
case _ =>
withInfo(expr, "Only scalar patterns are supported")
return None
}

val leftExpr = exprToProtoInternal(left, inputs)
val rightExpr = exprToProtoInternal(right, inputs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,12 @@ class CometExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelper {
withSQLConf(CometConf.COMET_REGEXP_ALLOW_INCOMPATIBLE.key -> "true") {
val query = sql(s"select id from $table where name rlike 'R[a-z]+s [Rr]ose'")
checkSparkAnswerAndOperator(query)

// test that we fall back to Spark if the pattern is not a scalar value
val query2 = sql(s"select id from $table where name rlike name")
val (sparkPlan, cometPlan) = checkSparkAnswer(query2)
val explain = new ExtendedExplainInfo().generateExtendedInfo(cometPlan)
assert(explain == "Only scalar patterns are supported")
}
}
}
Expand Down

0 comments on commit 7979634

Please sign in to comment.