| 1 | #pragma once |
| 2 | |
| 3 | #include <Core/Types.h> |
| 4 | |
| 5 | |
| 6 | namespace DB |
| 7 | { |
| 8 | /// Kind of a temporal interval. |
| 9 | struct IntervalKind |
| 10 | { |
| 11 | enum Kind |
| 12 | { |
| 13 | Second, |
| 14 | Minute, |
| 15 | Hour, |
| 16 | Day, |
| 17 | Week, |
| 18 | Month, |
| 19 | Quarter, |
| 20 | Year, |
| 21 | }; |
| 22 | Kind kind = Second; |
| 23 | |
| 24 | IntervalKind(Kind kind_ = Second) : kind(kind_) {} |
| 25 | operator Kind() const { return kind; } |
| 26 | |
| 27 | const char * toString() const; |
| 28 | |
| 29 | /// Returns number of seconds in one interval. |
| 30 | /// For `Month`, `Quarter` and `Year` the function returns an average number of seconds. |
| 31 | Int32 toAvgSeconds() const; |
| 32 | |
| 33 | /// Chooses an interval kind based on number of seconds. |
| 34 | /// For example, `IntervalKind::fromAvgSeconds(3600)` returns `IntervalKind::Hour`. |
| 35 | static IntervalKind fromAvgSeconds(Int64 num_seconds); |
| 36 | |
| 37 | /// Returns an uppercased version of what `toString()` returns. |
| 38 | const char * toKeyword() const; |
| 39 | |
| 40 | /// Returns the string which can be passed to the `unit` parameter of the dateDiff() function. |
| 41 | /// For example, `IntervalKind{IntervalKind::Day}.getDateDiffParameter()` returns "day". |
| 42 | const char * toDateDiffUnit() const; |
| 43 | |
| 44 | /// Returns the name of the function converting a number to the interval data type. |
| 45 | /// For example, `IntervalKind{IntervalKind::Day}.getToIntervalDataTypeFunctionName()` |
| 46 | /// returns "toIntervalDay". |
| 47 | const char * toNameOfFunctionToIntervalDataType() const; |
| 48 | |
| 49 | /// Returns the name of the function extracting time part from a date or a time. |
| 50 | /// For example, `IntervalKind{IntervalKind::Day}.getExtractTimePartFunctionName()` |
| 51 | /// returns "toDayOfMonth". |
| 52 | const char * () const; |
| 53 | }; |
| 54 | } |
| 55 | |