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_r273761370
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/DataSourceStrategy.scala
 ##########
 @@ -260,6 +261,75 @@ class FindDataSourceTable(sparkSession: SparkSession) 
extends Rule[LogicalPlan]
   }
 }
 
+/** 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 => {
+      val setIsNull = if (nullable) s"${ev.isNull} = true" else ""
+      s"""if ($c.numBytes() == 0) {
+         |  $setIsNull;
+         |  ${ev.value} = null;
+         |} else {
+         |  ${ev.value} = $c;
+         |}""".stripMargin
+    })
+  }
+}
+
+/** A strategy that converts the empty string to null for partition values. */
+case class UpdateEmptyValueOfPartitionToNull(conf: SQLConf) extends 
Rule[LogicalPlan] {
+  private def updateQueryPlan(query: LogicalPlan,
+    partitionColumnNames: Seq[String]): LogicalPlan = {
+      val partitionColumns = partitionColumnNames.map { name =>
+        query.output.find(a => conf.resolver(a.name, name)).getOrElse {
+          throw new AnalysisException(
+            s"Unable to resolve $name given 
[${query.output.map(_.name).mkString(", ")}]")
+        }
+      }
+      val partitionSet = AttributeSet(partitionColumns)
+      var needConvert = false
 
 Review comment:
   This is added for go through test cases, if it is not added, the test of 
`org.apache.spark.sql.hive.execution.HiveQuerySuite.SPARK-3810: 
PreprocessTableInsertion static partitioning support` will fail, because it 
checks the number of project.

----------------------------------------------------------------
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.
 
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