ClickHouse/src/Parsers/ParserSetQuery.cpp
Azat Khuzhin 5b3ab48861 More forward declaration for generic headers
The following headers are pretty generic, so use forward declaration as
much as possible:
- Context.h
- Settings.h
- ConnectionTimeouts.h
(Also this shows that some missing some includes -- this has been fixed)

And split ConnectionTimeouts.h into ConnectionTimeoutsContext.h (since
module part cannot be added for it, due to recursive build dependencies
that will be introduced)

Also remove Settings from the RemoteBlockInputStream/RemoteQueryExecutor
and just pass the context, since settings was passed only in speicifc
places, that can allow making a copy of Context (i.e. Copier).

Approx results (How much units will be recompiled after changing file X?):

- ConnectionTimeouts.h
  - mainline: 100

- Context.h:
  - mainline: ~800
  - patched:  415

- Settings.h:
  - mainline: 900-1K
  - patched:  440 (most of them because of the Context.h)
2020-12-12 17:43:10 +03:00

82 lines
1.8 KiB
C++

#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTLiteral.h>
#include <Parsers/ASTSetQuery.h>
#include <Parsers/CommonParsers.h>
#include <Parsers/ParserSetQuery.h>
#include <Common/typeid_cast.h>
#include <Common/SettingsChanges.h>
namespace DB
{
/// Parse `name = value`.
bool ParserSetQuery::parseNameValuePair(SettingChange & change, IParser::Pos & pos, Expected & expected)
{
ParserCompoundIdentifier name_p;
ParserLiteral value_p;
ParserToken s_eq(TokenType::Equals);
ASTPtr name;
ASTPtr value;
if (!name_p.parse(pos, name, expected))
return false;
if (!s_eq.ignore(pos, expected))
return false;
if (ParserKeyword("TRUE").ignore(pos, expected))
value = std::make_shared<ASTLiteral>(Field(UInt64(1)));
else if (ParserKeyword("FALSE").ignore(pos, expected))
value = std::make_shared<ASTLiteral>(Field(UInt64(0)));
else if (!value_p.parse(pos, value, expected))
return false;
tryGetIdentifierNameInto(name, change.name);
change.value = value->as<ASTLiteral &>().value;
return true;
}
bool ParserSetQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
ParserToken s_comma(TokenType::Comma);
if (!parse_only_internals)
{
ParserKeyword s_set("SET");
if (!s_set.ignore(pos, expected))
return false;
}
SettingsChanges changes;
while (true)
{
if (!changes.empty() && !s_comma.ignore(pos))
break;
changes.push_back(SettingChange{});
if (!parseNameValuePair(changes.back(), pos, expected))
return false;
}
auto query = std::make_shared<ASTSetQuery>();
node = query;
query->is_standalone = !parse_only_internals;
query->changes = std::move(changes);
return true;
}
}