From 7a4a65bc36eddabf1931878236fba3861e6c522a Mon Sep 17 00:00:00 2001 From: Kruglov Pavel <48961922+Avogar@users.noreply.github.com> Date: Thu, 1 Sep 2022 20:36:08 +0200 Subject: [PATCH 1/4] Make better exception message in schema inference --- src/Processors/Formats/ISchemaReader.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Processors/Formats/ISchemaReader.cpp b/src/Processors/Formats/ISchemaReader.cpp index c7d8b87ab77..34b4adf3b93 100644 --- a/src/Processors/Formats/ISchemaReader.cpp +++ b/src/Processors/Formats/ISchemaReader.cpp @@ -120,17 +120,20 @@ NamesAndTypesList IRowSchemaReader::readSchema() for (size_t i = 0; i != data_types.size(); ++i) column_names.push_back("c" + std::to_string(i + 1)); } - /// 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) + else if (!data_types.empty()) { - auto hint_it = hints.find(column_names[i]); - if (hint_it != hints.end()) - data_types[i] = hint_it->second; + /// If column names were set, check that the number of names match the number of types. + 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) + { + auto hint_it = hints.find(column_names[i]); + if (hint_it != hints.end()) + data_types[i] = hint_it->second; + } } for (rows_read = 1; rows_read < max_rows_to_read; ++rows_read) From 77071381e4c26d07a4f56419605e244bdb087667 Mon Sep 17 00:00:00 2001 From: Kruglov Pavel <48961922+Avogar@users.noreply.github.com> Date: Fri, 2 Sep 2022 16:37:33 +0200 Subject: [PATCH 2/4] fix build --- src/Processors/Formats/ISchemaReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Processors/Formats/ISchemaReader.cpp b/src/Processors/Formats/ISchemaReader.cpp index 34b4adf3b93..648b0f47365 100644 --- a/src/Processors/Formats/ISchemaReader.cpp +++ b/src/Processors/Formats/ISchemaReader.cpp @@ -123,7 +123,7 @@ NamesAndTypesList IRowSchemaReader::readSchema() else if (!data_types.empty()) { /// If column names were set, check that the number of names match the number of types. - if ((column_names.size() != data_types.size()) + 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()); From c33aa54032983b8050e8400c3b7f4914fa631ea9 Mon Sep 17 00:00:00 2001 From: Kruglov Pavel <48961922+Avogar@users.noreply.github.com> Date: Fri, 9 Sep 2022 17:53:26 +0200 Subject: [PATCH 3/4] Fix --- src/Processors/Formats/ISchemaReader.cpp | 34 ++++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Processors/Formats/ISchemaReader.cpp b/src/Processors/Formats/ISchemaReader.cpp index 648b0f47365..c418cbef41f 100644 --- a/src/Processors/Formats/ISchemaReader.cpp +++ b/src/Processors/Formats/ISchemaReader.cpp @@ -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()) { @@ -120,20 +125,19 @@ NamesAndTypesList IRowSchemaReader::readSchema() for (size_t i = 0; i != data_types.size(); ++i) column_names.push_back("c" + std::to_string(i + 1)); } - else if (!data_types.empty()) + /// If column names were set, check that the number of names match the number of types. + else if (column_names.size() != data_types.size()) { - /// If column names were set, check that the number of names match the number of types. - 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) - { - auto hint_it = hints.find(column_names[i]); - if (hint_it != hints.end()) - data_types[i] = hint_it->second; - } + 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) + { + auto hint_it = hints.find(column_names[i]); + if (hint_it != hints.end()) + data_types[i] = hint_it->second; } for (rows_read = 1; rows_read < max_rows_to_read; ++rows_read) @@ -158,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) { From 702ddff5f6914549087dde658bf1fc91829f1696 Mon Sep 17 00:00:00 2001 From: Kruglov Pavel <48961922+Avogar@users.noreply.github.com> Date: Mon, 12 Sep 2022 19:38:34 +0200 Subject: [PATCH 4/4] Fix style --- src/Processors/Formats/ISchemaReader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Processors/Formats/ISchemaReader.cpp b/src/Processors/Formats/ISchemaReader.cpp index c418cbef41f..9365384f4b7 100644 --- a/src/Processors/Formats/ISchemaReader.cpp +++ b/src/Processors/Formats/ISchemaReader.cpp @@ -113,7 +113,7 @@ 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"); @@ -132,7 +132,7 @@ NamesAndTypesList IRowSchemaReader::readSchema() 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) { auto hint_it = hints.find(column_names[i]);