mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
Do not add extra parentheses for tuple negate unary operator
This commit is contained in:
parent
192633cb9b
commit
4acd8f3147
@ -4,6 +4,7 @@
|
||||
#include <Common/FieldVisitorToString.h>
|
||||
#include <Common/SipHash.h>
|
||||
#include <Common/typeid_cast.h>
|
||||
#include <DataTypes/IDataType.h>
|
||||
#include <DataTypes/NumberTraits.h>
|
||||
#include <IO/Operators.h>
|
||||
#include <IO/WriteBufferFromString.h>
|
||||
@ -243,8 +244,11 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
|
||||
const auto * literal = arguments->children[0]->as<ASTLiteral>();
|
||||
const auto * function = arguments->children[0]->as<ASTFunction>();
|
||||
bool negate = name == "negate";
|
||||
bool is_tuple = literal && literal->value.getType() == Field::Types::Tuple;
|
||||
// do not add parentheses for tuple literal, otherwise extra parens will be added `-((3, 7, 3), 1)` -> `-(((3, 7, 3), 1))`
|
||||
bool literal_need_parens = literal && !is_tuple;
|
||||
// negate always requires parentheses, otherwise -(-1) will be printed as --1
|
||||
bool negate_need_parens = negate && (literal || (function && function->name == "negate"));
|
||||
bool negate_need_parens = negate && (literal_need_parens || (function && function->name == "negate"));
|
||||
// We don't need parentheses around a single literal.
|
||||
bool need_parens = !literal && frame.need_parens && !negate_need_parens;
|
||||
|
||||
|
@ -71,3 +71,4 @@
|
||||
3.6060655943063797
|
||||
4.3208683194033215
|
||||
\N
|
||||
SELECT -((3, 7, 3), 100)
|
||||
|
@ -101,3 +101,6 @@ SELECT LpNorm((1, 2, 3), -1.); -- { serverError 69 }
|
||||
SELECT LpNorm((1, 2, 3), -1); -- { serverError 44 }
|
||||
SELECT LpNorm((1, 2, 3), 0.); -- { serverError 69 }
|
||||
SELECT cosineDistance(materialize((NULL, -2147483648)), (1048577, 1048575));
|
||||
|
||||
-- not extra parentheses
|
||||
EXPLAIN SYNTAX SELECT -((3, 7, 3), 100);
|
||||
|
Loading…
Reference in New Issue
Block a user