2019-11-16 13:54:52 +00:00
|
|
|
#include <Parsers/parseIntervalKind.h>
|
|
|
|
#include <Parsers/CommonParsers.h>
|
|
|
|
#include <Common/IntervalKind.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
bool parseIntervalKind(IParser::Pos & pos, Expected & expected, IntervalKind & result)
|
|
|
|
{
|
2023-09-20 21:00:25 +00:00
|
|
|
if (ParserKeyword("NANOSECOND").ignore(pos, expected) || ParserKeyword("NANOSECONDS").ignore(pos, expected)
|
|
|
|
|| ParserKeyword("SQL_TSI_NANOSECOND").ignore(pos, expected)
|
2022-02-13 10:01:48 +00:00
|
|
|
|| ParserKeyword("NS").ignore(pos, expected))
|
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Nanosecond;
|
2022-02-13 10:01:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-09-20 21:00:25 +00:00
|
|
|
if (ParserKeyword("MICROSECOND").ignore(pos, expected) || ParserKeyword("MICROSECONDS").ignore(pos, expected)
|
|
|
|
|| ParserKeyword("SQL_TSI_MICROSECOND").ignore(pos, expected)
|
2022-02-13 10:01:48 +00:00
|
|
|
|| ParserKeyword("MCS").ignore(pos, expected))
|
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Microsecond;
|
2022-02-13 10:01:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-09-20 21:00:25 +00:00
|
|
|
if (ParserKeyword("MILLISECOND").ignore(pos, expected) || ParserKeyword("MILLISECONDS").ignore(pos, expected)
|
|
|
|
|| ParserKeyword("SQL_TSI_MILLISECOND").ignore(pos, expected)
|
2022-02-13 10:01:48 +00:00
|
|
|
|| ParserKeyword("MS").ignore(pos, expected))
|
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Millisecond;
|
2022-02-13 10:01:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-09-20 21:00:25 +00:00
|
|
|
if (ParserKeyword("SECOND").ignore(pos, expected) || ParserKeyword("SECONDS").ignore(pos, expected)
|
|
|
|
|| ParserKeyword("SQL_TSI_SECOND").ignore(pos, expected)
|
2019-11-16 13:54:52 +00:00
|
|
|
|| ParserKeyword("SS").ignore(pos, expected) || ParserKeyword("S").ignore(pos, expected))
|
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Second;
|
2019-11-16 13:54:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-09-20 21:00:25 +00:00
|
|
|
if (ParserKeyword("MINUTE").ignore(pos, expected) || ParserKeyword("MINUTES").ignore(pos, expected)
|
|
|
|
|| ParserKeyword("SQL_TSI_MINUTE").ignore(pos, expected)
|
2019-11-16 13:54:52 +00:00
|
|
|
|| ParserKeyword("MI").ignore(pos, expected) || ParserKeyword("N").ignore(pos, expected))
|
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Minute;
|
2019-11-16 13:54:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-09-20 21:00:25 +00:00
|
|
|
if (ParserKeyword("HOUR").ignore(pos, expected) || ParserKeyword("HOURS").ignore(pos, expected)
|
|
|
|
|| ParserKeyword("SQL_TSI_HOUR").ignore(pos, expected)
|
2022-08-08 15:54:53 +00:00
|
|
|
|| ParserKeyword("HH").ignore(pos, expected) || ParserKeyword("H").ignore(pos, expected))
|
2019-11-16 13:54:52 +00:00
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Hour;
|
2019-11-16 13:54:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-09-20 21:00:25 +00:00
|
|
|
if (ParserKeyword("DAY").ignore(pos, expected) || ParserKeyword("DAYS").ignore(pos, expected)
|
|
|
|
|| ParserKeyword("SQL_TSI_DAY").ignore(pos, expected)
|
2019-11-16 13:54:52 +00:00
|
|
|
|| ParserKeyword("DD").ignore(pos, expected) || ParserKeyword("D").ignore(pos, expected))
|
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Day;
|
2019-11-16 13:54:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-09-20 21:00:25 +00:00
|
|
|
if (ParserKeyword("WEEK").ignore(pos, expected) || ParserKeyword("WEEKS").ignore(pos, expected)
|
|
|
|
|| ParserKeyword("SQL_TSI_WEEK").ignore(pos, expected)
|
2019-11-16 13:54:52 +00:00
|
|
|
|| ParserKeyword("WK").ignore(pos, expected) || ParserKeyword("WW").ignore(pos, expected))
|
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Week;
|
2019-11-16 13:54:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-09-20 21:00:25 +00:00
|
|
|
if (ParserKeyword("MONTH").ignore(pos, expected) || ParserKeyword("MONTHS").ignore(pos, expected)
|
|
|
|
|| ParserKeyword("SQL_TSI_MONTH").ignore(pos, expected)
|
2019-11-16 13:54:52 +00:00
|
|
|
|| ParserKeyword("MM").ignore(pos, expected) || ParserKeyword("M").ignore(pos, expected))
|
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Month;
|
2019-11-16 13:54:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-09-20 21:00:25 +00:00
|
|
|
if (ParserKeyword("QUARTER").ignore(pos, expected) || ParserKeyword("QUARTERS").ignore(pos, expected)
|
|
|
|
|| ParserKeyword("SQL_TSI_QUARTER").ignore(pos, expected)
|
2019-11-16 13:54:52 +00:00
|
|
|
|| ParserKeyword("QQ").ignore(pos, expected) || ParserKeyword("Q").ignore(pos, expected))
|
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Quarter;
|
2019-11-16 13:54:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-09-20 21:00:25 +00:00
|
|
|
if (ParserKeyword("YEAR").ignore(pos, expected) || ParserKeyword("YEARS").ignore(pos, expected)
|
|
|
|
|| ParserKeyword("SQL_TSI_YEAR").ignore(pos, expected)
|
2019-11-16 13:54:52 +00:00
|
|
|
|| ParserKeyword("YYYY").ignore(pos, expected) || ParserKeyword("YY").ignore(pos, expected))
|
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Year;
|
2019-11-16 13:54:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|