Fix segfault in formatRow function

This commit is contained in:
avogar 2021-11-02 16:26:14 +03:00
parent 901ebcede6
commit 62c5951dd7
3 changed files with 12 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include <IO/WriteBufferFromVector.h>
#include <IO/WriteHelpers.h>
#include <Processors/Formats/IOutputFormat.h>
#include <Processors/Formats/IRowOutputFormat.h>
#include <base/map.h>
@ -18,6 +19,7 @@ namespace ErrorCodes
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
extern const int UNKNOWN_FORMAT;
extern const int BAD_ARGUMENTS;
}
namespace
@ -70,6 +72,11 @@ public:
writeChar('\0', buffer);
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);
return col_str;
}

View File

@ -0,0 +1,5 @@
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 }