Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix comments in DayTimeIntervalType
  • Loading branch information
MaxGekk committed Feb 22, 2021
commit afde2e46116311fcb5b05762bb33e4e2db1f99bd
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import org.apache.spark.annotation.Unstable
/**
* The type represents day-time intervals of the SQL standard. A day-time interval is made up
* of a contiguous subset of the following fields:
* - SECOND, seconds within minutes and possibly fractions of a second (0-59.999999),
* - MINUTE, minutes within hours (0-59),
* - HOUR, hours within days (0-23),
* - DAY, days in the range (0-106751991).
* - SECOND, seconds within minutes and possibly fractions of a second [0..59.999999],
* - MINUTE, minutes within hours [0..59],
* - HOUR, hours within days [0..23],
* - DAY, days in the range [0..106751991].
Copy link
Contributor

Choose a reason for hiding this comment

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

how do you get the upper limit?

Copy link
Contributor

Choose a reason for hiding this comment

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

can this be negative?

Copy link
Member Author

@MaxGekk MaxGekk Feb 24, 2021

Choose a reason for hiding this comment

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

how do you get the upper limit?

From the formula below:

>>> 2**63/((60*60*23 + 60 * 59 + 59.999999) * 1000000)
106751991.1685362

even more conservative:

>>> 2**63 / (24 * 60 * 60 * 1000000.0)
106751991.16730064

can this be negative?

Interval value, yes. The field, no, according to SQL:2016:
Screenshot 2021-02-24 at 19 17 31

So, individual interval fields are non-negative but interval itself can have a sign, and be negative.

*
* `DayTimeIntervalType` represents positive as well as negative day-time intervals.
*
Expand All @@ -39,7 +39,7 @@ import org.apache.spark.annotation.Unstable
@Unstable
class DayTimeIntervalType private() extends AtomicType {
/**
* Internally, values of day-time intervals are stored in long values as amount of time in terms
* Internally, values of day-time intervals are stored in `Long` values as amount of time in terms
* of microseconds that are calculated by the formula:
* -/+ (24*60*60 * DAY + 60*60 * HOUR + 60 * MINUTE + SECOND) * 1000000
*/
Expand All @@ -50,7 +50,8 @@ class DayTimeIntervalType private() extends AtomicType {
private[sql] val ordering = implicitly[Ordering[InternalType]]

/**
* The day-time interval type has constant precision, and it always occupies 8 bytes.
* The day-time interval type has constant precision. A value of the type always occupies 8 bytes.
* The DAY field is constrained by the upper bound 106751991 to fit to `Long`.
*/
override def defaultSize: Int = 8

Expand Down