-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29926][SQL] Fix weird interval string whose value is only a dangling decimal point #26573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -505,7 +505,9 @@ object IntervalUtils { | |
| var days: Int = 0 | ||
| var microseconds: Long = 0 | ||
| var fractionScale: Int = 0 | ||
| val initialFractionScale = (NANOS_PER_SECOND / 10).toInt | ||
| var fraction: Int = 0 | ||
| var pointPrefixed: Boolean = false | ||
|
|
||
| def trimToNextState(b: Byte, next: ParseState): Unit = { | ||
| b match { | ||
|
|
@@ -545,6 +547,7 @@ object IntervalUtils { | |
| // We preset the scale to an invalid value to track fraction presence in the UNIT_BEGIN | ||
| // state. If we meet '.', the scale become valid for the VALUE_FRACTIONAL_PART state. | ||
| fractionScale = -1 | ||
| pointPrefixed = false | ||
| b match { | ||
| case '-' => | ||
| isNegative = true | ||
|
|
@@ -556,7 +559,8 @@ object IntervalUtils { | |
| isNegative = false | ||
| case '.' => | ||
| isNegative = false | ||
| fractionScale = (NANOS_PER_SECOND / 10).toInt | ||
| fractionScale = initialFractionScale | ||
| pointPrefixed = true | ||
| i += 1 | ||
| state = VALUE_FRACTIONAL_PART | ||
| case _ => throwIAE( s"unrecognized number '$currentWord'") | ||
|
|
@@ -572,7 +576,7 @@ object IntervalUtils { | |
| } | ||
| case ' ' => state = TRIM_BEFORE_UNIT | ||
| case '.' => | ||
| fractionScale = (NANOS_PER_SECOND / 10).toInt | ||
| fractionScale = initialFractionScale | ||
| state = VALUE_FRACTIONAL_PART | ||
| case _ => throwIAE(s"invalid value '$currentWord'") | ||
| } | ||
|
|
@@ -582,7 +586,7 @@ object IntervalUtils { | |
| case _ if '0' <= b && b <= '9' && fractionScale > 0 => | ||
| fraction += (b - '0') * fractionScale | ||
| fractionScale /= 10 | ||
| case ' ' => | ||
| case ' ' if !pointPrefixed || fractionScale < initialFractionScale => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need this, the cases are (
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rm
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah i see! |
||
| fraction /= NANOS_PER_MICROS.toInt | ||
| state = TRIM_BEFORE_UNIT | ||
| case _ if '0' <= b && b <= '9' => | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we still need it now?