Do not crash if the row template file is empty.

This commit is contained in:
Alexander Kuzmenkov 2020-01-22 21:26:16 +03:00
parent ba7ab32098
commit 55be790199
3 changed files with 11 additions and 16 deletions

View File

@ -16,20 +16,10 @@ namespace ErrorCodes
ParsedTemplateFormatString::ParsedTemplateFormatString(const FormatSchemaInfo & schema, const ColumnIdxGetter & idx_by_name) ParsedTemplateFormatString::ParsedTemplateFormatString(const FormatSchemaInfo & schema, const ColumnIdxGetter & idx_by_name)
{ {
try ReadBufferFromFile schema_file(schema.absoluteSchemaPath(), 4096);
{ String format_string;
ReadBufferFromFile schema_file(schema.absoluteSchemaPath(), 4096); readStringUntilEOF(format_string, schema_file);
String format_string; parse(format_string, idx_by_name);
readStringUntilEOF(format_string, schema_file);
parse(format_string, idx_by_name);
}
catch (DB::Exception & e)
{
if (e.code() != ErrorCodes::INVALID_TEMPLATE_FORMAT)
throwInvalidFormat(e.message(), columnsCount());
else
throw;
}
} }
@ -193,8 +183,11 @@ const char * ParsedTemplateFormatString::readMayBeQuotedColumnNameInto(const cha
String ParsedTemplateFormatString::dump() const String ParsedTemplateFormatString::dump() const
{ {
WriteBufferFromOwnString res; WriteBufferFromOwnString res;
res << "Delimiter " << 0 << ": "; res << "\nDelimiter " << 0 << ": ";
verbosePrintString(delimiters.front().c_str(), delimiters.front().c_str() + delimiters.front().size(), res); if (delimiters.size() <= 1)
res << "<ERROR>";
else
verbosePrintString(delimiters[0].c_str(), delimiters[0].c_str() + delimiters[0].size(), res);
size_t num_columns = std::max(formats.size(), format_idx_to_column_idx.size()); size_t num_columns = std::max(formats.size(), format_idx_to_column_idx.size());
for (size_t i = 0; i < num_columns; ++i) for (size_t i = 0; i < num_columns; ++i)

View File

@ -0,0 +1,2 @@
select 1 format Template settings format_template_row='01070_nonexistent_file.txt'; -- { clientError 107 }
select 1 format Template settings format_template_row='/dev/null'; -- { clientError 474 }