cloud-fan commented on a change in pull request #30421:
URL: https://github.com/apache/spark/pull/30421#discussion_r530069998



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -503,13 +503,32 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with 
SQLConfHelper with Logg
     }
   }
 
+  private def convertTypedLiteralToString(literal: Literal): String = literal 
match {
+    case Literal(data: Int, _: DateType) =>
+      UTF8String.fromString(
+        DateFormatter(getZoneId(SQLConf.get.sessionLocalTimeZone))
+          .format(data)).toString
+    case Literal(data: Long, _: TimestampType) =>
+      UTF8String.fromString(
+        
TimestampFormatter.getFractionFormatter(getZoneId(SQLConf.get.sessionLocalTimeZone))
+          .format(data)).toString
+    case Literal(data: CalendarInterval, _: CalendarIntervalType) =>
+      UTF8String.fromString(data.toString).toString
+    case Literal(data: Array[Byte], _: BinaryType) =>
+      UTF8String.fromBytes(data).toString
+    case Literal(_, dataType) =>
+      throw new IllegalArgumentException(s"Literals of type '$dataType' are 
not" +
+        " supported when use typed literal as partition col value.")
+  }
+
   /**
    * Convert a constant of any type into a string. This is typically used in 
DDL commands, and its
    * main purpose is to prevent slight differences due to back to back 
conversions i.e.:
    * String -> Literal -> String.
    */
   protected def visitStringConstant(ctx: ConstantContext): String = 
withOrigin(ctx) {
     ctx match {
+      case l: TypeConstructorContext => 
convertTypedLiteralToString(visitTypeConstructor(l))
       case s: StringLiteralContext => createString(s)
       case o => o.getText

Review comment:
       previous, `date'xxx'` is just a string `"date'xxx'"`? then we need a 
migration guide for this change.




----------------------------------------------------------------
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:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to