@@ -21,7 +21,7 @@ package org.apache.comet.serde
2121
2222import java .util .Locale
2323
24- import org .apache .spark .sql .catalyst .expressions .{Attribute , Cast , Concat , ConcatWs , Expression , GetJsonObject , If , InitCap , IsNull , Left , Length , Like , Literal , Lower , RegExpReplace , Right , RLike , StringLPad , StringRepeat , StringRPad , StringSplit , Substring , SubstringIndex , Upper }
24+ import org .apache .spark .sql .catalyst .expressions .{Attribute , Cast , Concat , ConcatWs , Expression , GetJsonObject , If , InitCap , IsNull , Left , Length , Like , Literal , Lower , RegExpReplace , Right , RLike , StringLPad , StringRepeat , StringReplace , StringRPad , StringSplit , Substring , SubstringIndex , Upper }
2525import org .apache .spark .sql .types .{BinaryType , DataTypes , LongType , StringType }
2626import org .apache .spark .unsafe .types .UTF8String
2727
@@ -102,6 +102,27 @@ object CometInitCap extends CometScalarFunction[InitCap]("initcap") {
102102 }
103103}
104104
105+ object CometStringReplace extends CometScalarFunction [StringReplace ](" replace" ) {
106+
107+ override def getSupportLevel (expr : StringReplace ): SupportLevel = Compatible ()
108+
109+ override def convert (
110+ expr : StringReplace ,
111+ inputs : Seq [Attribute ],
112+ binding : Boolean ): Option [Expr ] = {
113+ if (CometConf .isExprAllowIncompat(getExprConfigName(expr))) {
114+ // The native DataFusion `replace` avoids the JVM allocations of the codegen
115+ // dispatcher but is not Spark-compatible for an empty search string, so it is
116+ // only used when incompatibility is explicitly allowed.
117+ super .convert(expr, inputs, binding)
118+ } else {
119+ // Run Spark's own generated code inside the Comet pipeline so the result matches Spark
120+ // exactly. Falls back to Spark when the codegen dispatcher is disabled.
121+ CometScalaUDF .emitJvmCodegenDispatch(expr, inputs, binding)
122+ }
123+ }
124+ }
125+
105126object CometSubstring extends CometExpressionSerde [Substring ] {
106127
107128 override def convert (
0 commit comments