Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ object DateTimeUtils {
}

/**
* Parses a given UTF8 date string to the corresponding a corresponding [[Long]] value.
* Trim and parse a given UTF8 date string to the corresponding a corresponding [[Long]] value.
* The return type is [[Option]] in order to distinguish between 0L and null. The following
* formats are allowed:
*
Expand Down Expand Up @@ -311,7 +311,7 @@ object DateTimeUtils {
val segments: Array[Int] = Array[Int](1, 1, 1, 0, 0, 0, 0, 0, 0)
var i = 0
var currentSegmentValue = 0
val bytes = s.getBytes
val bytes = s.trim.getBytes
var j = 0
var digitsMilli = 0
var justTime = false
Expand Down Expand Up @@ -441,7 +441,7 @@ object DateTimeUtils {
}

/**
* Parses a given UTF8 date string to a corresponding [[Int]] value.
* Trim and parse a given UTF8 date string to a corresponding [[Int]] value.
* The return type is [[Option]] in order to distinguish between 0 and null. The following
* formats are allowed:
*
Expand All @@ -459,7 +459,7 @@ object DateTimeUtils {
val segments: Array[Int] = Array[Int](1, 1, 1)
var i = 0
var currentSegmentValue = 0
val bytes = s.getBytes
val bytes = s.trim.getBytes
var j = 0
while (j < bytes.length && (i < 3 && !(bytes(j) == ' ' || bytes(j) == 'T'))) {
val b = bytes(j)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,10 @@ class DateTimeUtilsSuite extends SparkFunSuite {
c = Calendar.getInstance()
c.set(2015, 2, 18, 0, 0, 0)
c.set(Calendar.MILLISECOND, 0)
assert(stringToDate(UTF8String.fromString("2015-03-18")).get ===
millisToDays(c.getTimeInMillis))
assert(stringToDate(UTF8String.fromString("2015-03-18 ")).get ===
millisToDays(c.getTimeInMillis))
assert(stringToDate(UTF8String.fromString("2015-03-18 123142")).get ===
millisToDays(c.getTimeInMillis))
assert(stringToDate(UTF8String.fromString("2015-03-18T123123")).get ===
millisToDays(c.getTimeInMillis))
assert(stringToDate(UTF8String.fromString("2015-03-18T")).get ===
millisToDays(c.getTimeInMillis))
Seq("2015-03-18", "2015-03-18 ", " 2015-03-18", " 2015-03-18 ", "2015-03-18 123142",
Copy link
Contributor

Choose a reason for hiding this comment

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

the test result doesn't change?

Copy link
Member

@dongjoon-hyun dongjoon-hyun Nov 7, 2018

Choose a reason for hiding this comment

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

New test cases (with space padding) are added; e.g. ' 2015-03-18' and ' 2015-03-18 '.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah i see

"2015-03-18T123123", "2015-03-18T").foreach { s =>
assert(stringToDate(UTF8String.fromString(s)).get === millisToDays(c.getTimeInMillis))
}

assert(stringToDate(UTF8String.fromString("2015-03-18X")).isEmpty)
assert(stringToDate(UTF8String.fromString("2015/03/18")).isEmpty)
Expand Down Expand Up @@ -214,9 +208,10 @@ class DateTimeUtilsSuite extends SparkFunSuite {
c = Calendar.getInstance(tz)
c.set(2015, 2, 18, 0, 0, 0)
c.set(Calendar.MILLISECOND, 0)
checkStringToTimestamp("2015-03-18", Option(c.getTimeInMillis * 1000))
checkStringToTimestamp("2015-03-18 ", Option(c.getTimeInMillis * 1000))
checkStringToTimestamp("2015-03-18T", Option(c.getTimeInMillis * 1000))

Seq("2015-03-18", "2015-03-18 ", " 2015-03-18", " 2015-03-18 ", "2015-03-18T").foreach { s =>
checkStringToTimestamp(s, Option(c.getTimeInMillis * 1000))
}

c = Calendar.getInstance(tz)
c.set(2015, 2, 18, 12, 3, 17)
Expand Down