From 5fe4bcd22ef259314527df87f27047935b4a6835 Mon Sep 17 00:00:00 2001 From: Anton Popov Date: Sat, 30 Oct 2021 21:33:31 +0300 Subject: [PATCH] fix WITH FILL with set TO and FROM and no rows in result set --- .../Transforms/FillingTransform.cpp | 7 +++++-- .../02111_with_fill_no_rows.reference | 4 ++++ .../0_stateless/02111_with_fill_no_rows.sql | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 tests/queries/0_stateless/02111_with_fill_no_rows.reference create mode 100644 tests/queries/0_stateless/02111_with_fill_no_rows.sql diff --git a/src/Processors/Transforms/FillingTransform.cpp b/src/Processors/Transforms/FillingTransform.cpp index 3ff89c302ff..5fe051e9498 100644 --- a/src/Processors/Transforms/FillingTransform.cpp +++ b/src/Processors/Transforms/FillingTransform.cpp @@ -117,12 +117,12 @@ IProcessor::Status FillingTransform::prepare() { if (!on_totals && input.isFinished() && !output.isFinished() && !has_input && !generate_suffix) { - should_insert_first = next_row < filling_row; + should_insert_first = next_row < filling_row || first; for (size_t i = 0, size = filling_row.size(); i < size; ++i) next_row[i] = filling_row.getFillDescription(i).fill_to; - if (filling_row < next_row) + if (first || filling_row < next_row) { generate_suffix = true; return Status::Ready; @@ -160,6 +160,9 @@ void FillingTransform::transform(Chunk & chunk) init_columns_by_positions(empty_columns, old_fill_columns, res_fill_columns, fill_column_positions); init_columns_by_positions(empty_columns, old_other_columns, res_other_columns, other_column_positions); + if (first) + filling_row.initFromDefaults(); + if (should_insert_first && filling_row < next_row) insertFromFillingRow(res_fill_columns, res_other_columns, filling_row); diff --git a/tests/queries/0_stateless/02111_with_fill_no_rows.reference b/tests/queries/0_stateless/02111_with_fill_no_rows.reference new file mode 100644 index 00000000000..c0cc69a2d63 --- /dev/null +++ b/tests/queries/0_stateless/02111_with_fill_no_rows.reference @@ -0,0 +1,4 @@ +2019 0 +2020 0 +2021 0 +2022 0 diff --git a/tests/queries/0_stateless/02111_with_fill_no_rows.sql b/tests/queries/0_stateless/02111_with_fill_no_rows.sql new file mode 100644 index 00000000000..e671dd5f0f2 --- /dev/null +++ b/tests/queries/0_stateless/02111_with_fill_no_rows.sql @@ -0,0 +1,19 @@ +SELECT toYear(d) AS y, count() +FROM ( SELECT today() AS d WHERE 0) +GROUP BY y +ORDER BY y ASC WITH FILL FROM 2019 TO 2023; + +SELECT toYear(d) AS y, count() +FROM ( SELECT today() AS d WHERE 0) +GROUP BY y +ORDER BY y ASC WITH FILL FROM 2019; + +SELECT toYear(d) AS y, count() +FROM ( SELECT today() AS d WHERE 0) +GROUP BY y +ORDER BY y ASC WITH FILL TO 2023; + +SELECT toYear(d) AS y, count() +FROM ( SELECT today() AS d WHERE 0) +GROUP BY y +ORDER BY y ASC WITH FILL;