Skip to content

Commit

Permalink
Better
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitamikhaylov committed Mar 13, 2023
1 parent 9cb0185 commit f0b514a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
20 changes: 20 additions & 0 deletions src/Disks/getDiskConfigurationFromAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,24 @@ DiskConfigurationPtr getDiskConfigurationFromAST(const std::string & root_name,
return conf;
}


ASTs convertDiskConfigurationToAST(const Poco::Util::AbstractConfiguration & configuration, const std::string & config_path)
{
ASTs result;

Poco::Util::AbstractConfiguration::Keys keys;
configuration.keys(config_path, keys);

for (const auto & key : keys)
{
result.push_back(
makeASTFunction(
"equals",
std::make_shared<ASTIdentifier>(key),
std::make_shared<ASTLiteral>(configuration.getString(config_path + "." + key))));
}

return result;
}

}
8 changes: 8 additions & 0 deletions src/Disks/getDiskConfigurationFromAST.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ using DiskConfigurationPtr = Poco::AutoPtr<Poco::Util::AbstractConfiguration>;
*/
DiskConfigurationPtr getDiskConfigurationFromAST(const std::string & root_name, const ASTs & disk_args, ContextPtr context);

/// The same as above function, but return XML::Document for easier modification of result configuration.
[[ maybe_unused ]] Poco::AutoPtr<Poco::XML::Document> getDiskConfigurationFromASTImpl(const std::string & root_name, const ASTs & disk_args, ContextPtr context);

/*
* A reverse function.
*/
[[ maybe_unused ]] ASTs convertDiskConfigurationToAST(const Poco::Util::AbstractConfiguration & configuration, const std::string & config_path);

}
6 changes: 6 additions & 0 deletions src/Parsers/ASTDeleteQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ void ASTDeleteQuery::formatQueryImpl(const FormatSettings & settings, FormatStat

settings.ostr << (settings.hilite ? hilite_keyword : "") << " WHERE " << (settings.hilite ? hilite_none : "");
predicate->formatImpl(settings, state, frame);

if (settings_ast)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << settings.nl_or_ws << "SETTINGS " << (settings.hilite ? hilite_none : "");
settings_ast->formatImpl(settings, state, frame);
}
}

}
15 changes: 11 additions & 4 deletions src/Parsers/ExpressionElementParsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2151,17 +2151,21 @@ bool ParserTTLElement::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
ParserKeyword s_set("SET");
ParserKeyword s_recompress("RECOMPRESS");
ParserKeyword s_codec("CODEC");
ParserToken s_comma(TokenType::Comma);
ParserToken s_eq(TokenType::Equals);
ParserKeyword s_materialize("MATERIALIZE");
ParserKeyword s_remove("REMOVE");
ParserKeyword s_modify("MODIFY");

ParserIdentifier parser_identifier;
ParserStringLiteral parser_string_literal;
ParserExpression parser_exp;
ParserExpressionList parser_keys_list(false);
ParserCodec parser_codec;

ParserList parser_assignment_list(
std::make_unique<ParserAssignment>(), std::make_unique<ParserToken>(TokenType::Comma));
if (s_materialize.checkWithoutMoving(pos, expected) ||
s_remove.checkWithoutMoving(pos, expected) ||
s_modify.checkWithoutMoving(pos, expected))

return false;

ASTPtr ttl_expr;
if (!parser_exp.parse(pos, ttl_expr, expected))
Expand Down Expand Up @@ -2219,6 +2223,9 @@ bool ParserTTLElement::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)

if (s_set.ignore(pos))
{
ParserList parser_assignment_list(
std::make_unique<ParserAssignment>(), std::make_unique<ParserToken>(TokenType::Comma));

if (!parser_assignment_list.parse(pos, group_by_assignments, expected))
return false;
}
Expand Down

0 comments on commit f0b514a

Please sign in to comment.