mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
fixed review
This commit is contained in:
parent
7444987218
commit
8cd4d35ead
@ -1,6 +1,8 @@
|
|||||||
#include <base/arithmeticOverflow.h>
|
#include <base/arithmeticOverflow.h>
|
||||||
|
#include "Common/IntervalKind.h"
|
||||||
#include <Common/Exception.h>
|
#include <Common/Exception.h>
|
||||||
#include <Common/DateLUTImpl.h>
|
#include <Common/DateLUTImpl.h>
|
||||||
|
#include "base/types.h"
|
||||||
#include <DataTypes/DataTypesDecimal.h>
|
#include <DataTypes/DataTypesDecimal.h>
|
||||||
#include <Functions/FunctionHelpers.h>
|
#include <Functions/FunctionHelpers.h>
|
||||||
#include <Columns/ColumnsDateTime.h>
|
#include <Columns/ColumnsDateTime.h>
|
||||||
@ -220,7 +222,7 @@ private:
|
|||||||
|
|
||||||
if (isDateTime64(time_column_type))
|
if (isDateTime64(time_column_type))
|
||||||
{
|
{
|
||||||
if (!isDateTime64(origin_column.type.get()) && origin_column.column != nullptr)
|
if (origin_column.column != nullptr && !isDateTime64(origin_column.type.get()))
|
||||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Datetime argument and origin argument for function {} must have the same type", getName());
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Datetime argument and origin argument for function {} must have the same type", getName());
|
||||||
|
|
||||||
const auto * time_column_vec = checkAndGetColumn<ColumnDateTime64>(time_column_col);
|
const auto * time_column_vec = checkAndGetColumn<ColumnDateTime64>(time_column_col);
|
||||||
@ -231,8 +233,7 @@ private:
|
|||||||
}
|
}
|
||||||
else if (isDateTime(time_column_type))
|
else if (isDateTime(time_column_type))
|
||||||
{
|
{
|
||||||
if (origin_column.column != nullptr)
|
if (origin_column.column != nullptr && !isDateTime(origin_column.type.get()))
|
||||||
if (!isDateTime(origin_column.type.get()))
|
|
||||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Datetime argument and origin argument for function {} must have the same type", getName());
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Datetime argument and origin argument for function {} must have the same type", getName());
|
||||||
|
|
||||||
const auto * time_column_vec = checkAndGetColumn<ColumnDateTime>(time_column_col);
|
const auto * time_column_vec = checkAndGetColumn<ColumnDateTime>(time_column_col);
|
||||||
@ -241,8 +242,7 @@ private:
|
|||||||
}
|
}
|
||||||
else if (isDate(time_column_type))
|
else if (isDate(time_column_type))
|
||||||
{
|
{
|
||||||
if (origin_column.column != nullptr)
|
if (origin_column.column != nullptr && !isDate(origin_column.type.get()))
|
||||||
if (!isDate(origin_column.type.get()))
|
|
||||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Datetime argument and origin argument for function {} must have the same type", getName());
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Datetime argument and origin argument for function {} must have the same type", getName());
|
||||||
|
|
||||||
const auto * time_column_vec = checkAndGetColumn<ColumnDate>(time_column_col);
|
const auto * time_column_vec = checkAndGetColumn<ColumnDate>(time_column_col);
|
||||||
@ -330,19 +330,23 @@ private:
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
UInt64 origin = origin_column.column->get64(0);
|
UInt64 origin = origin_column.column->get64(0);
|
||||||
std::cerr << "origin: " << origin << std::endl;
|
|
||||||
std::cerr << "scale_multiplier: " << scale_multiplier << std::endl;
|
|
||||||
|
|
||||||
for (size_t i = 0; i != size; ++i)
|
for (size_t i = 0; i != size; ++i)
|
||||||
{
|
{
|
||||||
auto td = time_data[i];
|
auto td = time_data[i];
|
||||||
|
result_data[i] = 0;
|
||||||
if (origin > size_t(td))
|
if (origin > size_t(td))
|
||||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "The origin must be before the end date/datetime");
|
throw Exception(ErrorCodes::BAD_ARGUMENTS, "The origin must be before the end date/datetime");
|
||||||
|
|
||||||
td -= origin;
|
td -= origin;
|
||||||
result_data[i] = static_cast<ToFieldType>(ToStartOfInterval<unit>::execute(td, num_units, time_zone, scale_multiplier));
|
auto res = static_cast<ToFieldType>(ToStartOfInterval<unit>::execute(td, num_units, time_zone, scale_multiplier));
|
||||||
|
|
||||||
if (!(unit == IntervalKind::Millisecond || unit == IntervalKind::Microsecond || unit == IntervalKind::Nanosecond) && scale_multiplier != 10)
|
if (!(unit == IntervalKind::Millisecond || unit == IntervalKind::Microsecond || unit == IntervalKind::Nanosecond) && scale_multiplier != 10)
|
||||||
origin = origin / scale_multiplier;
|
origin = origin / scale_multiplier;
|
||||||
result_data[i] += origin;
|
if (unit == IntervalKind::Week || unit == IntervalKind::Month || unit == IntervalKind::Quarter || unit == IntervalKind::Year)
|
||||||
|
result_data[i] = UInt16(origin/86400 + res);
|
||||||
|
else
|
||||||
|
result_data[i] += origin + res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,15 +1,34 @@
|
|||||||
|
2023-01-02 14:45:50.917120700
|
||||||
|
2023-01-02 14:45:50.910600
|
||||||
|
2023-01-02 14:45:50.901
|
||||||
|
2023-01-02 14:45:50
|
||||||
|
2023-01-02 14:45:30
|
||||||
|
2023-01-02 14:44:30
|
||||||
|
2023-01-02 14:44:30
|
||||||
|
2023-01-06
|
||||||
|
2023-03-02
|
||||||
|
2023-07-02
|
||||||
|
2022-01-02
|
||||||
|
2023-01-02 15:45:50.917120700
|
||||||
|
2023-01-02 15:45:50.910600
|
||||||
|
2023-01-02 15:45:50.901
|
||||||
|
2023-01-02 15:45:50
|
||||||
|
2023-01-02 15:45:30
|
||||||
|
2023-01-02 15:44:30
|
||||||
|
2023-01-03 14:44:30
|
||||||
|
2023-01-06
|
||||||
|
2023-03-02
|
||||||
|
2023-07-02
|
||||||
|
2022-01-02
|
||||||
2023-03-01 16:55:00
|
2023-03-01 16:55:00
|
||||||
2023-02-01 16:55:00
|
2023-02-01 16:54:33
|
||||||
2023-03-01 16:55:00
|
2023-03-01 16:54:38
|
||||||
2023-02-01 16:55:00
|
2023-02-01 16:54:52
|
||||||
2023-03-01 16:55:00
|
2023-03-01 16:54:16
|
||||||
2023-03-01 16:55:00
|
2023-03-01 16:55:00
|
||||||
2023-02-01 16:55:00
|
2023-02-01 16:55:00
|
||||||
2023-03-01 16:55:00
|
2023-03-01 16:55:00
|
||||||
2023-02-01 16:55:00
|
2023-02-01 16:55:00
|
||||||
2023-03-01 16:55:00
|
2023-03-01 16:55:00
|
||||||
2023-01-02 15:44:30
|
2023-01-02 15:44:30
|
||||||
2023-01-02 15:44:30
|
2023-02-01 16:44:30
|
||||||
2023-01-02 14:45:30
|
|
||||||
2023-01-02 14:45:30
|
|
||||||
2023-01-02
|
|
||||||
|
@ -7,10 +7,10 @@ SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalSecond(2),
|
|||||||
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalMinute(1), toDateTime('2023-01-02 14:44:30'));
|
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalMinute(1), toDateTime('2023-01-02 14:44:30'));
|
||||||
SELECT toStartOfInterval(toDateTime64('2023-01-02 14:45:50', 2), toIntervalHour(1), toDateTime64('2023-01-02 14:44:30', 2));
|
SELECT toStartOfInterval(toDateTime64('2023-01-02 14:45:50', 2), toIntervalHour(1), toDateTime64('2023-01-02 14:44:30', 2));
|
||||||
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalDay(1), toDateTime('2023-01-02 14:44:30'));
|
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalDay(1), toDateTime('2023-01-02 14:44:30'));
|
||||||
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalWeek(1), toDateTime('2023-01-02 14:44:30'));
|
SELECT toStartOfInterval(toDateTime('2023-01-08 14:45:50'), toIntervalWeek(1), toDateTime('2023-01-02 14:44:30'));
|
||||||
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalMonth(1), toDateTime('2022-01-02 14:44:30'));
|
SELECT toStartOfInterval(toDateTime('2023-03-03 14:45:50'), toIntervalMonth(1), toDateTime('2022-01-02 14:44:30'));
|
||||||
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalQuarter(1), toDateTime('2022-01-02 14:44:30'));
|
SELECT toStartOfInterval(toDateTime('2023-08-02 14:45:50'), toIntervalQuarter(1), toDateTime('2022-01-02 14:44:30'));
|
||||||
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalYear(1), toDateTime('2020-01-02 14:44:30'));
|
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalYear(1), toDateTime('2020-01-03 14:44:30'));
|
||||||
|
|
||||||
SELECT toStartOfInterval(toDateTime64('2023-01-02 14:45:50.917122341', 9), toIntervalNanosecond(10000), toDateTime64('2023-01-02 14:44:30.500600700', 9), 'Europe/Amsterdam');
|
SELECT toStartOfInterval(toDateTime64('2023-01-02 14:45:50.917122341', 9), toIntervalNanosecond(10000), toDateTime64('2023-01-02 14:44:30.500600700', 9), 'Europe/Amsterdam');
|
||||||
SELECT toStartOfInterval(toDateTime64('2023-01-02 14:45:50.917122', 6), toIntervalMicrosecond(10000), toDateTime64('2023-01-02 14:44:30.500600', 6), 'Europe/Amsterdam');
|
SELECT toStartOfInterval(toDateTime64('2023-01-02 14:45:50.917122', 6), toIntervalMicrosecond(10000), toDateTime64('2023-01-02 14:44:30.500600', 6), 'Europe/Amsterdam');
|
||||||
@ -19,15 +19,15 @@ SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalSecond(2),
|
|||||||
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalMinute(1), toDateTime('2023-01-02 14:44:30'), 'Europe/Amsterdam');
|
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalMinute(1), toDateTime('2023-01-02 14:44:30'), 'Europe/Amsterdam');
|
||||||
SELECT toStartOfInterval(toDateTime64('2023-01-02 14:45:50', 2), toIntervalHour(1), toDateTime64('2023-01-02 14:44:30', 2), 'Europe/Amsterdam');
|
SELECT toStartOfInterval(toDateTime64('2023-01-02 14:45:50', 2), toIntervalHour(1), toDateTime64('2023-01-02 14:44:30', 2), 'Europe/Amsterdam');
|
||||||
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalDay(1), toDateTime('2023-01-02 14:44:30'), 'Europe/Amsterdam');
|
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalDay(1), toDateTime('2023-01-02 14:44:30'), 'Europe/Amsterdam');
|
||||||
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalWeek(1), toDateTime('2023-01-02 14:44:30'), 'Europe/Amsterdam');
|
SELECT toStartOfInterval(toDateTime('2023-01-08 14:45:50'), toIntervalWeek(1), toDateTime('2023-01-02 14:44:30'), 'Europe/Amsterdam');
|
||||||
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalMonth(1), toDateTime('2022-01-02 14:44:30'), 'Europe/Amsterdam');
|
SELECT toStartOfInterval(toDateTime('2023-03-03 14:45:50'), toIntervalMonth(1), toDateTime('2022-01-02 14:44:30'), 'Europe/Amsterdam');
|
||||||
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalQuarter(1), toDateTime('2022-01-02 14:44:30'), 'Europe/Amsterdam');
|
SELECT toStartOfInterval(toDateTime('2023-08-02 14:45:50'), toIntervalQuarter(1), toDateTime('2022-01-02 14:44:30'), 'Europe/Amsterdam');
|
||||||
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalYear(1), toDateTime('2020-01-02 14:44:30'), 'Europe/Amsterdam');
|
SELECT toStartOfInterval(toDateTime('2023-01-02 14:45:50'), toIntervalYear(1), toDateTime('2020-01-03 14:44:30'), 'Europe/Amsterdam');
|
||||||
|
|
||||||
SELECT toStartOfInterval(number % 2 == 0 ? toDateTime64('2023-03-01 15:55:00', 2) : toDateTime64('2023-02-01 15:55:00', 2), toIntervalMinute(1), toDateTime64('2023-01-01 13:55:00', 2), 'Europe/Amsterdam') from numbers(5);
|
SELECT toStartOfInterval(number % 2 == 0 ? toDateTime64('2023-03-01 15:55:00', 2) : toDateTime64('2023-02-01 15:55:00', 2), toIntervalMinute(1), toDateTime64('2023-01-01 13:55:00', 2), 'Europe/Amsterdam') from numbers(5);
|
||||||
SELECT toStartOfInterval(number % 2 == 0 ? toDateTime('2023-03-01 15:55:00') : toDateTime('2023-02-01 15:55:00'), toIntervalHour(1), toDateTime('2023-01-01 13:55:00'), 'Europe/Amsterdam') from numbers(5);
|
SELECT toStartOfInterval(number % 2 == 0 ? toDateTime('2023-03-01 15:55:00') : toDateTime('2023-02-01 15:55:00'), toIntervalHour(1), toDateTime('2023-01-01 13:55:00'), 'Europe/Amsterdam') from numbers(5);
|
||||||
SELECT toStartOfInterval(materialize(toDateTime('2023-01-02 14:45:50')), toIntervalHour(1), toDateTime('2023-01-02 14:44:30'), 'Europe/Amsterdam');
|
SELECT toStartOfInterval(materialize(toDateTime('2023-01-02 14:45:50')), toIntervalHour(1), toDateTime('2023-01-02 14:44:30'), 'Europe/Amsterdam');
|
||||||
SELECT toStartOfInterval(materialize(toDateTime64('2023-02-01 15:45:50', 2)), toIntervalHour(1), toDateTime('2023-01-02 14:44:30'), 'Europe/Amsterdam');
|
SELECT toStartOfInterval(materialize(toDateTime64('2023-02-01 15:45:50', 2)), toIntervalHour(1), toDateTime64('2023-01-02 14:44:30', 2), 'Europe/Amsterdam');
|
||||||
|
|
||||||
SELECT toStartOfInterval(toDate('2023-01-02 14:45:50'), toIntervalSecond(5), toDate32('2023-01-02 14:44:30')); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
SELECT toStartOfInterval(toDate('2023-01-02 14:45:50'), toIntervalSecond(5), toDate32('2023-01-02 14:44:30')); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
||||||
SELECT toStartOfInterval(toDate('2023-01-02 14:45:50'), toIntervalMillisecond(12), toDateTime('2023-01-02 14:44:30')); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
SELECT toStartOfInterval(toDate('2023-01-02 14:45:50'), toIntervalMillisecond(12), toDateTime('2023-01-02 14:44:30')); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
|
||||||
|
Loading…
Reference in New Issue
Block a user