[improvement](function) improve date_trunc function performance when timeunit is const (#25824)

this PR #22602 have check function.
only support date_trunc(column, const), so the second must be const literal
and no need to check time unit every row.
This commit is contained in:
zhangstar333
2023-10-26 09:51:21 +08:00
committed by GitHub
parent 77f727e0a1
commit da4de17d5c
3 changed files with 142 additions and 96 deletions

View File

@ -1475,40 +1475,82 @@ TEST(VTimestampFunctionsTest, dayname_test) {
TEST(VTimestampFunctionsTest, datetrunc_test) {
std::string func_name = "date_trunc";
{
InputTypeSet input_types = {TypeIndex::DateTime, TypeIndex::String};
InputTypeSet input_types = {TypeIndex::DateTime, Consted {TypeIndex::String}};
DataSet data_set = {{{std::string("2022-10-08 11:44:23"), std::string("second")},
str_to_date_time("2022-10-08 11:44:23")},
{{std::string("2022-10-08 11:44:23"), std::string("minute")},
str_to_date_time("2022-10-08 11:44:00")},
{{std::string("2022-10-08 11:44:23"), std::string("hour")},
str_to_date_time("2022-10-08 11:00:00")},
{{std::string("2022-10-08 11:44:23"), std::string("day")},
str_to_date_time("2022-10-08 00:00:00")},
{{std::string("2022-10-08 11:44:23"), std::string("month")},
str_to_date_time("2022-10-01 00:00:00")},
{{std::string("2022-10-08 11:44:23"), std::string("year")},
str_to_date_time("2022-10-08 11:44:23")}};
static_cast<void>(check_function<DataTypeDateTime, true>(func_name, input_types, data_set));
}
{
InputTypeSet input_types = {TypeIndex::DateTime, Consted {TypeIndex::String}};
DataSet data_set = {{{std::string("2022-10-08 11:44:23"), std::string("minute")},
str_to_date_time("2022-10-08 11:44:00")}};
static_cast<void>(check_function<DataTypeDateTime, true>(func_name, input_types, data_set));
}
{
InputTypeSet input_types = {TypeIndex::DateTime, Consted {TypeIndex::String}};
DataSet data_set = {{{std::string("2022-10-08 11:44:23"), std::string("hour")},
str_to_date_time("2022-10-08 11:00:00")}};
static_cast<void>(check_function<DataTypeDateTime, true>(func_name, input_types, data_set));
}
{
InputTypeSet input_types = {TypeIndex::DateTime, Consted {TypeIndex::String}};
DataSet data_set = {{{std::string("2022-10-08 11:44:23"), std::string("day")},
str_to_date_time("2022-10-08 00:00:00")}};
static_cast<void>(check_function<DataTypeDateTime, true>(func_name, input_types, data_set));
}
{
InputTypeSet input_types = {TypeIndex::DateTime, Consted {TypeIndex::String}};
DataSet data_set = {{{std::string("2022-10-08 11:44:23"), std::string("month")},
str_to_date_time("2022-10-01 00:00:00")}};
static_cast<void>(check_function<DataTypeDateTime, true>(func_name, input_types, data_set));
}
{
InputTypeSet input_types = {TypeIndex::DateTime, Consted {TypeIndex::String}};
DataSet data_set = {{{std::string("2022-10-08 11:44:23"), std::string("year")},
str_to_date_time("2022-01-01 00:00:00")}};
static_cast<void>(check_function<DataTypeDateTime, true>(func_name, input_types, data_set));
}
{
InputTypeSet input_types = {TypeIndex::DateTimeV2, TypeIndex::String};
DataSet data_set = {{{std::string("2022-10-08 11:44:23.123"), std::string("second")},
str_to_datetime_v2("2022-10-08 11:44:23.000", "%Y-%m-%d %H:%i:%s.%f")},
{{std::string("2022-10-08 11:44:23"), std::string("minute")},
str_to_datetime_v2("2022-10-08 11:44:00", "%Y-%m-%d %H:%i:%s")},
{{std::string("2022-10-08 11:44:23"), std::string("hour")},
str_to_datetime_v2("2022-10-08 11:00:00", "%Y-%m-%d %H:%i:%s")},
{{std::string("2022-10-08 11:44:23"), std::string("day")},
str_to_datetime_v2("2022-10-08 00:00:00", "%Y-%m-%d %H:%i:%s")},
{{std::string("2022-10-08 11:44:23"), std::string("month")},
str_to_datetime_v2("2022-10-01 00:00:00", "%Y-%m-%d %H:%i:%s")},
{{std::string("2022-10-08 11:44:23"), std::string("year")},
InputTypeSet input_types = {TypeIndex::DateTimeV2, Consted {TypeIndex::String}};
DataSet data_set = {
{{std::string("2022-10-08 11:44:23.123"), std::string("second")},
str_to_datetime_v2("2022-10-08 11:44:23.000", "%Y-%m-%d %H:%i:%s.%f")}};
static_cast<void>(
check_function<DataTypeDateTimeV2, true>(func_name, input_types, data_set));
}
{
InputTypeSet input_types = {TypeIndex::DateTimeV2, Consted {TypeIndex::String}};
DataSet data_set = {{{std::string("2022-10-08 11:44:23"), std::string("minute")},
str_to_datetime_v2("2022-10-08 11:44:00", "%Y-%m-%d %H:%i:%s")}};
static_cast<void>(
check_function<DataTypeDateTimeV2, true>(func_name, input_types, data_set));
}
{
InputTypeSet input_types = {TypeIndex::DateTimeV2, Consted {TypeIndex::String}};
DataSet data_set = {{{std::string("2022-10-08 11:44:23"), std::string("hour")},
str_to_datetime_v2("2022-10-08 11:00:00", "%Y-%m-%d %H:%i:%s")}};
static_cast<void>(
check_function<DataTypeDateTimeV2, true>(func_name, input_types, data_set));
}
{
InputTypeSet input_types = {TypeIndex::DateTimeV2, Consted {TypeIndex::String}};
DataSet data_set = {{{std::string("2022-10-08 11:44:23"), std::string("day")},
str_to_datetime_v2("2022-10-08 00:00:00", "%Y-%m-%d %H:%i:%s")}};
static_cast<void>(
check_function<DataTypeDateTimeV2, true>(func_name, input_types, data_set));
}
{
InputTypeSet input_types = {TypeIndex::DateTimeV2, Consted {TypeIndex::String}};
DataSet data_set = {{{std::string("2022-10-08 11:44:23"), std::string("month")},
str_to_datetime_v2("2022-10-01 00:00:00", "%Y-%m-%d %H:%i:%s")}};
static_cast<void>(
check_function<DataTypeDateTimeV2, true>(func_name, input_types, data_set));
}
{
InputTypeSet input_types = {TypeIndex::DateTimeV2, Consted {TypeIndex::String}};
DataSet data_set = {{{std::string("2022-10-08 11:44:23"), std::string("year")},
str_to_datetime_v2("2022-01-01 00:00:00", "%Y-%m-%d %H:%i:%s")}};
static_cast<void>(
check_function<DataTypeDateTimeV2, true>(func_name, input_types, data_set));
}