This commit is contained in:
Alexander Kuzmenkov 2021-04-16 21:50:12 +03:00
parent b991cbf9d6
commit 2782b2a6b0
2 changed files with 15 additions and 12 deletions

View File

@ -237,7 +237,9 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
* but the old comment said it is impossible, without mentioning * but the old comment said it is impossible, without mentioning
* the reason. We should also negate the nonnegative literals, * the reason. We should also negate the nonnegative literals,
* for symmetry. We print the negated value without parentheses, * for symmetry. We print the negated value without parentheses,
* because they are not needed around a single literal. * because they are not needed around a single literal. Also we
* use formatting from FieldVisitorToString, so that the type is
* preserved (e.g. -0. is printed with trailing period).
*/ */
if (literal && name == "negate") if (literal && name == "negate")
{ {
@ -257,14 +259,15 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
// fuzzer. Decimals are always signed, so no need // fuzzer. Decimals are always signed, so no need
// to deduce the result type like we do for ints. // to deduce the result type like we do for ints.
const auto int_value = value.getValue().value; const auto int_value = value.getValue().value;
settings.ostr << ValueType{ settings.ostr << FieldVisitorToString{}(ValueType{
-int_value, -int_value,
value.getScale()}; value.getScale()});
} }
else if constexpr (std::is_arithmetic_v<ValueType>) else if constexpr (std::is_arithmetic_v<ValueType>)
{ {
using ResultType = typename NumberTraits::ResultOfNegate<ValueType>::Type; using ResultType = typename NumberTraits::ResultOfNegate<ValueType>::Type;
settings.ostr << -static_cast<ResultType>(value); settings.ostr << FieldVisitorToString{}(
-static_cast<ResultType>(value));
return true; return true;
} }

View File

@ -8,10 +8,10 @@ SELECT
-1 IN (-1) -1 IN (-1)
explain syntax select negate(1.), negate(-1.), - -1., -(-1.), (-1.) in (-1.); explain syntax select negate(1.), negate(-1.), - -1., -(-1.), (-1.) in (-1.);
SELECT SELECT
-1, -1.,
1, 1.,
1, 1.,
1, 1.,
-1. IN (-1.) -1. IN (-1.)
explain syntax select negate(-9223372036854775808), -(-9223372036854775808), - -9223372036854775808; explain syntax select negate(-9223372036854775808), -(-9223372036854775808), - -9223372036854775808;
SELECT SELECT
@ -27,8 +27,8 @@ SELECT
0 IN (0) 0 IN (0)
explain syntax select negate(0.), negate(-0.), - -0., -(-0.), (-0.) in (-0.); explain syntax select negate(0.), negate(-0.), - -0., -(-0.), (-0.) in (-0.);
SELECT SELECT
-0, -0.,
0, 0.,
0, 0.,
0, 0.,
-0. IN (-0.) -0. IN (-0.)