AngersZhuuuu commented on a change in pull request #30421:
URL: https://github.com/apache/spark/pull/30421#discussion_r535134384



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -509,13 +509,28 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with 
SQLConfHelper with Logg
     }
   }
 
+  private def convertTypedLiteralToString(literal: Literal): String = literal 
match {
+    case Literal(data: Int, _: DateType) =>
+      DateFormatter(getZoneId(SQLConf.get.sessionLocalTimeZone)).format(data)
+    case Literal(data: Long, _: TimestampType) =>
+      
TimestampFormatter.getFractionFormatter(getZoneId(SQLConf.get.sessionLocalTimeZone))
+        .format(data)
+    case Literal(data: CalendarInterval, _: CalendarIntervalType) => 
data.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) {

Review comment:
       > > ... but Cast.eval can't run here.
   > 
   > Why? What's the error?
   
   SInce `eval()` need input, you mean write it like this ?
   ```
     protected def visitConstant(ctx: ConstantContext): String = 
withOrigin(ctx) {
       expression(ctx) match {
         case l: Literal => if (l.value == null) {
           null
         } else {
           Cast(l, StringType, Some(SQLConf.get.sessionLocalTimeZone))
             .eval(InternalRow.apply(l.value)).toString
         }
         case _ =>
           throw IllegalArgumentException("")
       }
     }
   ``` 




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



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

Reply via email to