Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #50536 to 23.4: Fix incorrect constant folding #50567

Merged
merged 1 commit into from Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Parsers/ExpressionElementParsers.cpp
Expand Up @@ -829,7 +829,11 @@ static bool parseNumber(char * buffer, size_t size, bool negative, int base, Fie

if (pos_integer == buffer + size && errno != ERANGE && (!negative || uint_value <= (1ULL << 63)))
{
if (negative)
/// -0 should be still parsed as UInt instead of Int,
/// because otherwise it is not preserved during formatting-parsing roundtrip
/// (the signedness is lost during formatting)

if (negative && uint_value != 0)
res = static_cast<Int64>(-uint_value);
else
res = uint_value;
Expand Down
@@ -0,0 +1,4 @@
0 UInt8 -1 Int8 -0 Float64
0
0
0
@@ -0,0 +1,41 @@
SELECT -0, toTypeName(-0), -1, toTypeName(-1), -0., toTypeName(-0.);

DROP TABLE IF EXISTS t4;
DROP TABLE IF EXISTS t7;

create table t4 (c26 String) engine = Log;
create view t7 as select max(ref_3.c26) as c_2_c46_1 from t4 as ref_3;

select
c_7_c4585_14 as c_4_c4593_5
from
(select
avg(0) as c_7_c4572_1,
max(-0) as c_7_c4585_14
from
t7 as ref_0
group by ref_0.c_2_c46_1) as subq_0
where c_4_c4593_5 <= multiIf(true, 1, exp10(c_4_c4593_5) <= 1, 1, 1);

select x as c
from
(select 1 AS k,
max(0) as a,
max(-0) as x
from
t7 GROUP BY k)
where NOT ignore(c);

SELECT x
FROM
(
SELECT
avg(0) AS c_7_c4572_1,
max(-0) AS x
FROM t7 AS ref_0
GROUP BY ref_0.c_2_c46_1
)
WHERE x <= multiIf(true, 1, exp10(x) <= 1, 1, 1);

DROP TABLE t7;
DROP TABLE t4;