diff --git a/src/Processors/Transforms/FillingTransform.cpp b/src/Processors/Transforms/FillingTransform.cpp index 317453f272a..46b913aed7a 100644 --- a/src/Processors/Transforms/FillingTransform.cpp +++ b/src/Processors/Transforms/FillingTransform.cpp @@ -1,6 +1,11 @@ #include #include #include +#include +#include +#include +#include + namespace DB { @@ -38,11 +43,19 @@ FillingTransform::FillingTransform( DataTypePtr to_type; /// TODO Wrong results for big integers. - if (isInteger(type) || which.isDateOrDateTime()) + if (isInteger(type) || which.isDate() || which.isDateTime()) { max_type = Field::Types::Int64; to_type = std::make_shared(); } + else if (which.isDateTime64()) + { + max_type = Field::Types::Decimal64; + const auto & dateType = static_cast(*type); + size_t precision = dateType.getPrecision(); + size_t scale = dateType.getScale(); + to_type = std::make_shared>(precision, scale); + } else if (which.isFloat()) { max_type = Field::Types::Float64; diff --git a/tests/queries/0_stateless/01868_order_by_fill_with_datetime64.reference b/tests/queries/0_stateless/01868_order_by_fill_with_datetime64.reference new file mode 100644 index 00000000000..420ff36feb4 --- /dev/null +++ b/tests/queries/0_stateless/01868_order_by_fill_with_datetime64.reference @@ -0,0 +1,14 @@ +1970-01-01 08:16:40.000 original +1970-01-01 08:33:20.000 +1970-01-01 08:50:00.000 +1970-01-01 09:06:40.000 original +1970-01-01 09:23:20.000 +1970-01-01 09:40:00.000 +1970-01-01 09:56:40.000 original +1970-01-01 08:16:40.000000000 original +1970-01-01 08:33:20.000000000 +1970-01-01 08:50:00.000000000 +1970-01-01 09:06:40.000000000 original +1970-01-01 09:23:20.000000000 +1970-01-01 09:40:00.000000000 +1970-01-01 09:56:40.000000000 original diff --git a/tests/queries/0_stateless/01868_order_by_fill_with_datetime64.sql b/tests/queries/0_stateless/01868_order_by_fill_with_datetime64.sql new file mode 100644 index 00000000000..5425de8f3ee --- /dev/null +++ b/tests/queries/0_stateless/01868_order_by_fill_with_datetime64.sql @@ -0,0 +1,2 @@ +SELECT n, source FROM (SELECT toDateTime64(number * 1000, 3) AS n, 'original' AS source FROM numbers(10) WHERE (number % 3) = 1 ) ORDER BY n ASC WITH FILL STEP toDateTime64(1000, 3); +SELECT n, source FROM (SELECT toDateTime64(number * 1000, 9) AS n, 'original' AS source FROM numbers(10) WHERE (number % 3) = 1 ) ORDER BY n ASC WITH FILL STEP toDateTime64(1000, 9);