Merge pull request #12306 from CurtizJ/fix-with-fill

Fix order of columns in WITH FILL modifier
This commit is contained in:
Anton Popov 2020-07-10 00:12:11 +03:00 committed by GitHub
commit c4767557f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 25 deletions

View File

@ -18,11 +18,7 @@ FillingTransform::FillingTransform(
, filling_row(sort_description_)
, next_row(sort_description_)
{
std::vector<bool> 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<bool> 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()

View File

@ -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

View File

@ -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;