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

Throw exception when parsing illegal string as float if precise_float_parsing is true #55861

Merged
merged 6 commits into from Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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: 3 additions & 3 deletions src/IO/readFloatText.h
Expand Up @@ -148,11 +148,11 @@ ReturnType readFloatTextPreciseImpl(T & x, ReadBuffer & buf)
static_assert('a' > '.' && 'A' > '.' && '\n' < '.' && '\t' < '.' && '\'' < '.' && '"' < '.', "Layout of char is not like ASCII");

static constexpr bool throw_exception = std::is_same_v<ReturnType, void>;

/// Fast path (avoid copying) if the buffer have at least MAX_LENGTH bytes.
static constexpr int MAX_LENGTH = 316;
ReadBufferFromMemory * buf_from_memory = dynamic_cast<ReadBufferFromMemory *>(&buf);

if (likely(!buf.eof() && buf.position() + MAX_LENGTH <= buf.buffer().end()))
/// Fast path (avoid copying) if the buffer have at least MAX_LENGTH bytes or buf is ReadBufferFromMemory
if (likely(!buf.eof() && (buf_from_memory || buf.position() + MAX_LENGTH <= buf.buffer().end())))
taiyang-li marked this conversation as resolved.
Show resolved Hide resolved
{
auto * initial_position = buf.position();
auto res = fast_float::from_chars(initial_position, buf.buffer().end(), x);
Expand Down
4 changes: 4 additions & 0 deletions tests/queries/0_stateless/02900_issue_55858.reference
@@ -0,0 +1,4 @@
0
0
\N
\N
10 changes: 10 additions & 0 deletions tests/queries/0_stateless/02900_issue_55858.sql
@@ -0,0 +1,10 @@
set precise_float_parsing = 1;

select cast('2023-01-01' as Float64); -- { serverError 6 }
taiyang-li marked this conversation as resolved.
Show resolved Hide resolved
select cast('2023-01-01' as Float32); -- { serverError 6 }
select toFloat32('2023-01-01'); -- { serverError 6 }
select toFloat64('2023-01-01'); -- { serverError 6 }
select toFloat32OrZero('2023-01-01');
select toFloat64OrZero('2023-01-01');
select toFloat32OrNull('2023-01-01');
select toFloat64OrNull('2023-01-01');