fix frame formatting error

This commit is contained in:
Alexander Kuzmenkov 2021-03-05 06:15:20 +03:00
parent 08148e062f
commit 7c8d17045c
3 changed files with 31 additions and 8 deletions

View File

@ -1317,7 +1317,10 @@ private:
auto base_after_fuzz = fuzz_base->formatForErrorMessage();
// Debug AST cloning errors.
// Check that the source AST didn't change after fuzzing. This
// helps debug AST cloning errors, where the cloned AST doesn't
// clone all its children, and erroneously points to some source
// child elements.
if (base_before_fuzz != base_after_fuzz)
{
fmt::print(stderr,
@ -1334,7 +1337,7 @@ private:
fmt::print(stderr, "IAST::clone() is broken for some AST node. This is a bug. The original AST ('dump before fuzz') and its cloned copy ('dump of cloned AST') refer to the same nodes, which must never happen. This means that their parent node doesn't implement clone() correctly.");
assert(false);
exit(1);
}
auto fuzzed_text = ast_to_process->formatForErrorMessage();
@ -1344,6 +1347,29 @@ private:
continue;
}
// Check that the query is formatted properly and we can parse
// it back and format again and get the same result. Unfortunately
// we can't compare the ASTs, which would be more sensitive to
// errors. This double formatting check doesn't catch all errors,
// e.g. we can format query incorrectly, but to a valid SQL that
// we can then parse and format into the same SQL.
{
const auto * tmp_pos = fuzzed_text.c_str();
auto parsed_formatted_query = parseQuery(tmp_pos,
tmp_pos + fuzzed_text.size(),
false /* allow_multi_statements */);
const auto formatted_twice
= parsed_formatted_query->formatForErrorMessage();
if (formatted_twice != fuzzed_text)
{
fmt::print(stderr, "The query formatting is broken. Got the following (different) text after formatting the fuzzed query and parsing it back:\n'{}'\n, expected:\n'{}'\n",
formatted_twice, fuzzed_text);
exit(1);
}
}
parsed_query = ast_to_process;
query_to_send = parsed_query->formatForErrorMessage();

View File

@ -81,7 +81,7 @@ void ASTWindowDefinition::formatImpl(const FormatSettings & settings,
}
else if (frame.end_type == WindowFrame::BoundaryType::Unbounded)
{
settings.ostr << "UNBOUNDED PRECEDING";
settings.ostr << "UNBOUNDED FOLLOWING";
}
else
{

View File

@ -533,6 +533,7 @@ static bool tryParseFrameDefinition(ASTWindowDefinition * node, IParser::Pos & p
ParserKeyword keyword_groups("GROUPS");
ParserKeyword keyword_range("RANGE");
node->frame.is_default = false;
if (keyword_rows.ignore(pos, expected))
{
node->frame.type = WindowFrame::FrameType::Rows;
@ -548,6 +549,7 @@ static bool tryParseFrameDefinition(ASTWindowDefinition * node, IParser::Pos & p
else
{
/* No frame clause. */
node->frame.is_default = true;
return true;
}
@ -699,11 +701,6 @@ static bool tryParseFrameDefinition(ASTWindowDefinition * node, IParser::Pos & p
}
}
if (!(node->frame == WindowFrame{}))
{
node->frame.is_default = false;
}
return true;
}