Miscellaneous

This commit is contained in:
Alexey Milovidov 2024-04-08 04:19:34 +02:00
parent 0ff26d2d77
commit 537f045c1c
4 changed files with 16 additions and 30 deletions

View File

@ -2056,7 +2056,7 @@ MultiQueryProcessingStage ClientBase::analyzeMultiQueryText(
return MultiQueryProcessingStage::QUERIES_END; return MultiQueryProcessingStage::QUERIES_END;
// Remove leading empty newlines and other whitespace, because they // Remove leading empty newlines and other whitespace, because they
// are annoying to filter in query log. This is mostly relevant for // are annoying to filter in the query log. This is mostly relevant for
// the tests. // the tests.
while (this_query_begin < all_queries_end && isWhitespaceASCII(*this_query_begin)) while (this_query_begin < all_queries_end && isWhitespaceASCII(*this_query_begin))
++this_query_begin; ++this_query_begin;
@ -2086,7 +2086,7 @@ MultiQueryProcessingStage ClientBase::analyzeMultiQueryText(
{ {
parsed_query = parseQuery(this_query_end, all_queries_end, true); parsed_query = parseQuery(this_query_end, all_queries_end, true);
} }
catch (Exception & e) catch (const Exception & e)
{ {
current_exception.reset(e.clone()); current_exception.reset(e.clone());
return MultiQueryProcessingStage::PARSING_EXCEPTION; return MultiQueryProcessingStage::PARSING_EXCEPTION;
@ -2111,9 +2111,9 @@ MultiQueryProcessingStage ClientBase::analyzeMultiQueryText(
// INSERT queries may have the inserted data in the query text // INSERT queries may have the inserted data in the query text
// that follow the query itself, e.g. "insert into t format CSV 1;2". // that follow the query itself, e.g. "insert into t format CSV 1;2".
// They need special handling. First of all, here we find where the // They need special handling. First of all, here we find where the
// inserted data ends. In multy-query mode, it is delimited by a // inserted data ends. In multi-query mode, it is delimited by a
// newline. // newline.
// The VALUES format needs even more handling -- we also allow the // The VALUES format needs even more handling - we also allow the
// data to be delimited by semicolon. This case is handled later by // data to be delimited by semicolon. This case is handled later by
// the format parser itself. // the format parser itself.
// We can't do multiline INSERTs with inline data, because most // We can't do multiline INSERTs with inline data, because most

View File

@ -161,7 +161,7 @@ void highlight(const String & query, std::vector<replxx::Replxx::Color> & colors
if (pos >= colors.size()) if (pos >= colors.size())
pos = colors.size() - 1; pos = colors.size() - 1;
colors[pos] = replxx::color::bg(replxx::color::rgb666(5, 3, 3)); colors[pos] = Replxx::Color::BRIGHTRED;
} }
if (last_token.type == TokenType::Semicolon || last_token.type == TokenType::VerticalDelimiter if (last_token.type == TokenType::Semicolon || last_token.type == TokenType::VerticalDelimiter

View File

@ -60,21 +60,6 @@ bool parseDatabaseAndTableAsAST(IParser::Pos & pos, Expected & expected, ASTPtr
} }
bool parseDatabase(IParser::Pos & pos, Expected & expected, String & database_str)
{
ParserToken s_dot(TokenType::Dot);
ParserIdentifier identifier_parser;
ASTPtr database;
database_str = "";
if (!identifier_parser.parse(pos, database, expected))
return false;
tryGetIdentifierNameInto(database, database_str);
return true;
}
bool parseDatabaseAsAST(IParser::Pos & pos, Expected & expected, ASTPtr & database) bool parseDatabaseAsAST(IParser::Pos & pos, Expected & expected, ASTPtr & database)
{ {
ParserIdentifier identifier_parser(/* allow_query_parameter */true); ParserIdentifier identifier_parser(/* allow_query_parameter */true);

View File

@ -226,24 +226,27 @@ std::string getUnmatchedParenthesesErrorMessage(
} }
const char * getInsertData(const ASTPtr & ast) static ASTInsertQuery * getInsertAST(const ASTPtr & ast)
{ {
/// Either it is INSERT or EXPLAIN INSERT. /// Either it is INSERT or EXPLAIN INSERT.
ASTInsertQuery * insert = nullptr;
if (auto * explain = ast->as<ASTExplainQuery>()) if (auto * explain = ast->as<ASTExplainQuery>())
{ {
if (auto explained_query = explain->getExplainedQuery()) if (auto explained_query = explain->getExplainedQuery())
{ {
insert = explained_query->as<ASTInsertQuery>(); return explained_query->as<ASTInsertQuery>();
} }
} }
else else
{ {
insert = ast->as<ASTInsertQuery>(); return ast->as<ASTInsertQuery>();
} }
if (insert) return nullptr;
}
const char * getInsertData(const ASTPtr & ast)
{
if (const ASTInsertQuery * insert = getInsertAST(ast))
return insert->data; return insert->data;
return nullptr; return nullptr;
} }
@ -439,11 +442,9 @@ std::pair<const char *, bool> splitMultipartQuery(
ast = parseQueryAndMovePosition(parser, pos, end, "", true, max_query_size, max_parser_depth, max_parser_backtracks); ast = parseQueryAndMovePosition(parser, pos, end, "", true, max_query_size, max_parser_depth, max_parser_backtracks);
auto * insert = ast->as<ASTInsertQuery>(); if (ASTInsertQuery * insert = getInsertAST(ast))
if (insert && insert->data)
{ {
/// Data for INSERT is broken on new line /// Data for INSERT is broken on the new line
pos = insert->data; pos = insert->data;
while (*pos && *pos != '\n') while (*pos && *pos != '\n')
++pos; ++pos;