Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b22f243
Generate benchmark results for JDK 8
MaxGekk Oct 24, 2019
c33710f
Generate benchmark results for JDK 11
MaxGekk Oct 24, 2019
ffa1bee
Initial implementation
MaxGekk Oct 25, 2019
a4c16a1
Add tests to IntervalUtilsSuite
MaxGekk Oct 25, 2019
f249f49
Optimize unit name matching
MaxGekk Oct 25, 2019
d077c87
Catch ArithmeticException
MaxGekk Oct 25, 2019
80f5a06
Generate benchmark results for JDK 8
MaxGekk Oct 25, 2019
479d5bd
Generate benchmark results for JDK 11
MaxGekk Oct 25, 2019
d68f41e
Merge remote-tracking branch 'remotes/origin/master' into string-to-i…
MaxGekk Oct 29, 2019
8e8e539
Merge remote-tracking branch 'remotes/origin/master' into string-to-i…
MaxGekk Nov 2, 2019
9dfb45d
Rebase on interval with days
MaxGekk Nov 2, 2019
8c3fb28
Merge remote-tracking branch 'remotes/origin/master' into string-to-i…
MaxGekk Nov 6, 2019
bc006a2
Refactor IntervalUtilsSuite to check fromString and stringToInterval
MaxGekk Nov 6, 2019
7515981
Bug fix: expect space after interval
MaxGekk Nov 6, 2019
78a2e8e
Use checkFromInvalidString
MaxGekk Nov 6, 2019
f61e6f8
Improve the multiple units test
MaxGekk Nov 6, 2019
dd8f2d1
Add a few units to the test
MaxGekk Nov 6, 2019
1204656
Return CalendarInterval from stringToInterval()
MaxGekk Nov 6, 2019
a2d91c3
Support fraction of seconds
MaxGekk Nov 6, 2019
94bd39b
Fix for negative values
MaxGekk Nov 6, 2019
98dd44f
Checks only second can have fractions
MaxGekk Nov 6, 2019
0cd7e88
Regen benchmark results for JDK 8
MaxGekk Nov 6, 2019
107d16c
Regen benchmark results for JDK 11
MaxGekk Nov 6, 2019
8dd9518
Address Wenchen's comments + change behavior for fractions
MaxGekk Nov 6, 2019
464eacc
Improve comments
MaxGekk Nov 6, 2019
dbad971
Unify structure
MaxGekk Nov 6, 2019
527b00e
Remove exact functions in fraction parsing
MaxGekk Nov 6, 2019
5e96a0e
Replace magic numbers
MaxGekk Nov 6, 2019
2222f13
Replace 100000000 by NANOS_PER_SECOND / 10
MaxGekk Nov 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address Wenchen's comments + change behavior for fractions
  • Loading branch information
MaxGekk committed Nov 6, 2019
commit 8dd95188ac8af1e5b9da206a92e6e660c2e7b46c
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,12 @@ object IntervalUtils {
isNegative = false
case _ => return null
}
state = PARSE_UNIT_VALUE
currentValue = 0
fraction = 0
// Sets the scale to an invalid value to track fraction presence
// in the BEGIN_UNIT_NAME state
fractionScale = -1
state = PARSE_UNIT_VALUE
case PARSE_UNIT_VALUE =>
b match {
case _ if '0' <= b && b <= '9' =>
Expand All @@ -476,7 +479,7 @@ object IntervalUtils {
case ' ' =>
state = BEGIN_UNIT_NAME
case '.' =>
fractionScale = 100000
fractionScale = 100000000
state = FRACTIONAL_PART
case _ => return null
}
Expand All @@ -487,6 +490,7 @@ object IntervalUtils {
fraction = Math.addExact(fraction, Math.multiplyExact(fractionScale, (b - '0')))
Copy link
Member Author

@MaxGekk MaxGekk Nov 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fractional part cannot overflow. The max number is 999999999 fits to Int. I will remove the exact functions.

fractionScale /= 10
case ' ' =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about 1. hour and 1. second?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spark-sql> select cast('1. seconds' as interval);
interval 1 seconds
spark-sql> select cast('1. days' as interval);
interval 1 days

fraction /= DateTimeUtils.NANOS_PER_MICROS.toInt
state = BEGIN_UNIT_NAME
case _ => return null
}
Expand All @@ -496,7 +500,7 @@ object IntervalUtils {
i += 1
} else {
// Checks that only seconds can have the fractional part
if (b != 's' && fraction != 0) {
if (b != 's' && fractionScale >= 0) {
return null
}
if (isNegative) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,21 @@ class IntervalUtilsSuite extends SparkFunSuite {
checkFromString("1 day 1 year", new CalendarInterval(12, 1, 0))
// duplicated fields
checkFromString("1 day 1 day", new CalendarInterval(0, 2, 0))
// value with fractions belongs to not seconds
// non seconds units cannot have the fractional part
checkFromInvalidString("1.5 days", "Error parsing interval string")
checkFromInvalidString("1. hour", "Error parsing interval string")
}

test("string to interval: seconds with fractional part") {
checkFromString("0.1 seconds", new CalendarInterval(0, 0, 100000))
checkFromString("1. seconds", new CalendarInterval(0, 0, 1000000))
checkFromString("123.001 seconds", new CalendarInterval(0, 0, 123001000))
checkFromString("1.001001 seconds", new CalendarInterval(0, 0, 1001001))
checkFromString("1 minute 1.001001 seconds", new CalendarInterval(0, 0, 61001001))
checkFromString("-1.5 seconds", new CalendarInterval(0, 0, -1500000))
// truncate to nanoseconds to microseconds
checkFromString("0.123456789 seconds", new CalendarInterval(0, 0, 123456))
checkFromInvalidString("0.123456789123 seconds", "Error parsing interval string")
}

test("from year-month string") {
Expand Down