| 1 | #include <Parsers/parseIntervalKind.h> | 
|---|
| 2 | #include <Parsers/CommonParsers.h> | 
|---|
| 3 | #include <Common/IntervalKind.h> | 
|---|
| 4 |  | 
|---|
| 5 |  | 
|---|
| 6 | namespace DB | 
|---|
| 7 | { | 
|---|
| 8 | bool parseIntervalKind(IParser::Pos & pos, Expected & expected, IntervalKind & result) | 
|---|
| 9 | { | 
|---|
| 10 | if (ParserKeyword( "SECOND").ignore(pos, expected) || ParserKeyword( "SQL_TSI_SECOND").ignore(pos, expected) | 
|---|
| 11 | || ParserKeyword( "SS").ignore(pos, expected) || ParserKeyword( "S").ignore(pos, expected)) | 
|---|
| 12 | { | 
|---|
| 13 | result = IntervalKind::Second; | 
|---|
| 14 | return true; | 
|---|
| 15 | } | 
|---|
| 16 |  | 
|---|
| 17 | if (ParserKeyword( "MINUTE").ignore(pos, expected) || ParserKeyword( "SQL_TSI_MINUTE").ignore(pos, expected) | 
|---|
| 18 | || ParserKeyword( "MI").ignore(pos, expected) || ParserKeyword( "N").ignore(pos, expected)) | 
|---|
| 19 | { | 
|---|
| 20 | result = IntervalKind::Minute; | 
|---|
| 21 | return true; | 
|---|
| 22 | } | 
|---|
| 23 |  | 
|---|
| 24 | if (ParserKeyword( "HOUR").ignore(pos, expected) || ParserKeyword( "SQL_TSI_HOUR").ignore(pos, expected) | 
|---|
| 25 | || ParserKeyword( "HH").ignore(pos, expected)) | 
|---|
| 26 | { | 
|---|
| 27 | result = IntervalKind::Hour; | 
|---|
| 28 | return true; | 
|---|
| 29 | } | 
|---|
| 30 |  | 
|---|
| 31 | if (ParserKeyword( "DAY").ignore(pos, expected) || ParserKeyword( "SQL_TSI_DAY").ignore(pos, expected) | 
|---|
| 32 | || ParserKeyword( "DD").ignore(pos, expected) || ParserKeyword( "D").ignore(pos, expected)) | 
|---|
| 33 | { | 
|---|
| 34 | result = IntervalKind::Day; | 
|---|
| 35 | return true; | 
|---|
| 36 | } | 
|---|
| 37 |  | 
|---|
| 38 | if (ParserKeyword( "WEEK").ignore(pos, expected) || ParserKeyword( "SQL_TSI_WEEK").ignore(pos, expected) | 
|---|
| 39 | || ParserKeyword( "WK").ignore(pos, expected) || ParserKeyword( "WW").ignore(pos, expected)) | 
|---|
| 40 | { | 
|---|
| 41 | result = IntervalKind::Week; | 
|---|
| 42 | return true; | 
|---|
| 43 | } | 
|---|
| 44 |  | 
|---|
| 45 | if (ParserKeyword( "MONTH").ignore(pos, expected) || ParserKeyword( "SQL_TSI_MONTH").ignore(pos, expected) | 
|---|
| 46 | || ParserKeyword( "MM").ignore(pos, expected) || ParserKeyword( "M").ignore(pos, expected)) | 
|---|
| 47 | { | 
|---|
| 48 | result = IntervalKind::Month; | 
|---|
| 49 | return true; | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 | if (ParserKeyword( "QUARTER").ignore(pos, expected) || ParserKeyword( "SQL_TSI_QUARTER").ignore(pos, expected) | 
|---|
| 53 | || ParserKeyword( "QQ").ignore(pos, expected) || ParserKeyword( "Q").ignore(pos, expected)) | 
|---|
| 54 | { | 
|---|
| 55 | result = IntervalKind::Quarter; | 
|---|
| 56 | return true; | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | if (ParserKeyword( "YEAR").ignore(pos, expected) || ParserKeyword( "SQL_TSI_YEAR").ignore(pos, expected) | 
|---|
| 60 | || ParserKeyword( "YYYY").ignore(pos, expected) || ParserKeyword( "YY").ignore(pos, expected)) | 
|---|
| 61 | { | 
|---|
| 62 | result = IntervalKind::Year; | 
|---|
| 63 | return true; | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | return false; | 
|---|
| 67 | } | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|