[FOLLOW-UP] (datetimev2) complete date function ut and built-in function declaration (#11154)

This commit is contained in:
Gabriel
2022-07-26 17:48:57 +08:00
committed by GitHub
parent 8551ceaa1b
commit 823088a9eb
9 changed files with 1940 additions and 193 deletions

View File

@ -40,6 +40,13 @@ uint32_t str_to_date_v2(std::string datetime_str, std::string datetime_format) {
return binary_cast<DateV2Value<DateV2ValueType>, UInt32>(v);
}
uint64_t str_to_datetime_v2(std::string datetime_str, std::string datetime_format) {
DateV2Value<DateTimeV2ValueType> v;
v.from_date_format_str(datetime_format.c_str(), datetime_format.size(), datetime_str.c_str(),
datetime_str.size());
return binary_cast<DateV2Value<DateTimeV2ValueType>, UInt64>(v);
}
size_t type_index_to_data_type(const std::vector<std::any>& input_types, size_t index,
ut_type::UTDataTypeDesc& ut_desc, DataTypePtr& type) {
doris_udf::FunctionContext::TypeDesc& desc = ut_desc.type_desc;
@ -109,7 +116,7 @@ size_t type_index_to_data_type(const std::vector<std::any>& input_types, size_t
return 1;
case TypeIndex::DateTimeV2:
desc.type = doris_udf::FunctionContext::TYPE_DATETIMEV2;
type = std::make_shared<DataTypeDateV2>();
type = std::make_shared<DataTypeDateTimeV2>();
return 1;
case TypeIndex::Array: {
desc.type = doris_udf::FunctionContext::TYPE_ARRAY;
@ -220,6 +227,13 @@ bool insert_cell(MutableColumnPtr& column, DataTypePtr type_ptr, const std::any&
v.from_date_format_str(date_time_format.c_str(), date_time_format.size(),
datetime_str.c_str(), datetime_str.size());
column->insert_data(reinterpret_cast<char*>(&v), 0);
} else if (type.is_date_time_v2()) {
static std::string date_time_format("%Y-%m-%d %H:%i:%s.%f");
auto datetime_str = std::any_cast<std::string>(cell);
DateV2Value<DateTimeV2ValueType> v;
v.from_date_format_str(date_time_format.c_str(), date_time_format.size(),
datetime_str.c_str(), datetime_str.size());
column->insert_data(reinterpret_cast<char*>(&v), 0);
} else if (type.is_array()) {
auto v = std::any_cast<Array>(cell);
column->insert(v);