mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-28 02:21:59 +00:00
refine
This commit is contained in:
parent
ca6930eb11
commit
7f1ee68c87
@ -734,11 +734,11 @@ struct ToYearImpl
|
||||
|
||||
const DateLUTImpl & date_lut = DateLUT::instance();
|
||||
|
||||
auto start_time = date_lut.makeDateTime(year, 1, 1, 0, 0, 0);
|
||||
auto start_time = date_lut.makeDayNum(year, 1, 1);
|
||||
auto end_time = date_lut.addYears(start_time, 1);
|
||||
|
||||
if (isDateOrDate32(type) || isDateTime(type) || isDateTime64(type))
|
||||
return {std::make_pair(Field(start_time), Field(end_time))};
|
||||
return {std::make_pair(Field(Int32(start_time)), Field(Int32(end_time)))};
|
||||
else
|
||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
||||
"Illegal type {} of argument of function {}. Should be Date, Date32, DateTime or DateTime64",
|
||||
@ -1412,11 +1412,11 @@ struct ToYYYYMMImpl
|
||||
|
||||
const DateLUTImpl & date_lut = DateLUT::instance();
|
||||
|
||||
auto start_time = date_lut.makeDateTime(year, month, 1, 0, 0, 0);
|
||||
auto start_time = date_lut.makeDayNum(year, month, 1);
|
||||
auto end_time = date_lut.addMonths(start_time, 1);
|
||||
|
||||
if (isDateOrDate32(type) || isDateTime(type) || isDateTime64(type))
|
||||
return {std::make_pair(Field(start_time), Field(end_time))};
|
||||
return {std::make_pair(Field(Int32(start_time)), Field(Int32(end_time)))};
|
||||
else
|
||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
|
||||
"Illegal type {} of argument of function {}. Should be Date, Date32, DateTime or DateTime64",
|
||||
|
@ -11,6 +11,10 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if USE_EMBEDDED_COMPILER
|
||||
# include <Core/ValuesWithType.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
|
||||
/// This file contains user interface for functions.
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <Core/NamesAndTypes.h>
|
||||
#include <Common/DateLUT.h>
|
||||
#include <Common/DateLUTImpl.h>
|
||||
#include "base/DayNum.h"
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Interpreters/IdentifierSemantic.h>
|
||||
#include <Parsers/ASTIdentifier.h>
|
||||
@ -37,20 +38,18 @@ ASTPtr generateOptimizedDateFilterAST(const String & comparator, const NameAndTy
|
||||
const DateLUTImpl & date_lut = DateLUT::instance();
|
||||
|
||||
const String & column_name = column.name;
|
||||
String start_date_or_date_time;
|
||||
String end_date_or_date_time;
|
||||
|
||||
if (isDateOrDate32(column.type.get()))
|
||||
auto start_date = range.first.get<Int64>();
|
||||
auto end_date = range.second.get<Int64>();
|
||||
String start_date_or_date_time = date_lut.dateToString(ExtendedDayNum(static_cast<Int32>(start_date)));
|
||||
String end_date_or_date_time = date_lut.dateToString(ExtendedDayNum(static_cast<Int32>(end_date)));
|
||||
|
||||
if (isDateTime(column.type.get()) || isDateTime64(column.type.get()))
|
||||
{
|
||||
start_date_or_date_time = date_lut.dateToString(range.first.get<DateLUTImpl::Time>());
|
||||
end_date_or_date_time = date_lut.dateToString(range.second.get<DateLUTImpl::Time>());
|
||||
start_date_or_date_time += " 00:00:00";
|
||||
end_date_or_date_time += " 00:00:00";
|
||||
}
|
||||
else if (isDateTime(column.type.get()) || isDateTime64(column.type.get()))
|
||||
{
|
||||
start_date_or_date_time = date_lut.timeToString(range.first.get<DateLUTImpl::Time>());
|
||||
end_date_or_date_time = date_lut.timeToString(range.second.get<DateLUTImpl::Time>());
|
||||
}
|
||||
else [[unlikely]] return {};
|
||||
else if (!isDateOrDate32(column.type.get())) return {};
|
||||
|
||||
if (comparator == "equals")
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user