diff --git a/src/Processors/Transforms/FillingTransform.cpp b/src/Processors/Transforms/FillingTransform.cpp index e8d56389eac..292b86a1446 100644 --- a/src/Processors/Transforms/FillingTransform.cpp +++ b/src/Processors/Transforms/FillingTransform.cpp @@ -18,11 +18,7 @@ FillingTransform::FillingTransform( , filling_row(sort_description_) , next_row(sort_description_) { - std::vector is_fill_column(header_.columns()); - for (const auto & elem : sort_description) - is_fill_column[header_.getPositionByName(elem.column_name)] = true; - - auto try_convert_fields = [](FillColumnDescription & descr, const DataTypePtr & type) + auto try_convert_fields = [](auto & descr, const auto & type) { auto max_type = Field::Types::Null; WhichDataType which(type); @@ -49,30 +45,32 @@ FillingTransform::FillingTransform( return true; }; - for (size_t i = 0; i < header_.columns(); ++i) + std::vector is_fill_column(header_.columns()); + for (size_t i = 0; i < sort_description.size(); ++i) { - if (is_fill_column[i]) + size_t block_position = header_.getPositionByName(sort_description[i].column_name); + is_fill_column[block_position] = true; + fill_column_positions.push_back(block_position); + + auto & descr = filling_row.getFillDescription(i); + const auto & type = header_.getByPosition(block_position).type; + + if (!try_convert_fields(descr, type)) + throw Exception("Incompatible types of WITH FILL expression values with column type " + + type->getName(), ErrorCodes::INVALID_WITH_FILL_EXPRESSION); + + if (type->isValueRepresentedByUnsignedInteger() && + ((!descr.fill_from.isNull() && less(descr.fill_from, Field{0}, 1)) || + (!descr.fill_to.isNull() && less(descr.fill_to, Field{0}, 1)))) { - size_t pos = fill_column_positions.size(); - auto & descr = filling_row.getFillDescription(pos); - auto type = header_.getByPosition(i).type; - if (!try_convert_fields(descr, type)) - throw Exception("Incompatible types of WITH FILL expression values with column type " - + type->getName(), ErrorCodes::INVALID_WITH_FILL_EXPRESSION); - - if (type->isValueRepresentedByUnsignedInteger() && - ((!descr.fill_from.isNull() && less(descr.fill_from, Field{0}, 1)) || - (!descr.fill_to.isNull() && less(descr.fill_to, Field{0}, 1)))) - { - throw Exception("WITH FILL bound values cannot be negative for unsigned type " - + type->getName(), ErrorCodes::INVALID_WITH_FILL_EXPRESSION); - } - - fill_column_positions.push_back(i); + throw Exception("WITH FILL bound values cannot be negative for unsigned type " + + type->getName(), ErrorCodes::INVALID_WITH_FILL_EXPRESSION); } - else - other_column_positions.push_back(i); } + + for (size_t i = 0; i < header_.columns(); ++i) + if (!is_fill_column[i]) + other_column_positions.push_back(i); } IProcessor::Status FillingTransform::prepare() diff --git a/tests/queries/0_stateless/01379_with_fill_several_columns.reference b/tests/queries/0_stateless/01379_with_fill_several_columns.reference new file mode 100644 index 00000000000..f3362a47aab --- /dev/null +++ b/tests/queries/0_stateless/01379_with_fill_several_columns.reference @@ -0,0 +1,21 @@ +1970-01-11 1970-01-02 original +0000-00-00 1970-01-03 +0000-00-00 1970-01-04 +1970-02-10 1970-01-05 original +0000-00-00 1970-01-06 +0000-00-00 1970-01-07 +1970-03-12 1970-01-08 original +=============== +1970-01-11 1970-01-02 original +1970-01-16 0000-00-00 +1970-01-21 0000-00-00 +1970-01-26 0000-00-00 +1970-01-31 0000-00-00 +1970-02-05 0000-00-00 +1970-02-10 1970-01-05 original +1970-02-15 0000-00-00 +1970-02-20 0000-00-00 +1970-02-25 0000-00-00 +1970-03-02 0000-00-00 +1970-03-07 0000-00-00 +1970-03-12 1970-01-08 original diff --git a/tests/queries/0_stateless/01379_with_fill_several_columns.sql b/tests/queries/0_stateless/01379_with_fill_several_columns.sql new file mode 100644 index 00000000000..5d1cb4e6828 --- /dev/null +++ b/tests/queries/0_stateless/01379_with_fill_several_columns.sql @@ -0,0 +1,21 @@ +SELECT + toDate((number * 10) * 86400) AS d1, + toDate(number * 86400) AS d2, + 'original' AS source +FROM numbers(10) +WHERE (number % 3) = 1 +ORDER BY + d2 WITH FILL, + d1 WITH FILL STEP 5; + +SELECT '==============='; + +SELECT + toDate((number * 10) * 86400) AS d1, + toDate(number * 86400) AS d2, + 'original' AS source +FROM numbers(10) +WHERE (number % 3) = 1 +ORDER BY + d1 WITH FILL STEP 5, + d2 WITH FILL; \ No newline at end of file