@@ -18,11 +18,7 @@ FillingTransform::FillingTransform(
1818 , filling_row(sort_description_)
1919 , next_row(sort_description_)
2020{
21- std::vector<bool > is_fill_column (header_.columns ());
22- for (const auto & elem : sort_description)
23- is_fill_column[header_.getPositionByName (elem.column_name )] = true ;
24-
25- auto try_convert_fields = [](FillColumnDescription & descr, const DataTypePtr & type)
21+ auto try_convert_fields = [](auto & descr, const auto & type)
2622 {
2723 auto max_type = Field::Types::Null;
2824 WhichDataType which (type);
@@ -49,30 +45,32 @@ FillingTransform::FillingTransform(
4945 return true ;
5046 };
5147
52- for (size_t i = 0 ; i < header_.columns (); ++i)
48+ std::vector<bool > is_fill_column (header_.columns ());
49+ for (size_t i = 0 ; i < sort_description.size (); ++i)
5350 {
54- if (is_fill_column[i])
55- {
56- size_t pos = fill_column_positions.size ();
57- auto & descr = filling_row.getFillDescription (pos);
58- auto type = header_.getByPosition (i).type ;
59- if (!try_convert_fields (descr, type))
60- throw Exception (" Incompatible types of WITH FILL expression values with column type "
61- + type->getName (), ErrorCodes::INVALID_WITH_FILL_EXPRESSION);
62-
63- if (type->isValueRepresentedByUnsignedInteger () &&
64- ((!descr.fill_from .isNull () && less (descr.fill_from , Field{0 }, 1 )) ||
65- (!descr.fill_to .isNull () && less (descr.fill_to , Field{0 }, 1 ))))
66- {
67- throw Exception (" WITH FILL bound values cannot be negative for unsigned type "
68- + type->getName (), ErrorCodes::INVALID_WITH_FILL_EXPRESSION);
69- }
51+ size_t block_position = header_.getPositionByName (sort_description[i].column_name );
52+ is_fill_column[block_position] = true ;
53+ fill_column_positions.push_back (block_position);
7054
71- fill_column_positions.push_back (i);
55+ auto & descr = filling_row.getFillDescription (i);
56+ const auto & type = header_.getByPosition (block_position).type ;
57+
58+ if (!try_convert_fields (descr, type))
59+ throw Exception (" Incompatible types of WITH FILL expression values with column type "
60+ + type->getName (), ErrorCodes::INVALID_WITH_FILL_EXPRESSION);
61+
62+ if (type->isValueRepresentedByUnsignedInteger () &&
63+ ((!descr.fill_from .isNull () && less (descr.fill_from , Field{0 }, 1 )) ||
64+ (!descr.fill_to .isNull () && less (descr.fill_to , Field{0 }, 1 ))))
65+ {
66+ throw Exception (" WITH FILL bound values cannot be negative for unsigned type "
67+ + type->getName (), ErrorCodes::INVALID_WITH_FILL_EXPRESSION);
7268 }
73- else
74- other_column_positions.push_back (i);
7569 }
70+
71+ for (size_t i = 0 ; i < header_.columns (); ++i)
72+ if (!is_fill_column[i])
73+ other_column_positions.push_back (i);
7674}
7775
7876IProcessor::Status FillingTransform::prepare ()
0 commit comments