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)
|
|
|
|
{
|
2024-03-18 15:58:57 +00:00
|
|
|
if (ParserKeyword(Keyword::NANOSECOND).ignore(pos, expected) || ParserKeyword(Keyword::NANOSECONDS).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::SQL_TSI_NANOSECOND).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::NS).ignore(pos, expected))
|
2022-02-13 10:01:48 +00:00
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Nanosecond;
|
2022-02-13 10:01:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-03-18 15:58:57 +00:00
|
|
|
if (ParserKeyword(Keyword::MICROSECOND).ignore(pos, expected) || ParserKeyword(Keyword::MICROSECONDS).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::SQL_TSI_MICROSECOND).ignore(pos, expected))
|
2022-02-13 10:01:48 +00:00
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Microsecond;
|
2022-02-13 10:01:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-03-18 15:58:57 +00:00
|
|
|
if (ParserKeyword(Keyword::MILLISECOND).ignore(pos, expected) || ParserKeyword(Keyword::MILLISECONDS).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::SQL_TSI_MILLISECOND).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::MS).ignore(pos, expected))
|
2022-02-13 10:01:48 +00:00
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Millisecond;
|
2022-02-13 10:01:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-03-18 15:58:57 +00:00
|
|
|
if (ParserKeyword(Keyword::SECOND).ignore(pos, expected) || ParserKeyword(Keyword::SECONDS).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::SQL_TSI_SECOND).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::SS).ignore(pos, expected) || ParserKeyword(Keyword::S).ignore(pos, expected))
|
2019-11-16 13:54:52 +00:00
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Second;
|
2019-11-16 13:54:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-03-18 15:58:57 +00:00
|
|
|
if (ParserKeyword(Keyword::MINUTE).ignore(pos, expected) || ParserKeyword(Keyword::MINUTES).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::SQL_TSI_MINUTE).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::MI).ignore(pos, expected) || ParserKeyword(Keyword::N).ignore(pos, expected))
|
2019-11-16 13:54:52 +00:00
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Minute;
|
2019-11-16 13:54:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-03-18 15:58:57 +00:00
|
|
|
if (ParserKeyword(Keyword::HOUR).ignore(pos, expected) || ParserKeyword(Keyword::HOURS).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::SQL_TSI_HOUR).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::HH).ignore(pos, expected) || ParserKeyword(Keyword::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;
|
|
|
|
}
|
|
|
|
|
2024-03-18 15:58:57 +00:00
|
|
|
if (ParserKeyword(Keyword::DAY).ignore(pos, expected) || ParserKeyword(Keyword::DAYS).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::SQL_TSI_DAY).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::DD).ignore(pos, expected) || ParserKeyword(Keyword::D).ignore(pos, expected))
|
2019-11-16 13:54:52 +00:00
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Day;
|
2019-11-16 13:54:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-03-18 15:58:57 +00:00
|
|
|
if (ParserKeyword(Keyword::WEEK).ignore(pos, expected) || ParserKeyword(Keyword::WEEKS).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::SQL_TSI_WEEK).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::WK).ignore(pos, expected) || ParserKeyword(Keyword::WW).ignore(pos, expected))
|
2019-11-16 13:54:52 +00:00
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Week;
|
2019-11-16 13:54:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-03-18 15:58:57 +00:00
|
|
|
if (ParserKeyword(Keyword::MONTH).ignore(pos, expected) || ParserKeyword(Keyword::MONTHS).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::SQL_TSI_MONTH).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::MM).ignore(pos, expected) || ParserKeyword(Keyword::M).ignore(pos, expected))
|
2019-11-16 13:54:52 +00:00
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Month;
|
2019-11-16 13:54:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-03-18 15:58:57 +00:00
|
|
|
if (ParserKeyword(Keyword::QUARTER).ignore(pos, expected) || ParserKeyword(Keyword::QUARTERS).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::SQL_TSI_QUARTER).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::QQ).ignore(pos, expected) || ParserKeyword(Keyword::Q).ignore(pos, expected))
|
2019-11-16 13:54:52 +00:00
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Quarter;
|
2019-11-16 13:54:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-03-18 15:58:57 +00:00
|
|
|
if (ParserKeyword(Keyword::YEAR).ignore(pos, expected) || ParserKeyword(Keyword::YEARS).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::SQL_TSI_YEAR).ignore(pos, expected)
|
|
|
|
|| ParserKeyword(Keyword::YYYY).ignore(pos, expected) || ParserKeyword(Keyword::YY).ignore(pos, expected))
|
2019-11-16 13:54:52 +00:00
|
|
|
{
|
2024-02-27 13:37:21 +00:00
|
|
|
result = IntervalKind::Kind::Year;
|
2019-11-16 13:54:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|