cloud-fan commented on a change in pull request #32959:
URL: https://github.com/apache/spark/pull/32959#discussion_r666415654
##########
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)
+ }
+ if (s == null || s.trimAll().numBytes() == 0) {
return (Array.empty, None, false)
}
var tz: Option[String] = None
val segments: Array[Int] = Array[Int](1, 1, 1, 0, 0, 0, 0, 0, 0)
var i = 0
var currentSegmentValue = 0
+ var currentSegmentDigits = 0
val bytes = s.trimAll().getBytes
var j = 0
var digitsMilli = 0
var justTime = false
+ var yearSign: Option[Int] = None
+ if (bytes(j) == '-' || bytes(j) == '+') {
+ yearSign = if (bytes(j) == '-') Some(-1) else Some(1)
+ j += 1
+ }
while (j < bytes.length) {
val b = bytes(j)
val parsedValue = b - '0'.toByte
if (parsedValue < 0 || parsedValue > 9) {
- if (j == 0 && b == 'T') {
+ if (j == 0 && b == 'T' && yearSign.isEmpty) {
Review comment:
unnecessary change. if `j == 0`, then it's the first char and the year
sign can't be present.
--
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]