Merge pull request #31001 from Avogar/fix-format-row

Fix segfault in formatRow function
This commit is contained in:
Anton Popov 2021-11-03 00:58:56 +03:00 committed by GitHub
commit 0936d90210
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include <IO/WriteBufferFromVector.h> #include <IO/WriteBufferFromVector.h>
#include <IO/WriteHelpers.h> #include <IO/WriteHelpers.h>
#include <Processors/Formats/IOutputFormat.h> #include <Processors/Formats/IOutputFormat.h>
#include <Processors/Formats/IRowOutputFormat.h>
#include <base/map.h> #include <base/map.h>
@ -18,6 +19,7 @@ namespace ErrorCodes
extern const int ILLEGAL_TYPE_OF_ARGUMENT; extern const int ILLEGAL_TYPE_OF_ARGUMENT;
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
extern const int UNKNOWN_FORMAT; extern const int UNKNOWN_FORMAT;
extern const int BAD_ARGUMENTS;
} }
namespace namespace
@ -70,6 +72,11 @@ public:
writeChar('\0', buffer); writeChar('\0', buffer);
offsets[row] = buffer.count(); offsets[row] = buffer.count();
}); });
/// This function make sense only for row output formats.
if (!dynamic_cast<IRowOutputFormat *>(out.get()))
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Cannot turn rows into a {} format strings. {} function supports only row output formats", format_name, getName());
out->write(arg_columns); out->write(arg_columns);
return col_str; return col_str;
} }

View File

@ -0,0 +1,6 @@
-- Tags: no-fasttest
select formatRow('ORC', number, toDate(number)) from numbers(5); -- { serverError 36 }
select formatRow('Parquet', number, toDate(number)) from numbers(5); -- { serverError 36 }
select formatRow('Arrow', number, toDate(number)) from numbers(5); -- { serverError 36 }
select formatRow('Native', number, toDate(number)) from numbers(5); -- { serverError 36 }