support for order by fill with DateTime64

This commit is contained in:
万康 2021-05-11 21:03:32 +08:00
parent d02d14fa00
commit 36fc6432ce
3 changed files with 30 additions and 1 deletions

View File

@ -1,6 +1,11 @@
#include <Processors/Transforms/FillingTransform.h>
#include <Interpreters/convertFieldToType.h>
#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/DataTypeDateTime64.h>
#include <DataTypes/IDataType.h>
#include <Core/Types.h>
#include <DataTypes/DataTypesDecimal.h>
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<DataTypeInt64>();
}
else if (which.isDateTime64())
{
max_type = Field::Types::Decimal64;
const auto & dateType = static_cast<const DataTypeDateTime64 &>(*type);
size_t precision = dateType.getPrecision();
size_t scale = dateType.getScale();
to_type = std::make_shared<DataTypeDecimal<Decimal64>>(precision, scale);
}
else if (which.isFloat())
{
max_type = Field::Types::Float64;

View File

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

View File

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