linhongliu-db commented on a change in pull request #32959: URL: https://github.com/apache/spark/pull/32959#discussion_r665015489
########## File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala ########## @@ -249,70 +249,107 @@ object DateTimeUtils { * the input string can't be parsed as timestamp, the result timestamp segments are empty. */ def parseTimestampString(s: UTF8String): (Array[Int], Option[ZoneId], Boolean) = { - if (s == null) { + def isValidDigits(segment: Int, digits: Int): Boolean = { + // A Long is able to represent a timestamp within [+-]200 thousand years + val maxDigitsYear = 6 + // For the nanosecond part, more than 6 digits is allowed, but will be truncated. + segment == 6 || (segment == 0 && digits > 0 && digits <= maxDigitsYear) || + (segment != 0 && segment != 6 && digits <= 2) Review comment: segments except year are allowed to have 0 digits before this PR. so I didn't do zero checks for these segments. for example, before this PR, the below query is valid: ```sql select cast('12::' as timestamp); -- output: 2021-07-07 12:00:00 select cast('T' as timestamp); -- output: 2021-07-07 00:00:00 ``` ########## File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala ########## @@ -249,70 +249,107 @@ object DateTimeUtils { * the input string can't be parsed as timestamp, the result timestamp segments are empty. */ def parseTimestampString(s: UTF8String): (Array[Int], Option[ZoneId], Boolean) = { - if (s == null) { + def isValidDigits(segment: Int, digits: Int): Boolean = { + // A Long is able to represent a timestamp within [+-]200 thousand years + val maxDigitsYear = 6 + // For the nanosecond part, more than 6 digits is allowed, but will be truncated. + segment == 6 || (segment == 0 && digits > 0 && digits <= maxDigitsYear) || + (segment != 0 && segment != 6 && digits <= 2) Review comment: segments except year are allowed to have 0 digits before this PR. so I didn't do zero checks for these segments. for example, before and after this PR, the below query is valid: ```sql select cast('12::' as timestamp); -- output: 2021-07-07 12:00:00 select cast('T' as timestamp); -- output: 2021-07-07 00:00:00 ``` -- 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: reviews-unsubscr...@spark.apache.org 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