Merge pull request #40909 from ClickHouse/Avogar-patch-1

Make better exception message in schema inference
This commit is contained in:
Kruglov Pavel 2022-09-13 14:44:29 +02:00 committed by GitHub
commit 110be0688e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -113,6 +113,11 @@ NamesAndTypesList IRowSchemaReader::readSchema()
"Most likely setting input_format_max_rows_to_read_for_schema_inference is set to 0");
DataTypes data_types = readRowAndGetDataTypes();
/// Check that we read at list one column.
if (data_types.empty())
throw Exception(ErrorCodes::EMPTY_DATA_PASSED, "Cannot read rows from the data");
/// If column names weren't set, use default names 'c1', 'c2', ...
if (column_names.empty())
{
@ -122,9 +127,11 @@ NamesAndTypesList IRowSchemaReader::readSchema()
}
/// If column names were set, check that the number of names match the number of types.
else if (column_names.size() != data_types.size())
{
throw Exception(
ErrorCodes::INCORRECT_DATA,
"The number of column names {} differs with the number of types {}", column_names.size(), data_types.size());
}
for (size_t i = 0; i != column_names.size(); ++i)
{
@ -155,10 +162,6 @@ NamesAndTypesList IRowSchemaReader::readSchema()
}
}
/// Check that we read at list one column.
if (data_types.empty())
throw Exception(ErrorCodes::EMPTY_DATA_PASSED, "Cannot read rows from the data");
NamesAndTypesList result;
for (size_t i = 0; i != data_types.size(); ++i)
{