Fix inconsistent formatting of CODEC and STATISTICS

This commit is contained in:
Alexey Milovidov 2024-07-30 04:05:43 +02:00
parent a023f2c970
commit 8f920d064c
6 changed files with 12 additions and 2 deletions

View File

@ -285,6 +285,8 @@ static bool formatNamedArgWithHiddenValue(IAST * arg, const IAST::FormatSettings
void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
{
frame.expression_list_prepend_whitespace = false;
if (kind == Kind::CODEC || kind == Kind::STATISTICS || kind == Kind::BACKUP_NAME)
frame.allow_operators = false;
FormatStateStacked nested_need_parens = frame;
FormatStateStacked nested_dont_need_parens = frame;
nested_need_parens.need_parens = true;
@ -308,7 +310,7 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
/// Should this function to be written as operator?
bool written = false;
if (arguments && !parameters && nulls_action == NullsAction::EMPTY)
if (arguments && !parameters && frame.allow_operators && nulls_action == NullsAction::EMPTY)
{
/// Unary prefix operators.
if (arguments->children.size() == 1)

View File

@ -58,6 +58,8 @@ public:
TABLE_ENGINE,
DATABASE_ENGINE,
BACKUP_NAME,
CODEC,
STATISTICS,
};
Kind kind = Kind::ORDINARY_FUNCTION;

View File

@ -696,6 +696,7 @@ bool ParserCodec::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
auto function_node = std::make_shared<ASTFunction>();
function_node->name = "CODEC";
function_node->kind = ASTFunction::Kind::CODEC;
function_node->arguments = expr_list_args;
function_node->children.push_back(function_node->arguments);
@ -723,6 +724,7 @@ bool ParserStatisticsType::parseImpl(Pos & pos, ASTPtr & node, Expected & expect
auto function_node = std::make_shared<ASTFunction>();
function_node->name = "STATISTICS";
function_node->kind = ASTFunction::Kind::STATISTICS;
function_node->arguments = stat_type;
function_node->children.push_back(function_node->arguments);
node = function_node;

View File

@ -33,7 +33,9 @@ public:
{
case ASTFunction::Kind::ORDINARY_FUNCTION: findOrdinaryFunctionSecretArguments(); break;
case ASTFunction::Kind::WINDOW_FUNCTION: break;
case ASTFunction::Kind::LAMBDA_FUNCTION: break;
case ASTFunction::Kind::LAMBDA_FUNCTION: break;
case ASTFunction::Kind::CODEC: break;
case ASTFunction::Kind::STATISTICS: break;
case ASTFunction::Kind::TABLE_ENGINE: findTableEngineSecretArguments(); break;
case ASTFunction::Kind::DATABASE_ENGINE: findDatabaseEngineSecretArguments(); break;
case ASTFunction::Kind::BACKUP_NAME: findBackupNameSecretArguments(); break;

View File

@ -256,6 +256,7 @@ public:
bool expression_list_always_start_on_new_line = false; /// Line feed and indent before expression list even if it's of single element.
bool expression_list_prepend_whitespace = false; /// Prepend whitespace (if it is required)
bool surround_each_list_element_with_parens = false;
bool allow_operators = true; /// Format some functions, such as "plus", "in", etc. as operators.
size_t list_element_index = 0;
const IAST * current_select = nullptr;
};

View File

@ -193,6 +193,7 @@ ASTPtr ColumnStatisticsDescription::getAST() const
{
auto function_node = std::make_shared<ASTFunction>();
function_node->name = "STATISTICS";
function_node->kind = ASTFunction::Kind::STATISTICS;
function_node->arguments = std::make_shared<ASTExpressionList>();
for (const auto & [type, desc] : types_to_desc)
{