mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 09:32:01 +00:00
Merge pull request #12306 from CurtizJ/fix-with-fill
Fix order of columns in WITH FILL modifier
This commit is contained in:
commit
c4767557f2
@ -18,11 +18,7 @@ FillingTransform::FillingTransform(
|
|||||||
, filling_row(sort_description_)
|
, filling_row(sort_description_)
|
||||||
, next_row(sort_description_)
|
, next_row(sort_description_)
|
||||||
{
|
{
|
||||||
std::vector<bool> is_fill_column(header_.columns());
|
auto try_convert_fields = [](auto & descr, const auto & type)
|
||||||
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 max_type = Field::Types::Null;
|
auto max_type = Field::Types::Null;
|
||||||
WhichDataType which(type);
|
WhichDataType which(type);
|
||||||
@ -49,30 +45,32 @@ FillingTransform::FillingTransform(
|
|||||||
return true;
|
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();
|
throw Exception("WITH FILL bound values cannot be negative for unsigned type "
|
||||||
auto & descr = filling_row.getFillDescription(pos);
|
+ type->getName(), ErrorCodes::INVALID_WITH_FILL_EXPRESSION);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
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()
|
IProcessor::Status FillingTransform::prepare()
|
||||||
|
@ -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
|
@ -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;
|
Loading…
Reference in New Issue
Block a user