From 7e3587034d17dd75838110bb3236816161bcd3f7 Mon Sep 17 00:00:00 2001 From: Joanna Hulboj Date: Thu, 12 Oct 2023 19:49:06 +0100 Subject: [PATCH] Consume leading zeroes when parsing a number in ConstantExpressionTemplate --- .../Formats/Impl/ConstantExpressionTemplate.cpp | 4 ++++ .../02896_leading_zeroes_no_octal.reference | 15 +++++++++++++++ .../0_stateless/02896_leading_zeroes_no_octal.sql | 8 ++++++++ 3 files changed, 27 insertions(+) create mode 100644 tests/queries/0_stateless/02896_leading_zeroes_no_octal.reference create mode 100644 tests/queries/0_stateless/02896_leading_zeroes_no_octal.sql diff --git a/src/Processors/Formats/Impl/ConstantExpressionTemplate.cpp b/src/Processors/Formats/Impl/ConstantExpressionTemplate.cpp index fe6fb42d0a0..c2b0ce3e486 100644 --- a/src/Processors/Formats/Impl/ConstantExpressionTemplate.cpp +++ b/src/Processors/Formats/Impl/ConstantExpressionTemplate.cpp @@ -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); diff --git a/tests/queries/0_stateless/02896_leading_zeroes_no_octal.reference b/tests/queries/0_stateless/02896_leading_zeroes_no_octal.reference new file mode 100644 index 00000000000..5982c315878 --- /dev/null +++ b/tests/queries/0_stateless/02896_leading_zeroes_no_octal.reference @@ -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 diff --git a/tests/queries/0_stateless/02896_leading_zeroes_no_octal.sql b/tests/queries/0_stateless/02896_leading_zeroes_no_octal.sql new file mode 100644 index 00000000000..fbb931b4c88 --- /dev/null +++ b/tests/queries/0_stateless/02896_leading_zeroes_no_octal.sql @@ -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;