Consume leading zeroes when parsing a number in ConstantExpressionTemplate

This commit is contained in:
Joanna Hulboj 2023-10-12 19:49:06 +01:00
parent 57df56733f
commit 7e3587034d
3 changed files with 27 additions and 0 deletions

View File

@ -597,6 +597,10 @@ bool ConstantExpressionTemplate::parseLiteralAndAssertType(
if (negative || *istr.position() == '+')
++istr.position();
/// Consume leading zeroes - we don't want any funny octal business
while (*istr.position() == '0')
++istr.position();
static constexpr size_t MAX_LENGTH_OF_NUMBER = 319;
char buf[MAX_LENGTH_OF_NUMBER + 1];
size_t bytes_to_copy = std::min(istr.available(), MAX_LENGTH_OF_NUMBER);

View File

@ -0,0 +1,15 @@
-0.02 0
0 0
0.01 0
0.02 1
0.03 1
0.04 -1
1 1
2 5
3 8
4 17
5 21
6 51
7 123
8 16
9 43981

View File

@ -0,0 +1,8 @@
DROP TABLE IF EXISTS t_leading_zeroes;
CREATE TABLE t_leading_zeroes(ref Float64, val INTEGER) ENGINE=MergeTree ORDER BY ref;
INSERT INTO t_leading_zeroes VALUES (-0.02, 00000), (0, 0), (0.01, 00), (0.02, 01), (0.03, +01), (0.04, -01), (1, 0001), (2, 0005), (3, 0008), (4, 0017), (5, 0021), (6, 0051), (7, 00000123), (8, 0b10000), (9, 0x0abcd);
SELECT * FROM t_leading_zeroes;
DROP TABLE IF EXISTS t_leading_zeroes;