peter-toth commented on code in PR #59571:
URL: https://github.com/apache/spark/pull/59571#discussion_r4312174332


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala:
##########
@@ -688,6 +689,10 @@ case class Literal (value: Any, dataType: DataType) 
extends LeafExpression {
     case (v: Decimal, t: DecimalType) => s"${v}BD"
     case (v: Int, DateType) =>
       s"DATE '$toString'"
+    // toString strips trailing zeros, but the parser derives TIME(7)..TIME(9) 
from the number of
+    // fractional digits (6 or fewer give TIME(6)), so pad back to exactly 
`precision` digits.
+    case (_: Long, t: TimeType) if t.precision > TimeType.MICROS_PRECISION =>
+      s"TIME '${padToNanosPrecision(toString, t.precision)}'"
     case (_: Long, _: TimeType) =>
       s"TIME '$toString'"

Review Comment:
   Two additions from running this at the head:
   - The `spark.sql(args)` form above doesn't get there. A `CAST` argument is 
rejected with `INVALID_SQL_ARG`. `EXECUTE IMMEDIATE` does get there, with a 
`CAST` or a `TIME(3)` session variable in `USING`. With `DECLARE VARIABLE v3 
TIME(3) DEFAULT TIME '12:00:00.1'`, `SELECT v3 = '12:00:00.1001'` returns 
`true`. `EXECUTE IMMEDIATE 'SELECT ? = \'12:00:00.1001\', typeof(?)' USING v3, 
v3` returns `false, time(6)`.
   - This case is not new in 4.3. branch-4.1 already substitutes `Literal.sql` 
by default and has `TIME(0)`-`TIME(6)`, with every `TIME` literal parsed as 
`TIME(6)`. I read that from the code and didn't run it on 4.1. So it looks like 
a separate bug for 4.1 and later, rather than part of this 4.3 blocker.
   



-- 
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: [email protected]

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