| 18 | ParserTimeInterval::ParserTimeInterval() = default; |
| 19 | |
| 20 | bool ParserTimeInterval::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) |
| 21 | { |
| 22 | CalendarTimeInterval::Intervals intervals; |
| 23 | while (true) |
| 24 | { |
| 25 | ASTPtr value; |
| 26 | IntervalKind kind; |
| 27 | if (!ParserNumber{}.parse(pos, value, expected)) |
| 28 | break; |
| 29 | if (!parseIntervalKind(pos, expected, kind)) |
| 30 | return false; |
| 31 | |
| 32 | UInt64 val = 0; |
| 33 | if (!value->as<ASTLiteral &>().value.tryGet(val)) |
| 34 | throw Exception(ErrorCodes::SYNTAX_ERROR, "Time interval must be an integer"); |
| 35 | intervals.emplace_back(kind, val); |
| 36 | } |
| 37 | |
| 38 | if (intervals.empty()) |
| 39 | return false; |
| 40 | |
| 41 | std::sort(intervals.begin(), intervals.end()); |
| 42 | for (size_t i = 0; i + 1 < intervals.size(); ++i) |
| 43 | { |
| 44 | if (intervals[i].first == intervals[i + 1].first) |
| 45 | throw Exception(ErrorCodes::SYNTAX_ERROR, "Time interval contains multiple {} components", intervals[i].first.toString()); |
| 46 | } |
| 47 | |
| 48 | CalendarTimeInterval interval(intervals); |
| 49 | |
| 50 | if (!options.allow_zero) |
| 51 | interval.assertPositive(); |
| 52 | if (!options.allow_mixing_calendar_and_clock_units) |
| 53 | interval.assertSingleUnit(); |
| 54 | |
| 55 | auto time_interval = make_intrusive<ASTTimeInterval>(); |
| 56 | time_interval->interval = interval; |
| 57 | |
| 58 | node = time_interval; |
| 59 | return true; |
| 60 | } |
| 61 | |
| 62 | } |
nothing calls this directly
no test coverage detected