eatoncys commented on a change in pull request #23010: [SPARK-26012][SQL]Null 
and '' values should not cause dynamic partition failure of string types
URL: https://github.com/apache/spark/pull/23010#discussion_r248142099
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileFormatWriter.scala
 ##########
 @@ -49,6 +52,18 @@ object FileFormatWriter extends Logging {
       customPartitionLocations: Map[TablePartitionSpec, String],
       outputColumns: Seq[Attribute])
 
+  /** A function that converts the empty string to null for partition values. 
*/
+  case class Empty2Null(child: Expression) extends UnaryExpression with 
String2StringExpression {
+    override def convert(v: UTF8String): UTF8String = if (v.numBytes() == 0) 
null else v
+    override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
+      nullSafeCodeGen(ctx, ev, c =>
+        s"""if ($c.numBytes() == 0) {
+           |${ev.isNull} = true;
+           |${ev.value} = null; }
+           |else ${ev.value} = $c;""".stripMargin)
+    }
 
 Review comment:
   Modified, thanks for review.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to