MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / parseImpl

Method parseImpl

src/Parsers/ParserTimeInterval.cpp:20–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18ParserTimeInterval::ParserTimeInterval() = default;
19
20bool 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}

Callers

nothing calls this directly

Calls 13

parseIntervalKindFunction · 0.85
assertPositiveMethod · 0.80
assertSingleUnitMethod · 0.80
ExceptionClass · 0.50
sortFunction · 0.50
parseMethod · 0.45
tryGetMethod · 0.45
emplace_backMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected