Skip to content

Commit c476755

Browse files
authored
Merge pull request #12306 from CurtizJ/fix-with-fill
Fix order of columns in WITH FILL modifier
2 parents 7af916e + 1122d99 commit c476755

3 files changed

Lines changed: 65 additions & 25 deletions

File tree

src/Processors/Transforms/FillingTransform.cpp

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

7876
IProcessor::Status FillingTransform::prepare()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
1970-01-11 1970-01-02 original
2+
0000-00-00 1970-01-03
3+
0000-00-00 1970-01-04
4+
1970-02-10 1970-01-05 original
5+
0000-00-00 1970-01-06
6+
0000-00-00 1970-01-07
7+
1970-03-12 1970-01-08 original
8+
===============
9+
1970-01-11 1970-01-02 original
10+
1970-01-16 0000-00-00
11+
1970-01-21 0000-00-00
12+
1970-01-26 0000-00-00
13+
1970-01-31 0000-00-00
14+
1970-02-05 0000-00-00
15+
1970-02-10 1970-01-05 original
16+
1970-02-15 0000-00-00
17+
1970-02-20 0000-00-00
18+
1970-02-25 0000-00-00
19+
1970-03-02 0000-00-00
20+
1970-03-07 0000-00-00
21+
1970-03-12 1970-01-08 original
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
SELECT
2+
toDate((number * 10) * 86400) AS d1,
3+
toDate(number * 86400) AS d2,
4+
'original' AS source
5+
FROM numbers(10)
6+
WHERE (number % 3) = 1
7+
ORDER BY
8+
d2 WITH FILL,
9+
d1 WITH FILL STEP 5;
10+
11+
SELECT '===============';
12+
13+
SELECT
14+
toDate((number * 10) * 86400) AS d1,
15+
toDate(number * 86400) AS d2,
16+
'original' AS source
17+
FROM numbers(10)
18+
WHERE (number % 3) = 1
19+
ORDER BY
20+
d1 WITH FILL STEP 5,
21+
d2 WITH FILL;

0 commit comments

Comments
 (0)