cloud-fan commented on code in PR #45408: URL: https://github.com/apache/spark/pull/45408#discussion_r1517826436
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala: ########## @@ -2426,21 +2426,34 @@ case class Chr(child: Expression) """, since = "1.5.0", group = "string_funcs") -case class Base64(child: Expression) +case class Base64(child: Expression, chunkBase64: Boolean = SQLConf.get.base64Chunking) extends UnaryExpression with ImplicitCastInputTypes with NullIntolerant { + lazy val encoder: JBase64.Encoder = if (chunkBase64) { + JBase64.getMimeEncoder + } else { + JBase64.getMimeEncoder(-1, Array()) + } + override def dataType: DataType = StringType override def inputTypes: Seq[DataType] = Seq(BinaryType) protected override def nullSafeEval(bytes: Any): Any = { - UTF8String.fromBytes(JBase64.getMimeEncoder.encode(bytes.asInstanceOf[Array[Byte]])) + UTF8String.fromBytes(encoder.encode(bytes.asInstanceOf[Array[Byte]])) } override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = { nullSafeCodeGen(ctx, ev, (child) => { - s"""${ev.value} = UTF8String.fromBytes( - ${classOf[JBase64].getName}.getMimeEncoder().encode($child)); - """}) + s""" + if ($chunkBase64) { Review Comment: We know the value of `chunkBase64` before generating the java code, so we can do better ``` if (chunkBase64) { s""" ... } else { s""" ... } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org