mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
Merge pull request #55575 from jh0x/no-octal-leading-zeroes
Consume leading zeroes when parsing a number in ConstantExpressionTemplate
This commit is contained in:
commit
b8d9880b17
@ -603,18 +603,21 @@ bool ConstantExpressionTemplate::parseLiteralAndAssertType(
|
||||
memcpy(buf, istr.position(), bytes_to_copy);
|
||||
buf[bytes_to_copy] = 0;
|
||||
|
||||
char * pos_double = buf;
|
||||
/// Skip leading zeroes - we don't want any funny octal business
|
||||
char * non_zero_buf = find_first_not_symbols<'0'>(buf, buf + bytes_to_copy);
|
||||
|
||||
char * pos_double = non_zero_buf;
|
||||
errno = 0;
|
||||
Float64 float_value = std::strtod(buf, &pos_double);
|
||||
if (pos_double == buf || errno == ERANGE || float_value < 0)
|
||||
Float64 float_value = std::strtod(non_zero_buf, &pos_double);
|
||||
if (pos_double == non_zero_buf || errno == ERANGE || float_value < 0)
|
||||
return false;
|
||||
|
||||
if (negative)
|
||||
float_value = -float_value;
|
||||
|
||||
char * pos_integer = buf;
|
||||
char * pos_integer = non_zero_buf;
|
||||
errno = 0;
|
||||
UInt64 uint_value = std::strtoull(buf, &pos_integer, 0);
|
||||
UInt64 uint_value = std::strtoull(non_zero_buf, &pos_integer, 0);
|
||||
if (pos_integer == pos_double && errno != ERANGE && (!negative || uint_value <= (1ULL << 63)))
|
||||
{
|
||||
istr.position() += pos_integer - buf;
|
||||
|
@ -0,0 +1,35 @@
|
||||
Leading zeroes into INTEGER
|
||||
1 1 00000 0 0
|
||||
1 2 0 0 0
|
||||
1 3 00 0 0
|
||||
1 4 01 1 1
|
||||
1 5 +01 1 1
|
||||
1 6 -01 -1 -1
|
||||
1 7 0001 1 1
|
||||
1 8 0005 5 5
|
||||
1 9 0008 8 8
|
||||
1 10 0017 17 17
|
||||
1 11 0021 21 21
|
||||
1 12 0051 51 51
|
||||
1 13 00000123 123 123
|
||||
1 14 0b10000 16 16
|
||||
1 15 0x0abcd 43981 43981
|
||||
1 16 0000.008 0 0
|
||||
1 17 1000.0008 1000 1000
|
||||
1 18 0008.0008 8 8
|
||||
Leading zeroes into Float32
|
||||
1 1 00000 0 0
|
||||
1 2 00009.00009 9.00009 9.00009
|
||||
1 3 00009e9 9000000000 9000000000
|
||||
1 4 00009e09 9000000000 9000000000
|
||||
1 5 00009e0009 9000000000 9000000000
|
||||
1 6 -00000 -0.1 -0.1
|
||||
1 7 -00009.00009 -9.00009 -9.00009
|
||||
1 8 -00009e9 -9000000000 -9000000000
|
||||
1 9 -00009e09 -9000000000 -9000000000
|
||||
1 10 -00009e0009 -9000000000 -9000000000
|
||||
1 11 +00000 0 0
|
||||
1 12 +00009.00009 9.00009 9.00009
|
||||
1 13 +00009e9 9000000000 9000000000
|
||||
1 14 +00009e09 9000000000 9000000000
|
||||
1 15 +00009e0009 9000000000 9000000000
|
28
tests/queries/0_stateless/02896_leading_zeroes_no_octal.sql
Normal file
28
tests/queries/0_stateless/02896_leading_zeroes_no_octal.sql
Normal file
@ -0,0 +1,28 @@
|
||||
DROP TABLE IF EXISTS t_leading_zeroes;
|
||||
DROP TABLE IF EXISTS t_leading_zeroes_f;
|
||||
|
||||
CREATE TABLE t_leading_zeroes(id INTEGER, input String, val INTEGER, expected INTEGER) ENGINE=MergeTree ORDER BY id;
|
||||
|
||||
INSERT INTO t_leading_zeroes VALUES (1, '00000', 00000, 0), (2, '0', 0, 0), (3, '00', 00, 0), (4, '01', 01, 1), (5, '+01', +01, 1);
|
||||
INSERT INTO t_leading_zeroes VALUES (6, '-01', -01, -1), (7, '0001', 0001, 1), (8, '0005', 0005, 5), (9, '0008', 0008, 8);
|
||||
INSERT INTO t_leading_zeroes VALUES (10, '0017', 0017, 17), (11, '0021', 0021, 21), (12, '0051', 0051, 51), (13, '00000123', 00000123, 123);
|
||||
INSERT INTO t_leading_zeroes VALUES (14, '0b10000', 0b10000, 16), (15, '0x0abcd', 0x0abcd, 43981), (16, '0000.008', 0000.008, 0)
|
||||
INSERT INTO t_leading_zeroes VALUES (17, '1000.0008', 1000.0008, 1000), (18, '0008.0008', 0008.0008, 8);
|
||||
|
||||
SELECT 'Leading zeroes into INTEGER';
|
||||
SELECT t.val == t.expected AS ok, * FROM t_leading_zeroes t ORDER BY id;
|
||||
|
||||
-- Floats don't go via the weird octal path:
|
||||
CREATE TABLE t_leading_zeroes_f(id INTEGER, input String, val Float32, expected Float32) ENGINE=MergeTree ORDER BY id;
|
||||
INSERT INTO t_leading_zeroes_f VALUES (1, '00000', 00000, 0), (2, '00009.00009', 00009.00009, 9.00009), (3, '00009e9', 00009e9, 9e9), (4, '00009e09', 00009e09, 9e9), (5, '00009e0009', 00009e0009, 9e9);
|
||||
INSERT INTO t_leading_zeroes_f VALUES (6, '-00000', -00000.1, -0.1), (7, '-00009.00009', -00009.00009, -9.00009), (8, '-00009e9', -00009e9, -9e9), (9, '-00009e09', -00009e09, -9e9), (10, '-00009e0009', -00009e0009, -9e9);
|
||||
INSERT INTO t_leading_zeroes_f VALUES (11, '+00000', +00000., 0), (12, '+00009.00009', +00009.00009, 9.00009), (13, '+00009e9', +00009e9, 9e9), (14, '+00009e09', +00009e09, 9e9), (15, '+00009e0009', +00009e0009, 9e9);
|
||||
-- Coincidentally, the following result in 9 rather than 9e9 because of readFloatTextFastImpl
|
||||
-- using readUIntTextUpToNSignificantDigits<4>(exponent, in)
|
||||
-- INSERT INTO t_leading_zeroes_f VALUES (100, '00009e00009', 00009e00009, 9e9), (101, '-00009e00009', -00009e00009, -9e9), (102, '+00009e00009', +00009e00009, 9e9)
|
||||
|
||||
SELECT 'Leading zeroes into Float32';
|
||||
SELECT t.val == t.expected AS ok, * FROM t_leading_zeroes_f t ORDER BY id;
|
||||
|
||||
DROP TABLE IF EXISTS t_leading_zeroes;
|
||||
DROP TABLE IF EXISTS t_leading_zeroes_f;
|
Loading…
Reference in New Issue
Block a user