From 935a0a0a0604925259435fa3f517ae23e661333d Mon Sep 17 00:00:00 2001 From: BiteTheDDDDt <952130278@qq.com> Date: Wed, 6 Apr 2022 18:33:02 +0800 Subject: [PATCH 1/6] fix read datetime update fix --- be/src/olap/row_block2.cpp | 25 ++-- .../aggregate_function_window_funnel.h | 2 +- be/src/vec/columns/column_vector.h | 9 +- be/src/vec/columns/predicate_column.h | 8 +- be/src/vec/exec/volap_scanner.cpp | 135 ------------------ be/src/vec/exec/volap_scanner.h | 2 - be/src/vec/functions/function_rpc.cpp | 12 +- be/src/vec/functions/function_timestamp.cpp | 4 +- be/src/vec/runtime/vdatetime_value.h | 29 +++- 9 files changed, 60 insertions(+), 166 deletions(-) diff --git a/be/src/olap/row_block2.cpp b/be/src/olap/row_block2.cpp index 4f2feec37bd88c..8beca02192d82c 100644 --- a/be/src/olap/row_block2.cpp +++ b/be/src/olap/row_block2.cpp @@ -236,11 +236,12 @@ Status RowBlockV2::_copy_data_to_column(int cid, value |= *(unsigned char*)(ptr + 1); value <<= 8; value |= *(unsigned char*)(ptr); - vectorized::VecDateTimeValue date; - date.from_olap_date(value); + vectorized::VecDateTimeValue date = + vectorized::VecDateTimeValue::create_from_olap_date(value); (column_int)->insert_data(reinterpret_cast(&date), 0); - } else + } else { column_int->insert_default(); + } } break; } @@ -253,9 +254,9 @@ Status RowBlockV2::_copy_data_to_column(int cid, auto ptr = reinterpret_cast(column_block(cid).cell_ptr(row_idx)); uint64_t value = *reinterpret_cast(ptr); - vectorized::VecDateTimeValue data; - data.from_olap_datetime(value); - (column_int)->insert_data(reinterpret_cast(&data), 0); + vectorized::VecDateTimeValue datetime = + vectorized::VecDateTimeValue::create_from_olap_datetime(value); + (column_int)->insert_data(reinterpret_cast(&datetime), 0); } else { column_int->insert_default(); } @@ -498,11 +499,12 @@ Status RowBlockV2::_append_data_to_column(const ColumnVectorBatch* batch, size_t value |= *(unsigned char*)(ptr + 1); value <<= 8; value |= *(unsigned char*)(ptr); - vectorized::VecDateTimeValue date; - date.from_olap_date(value); + vectorized::VecDateTimeValue date = + vectorized::VecDateTimeValue::create_from_olap_date(value); (column_int)->insert_data(reinterpret_cast(&date), 0); - } else + } else { column_int->insert_default(); + } } break; } @@ -515,8 +517,9 @@ Status RowBlockV2::_append_data_to_column(const ColumnVectorBatch* batch, size_t auto ptr = reinterpret_cast(batch->cell_ptr(row_idx)); uint64_t value = *reinterpret_cast(ptr); - vectorized::VecDateTimeValue data(value); - (column_int)->insert_data(reinterpret_cast(&data), 0); + vectorized::VecDateTimeValue datetime = + vectorized::VecDateTimeValue::create_from_olap_datetime(value); + (column_int)->insert_data(reinterpret_cast(&datetime), 0); } else { column_int->insert_default(); } diff --git a/be/src/vec/aggregate_functions/aggregate_function_window_funnel.h b/be/src/vec/aggregate_functions/aggregate_function_window_funnel.h index f4364eebb45208..f3078b74d40fd4 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_window_funnel.h +++ b/be/src/vec/aggregate_functions/aggregate_function_window_funnel.h @@ -152,7 +152,7 @@ struct WindowFunnelState { read_var_int(timestamp, in); read_var_int(event_idx, in); - VecDateTimeValue time_value(timestamp); + VecDateTimeValue time_value = VecDateTimeValue::create_from_normal_datetime(timestamp); add(time_value, (int)event_idx, max_event_level, window); } } diff --git a/be/src/vec/columns/column_vector.h b/be/src/vec/columns/column_vector.h index 216e8fd0edde08..e57ffe4a9c2547 100644 --- a/be/src/vec/columns/column_vector.h +++ b/be/src/vec/columns/column_vector.h @@ -21,6 +21,7 @@ #pragma once #include +#include #include "olap/uint24.h" #include "vec/columns/column.h" @@ -177,8 +178,7 @@ class ColumnVector final : public COWHelper> value |= *(unsigned char*)(cur_ptr + 1); value <<= 8; value |= *(unsigned char*)(cur_ptr); - vectorized::VecDateTimeValue date; - date.from_olap_date(value); + vectorized::VecDateTimeValue date = VecDateTimeValue::create_from_olap_date(value); this->insert_data(reinterpret_cast(&date), 0); } } @@ -188,8 +188,9 @@ class ColumnVector final : public COWHelper> for (int i = 0; i < num; i++) { const char* cur_ptr = data_ptr + value_size * i; uint64_t value = *reinterpret_cast(cur_ptr); - vectorized::VecDateTimeValue date(value); - this->insert_data(reinterpret_cast(&date), 0); + vectorized::VecDateTimeValue datetime = + VecDateTimeValue::create_from_olap_datetime(value); + this->insert_data(reinterpret_cast(&datetime), 0); } } diff --git a/be/src/vec/columns/predicate_column.h b/be/src/vec/columns/predicate_column.h index f41c239b5e605f..7db73b9d0a3850 100644 --- a/be/src/vec/columns/predicate_column.h +++ b/be/src/vec/columns/predicate_column.h @@ -58,8 +58,7 @@ class PredicateColumnType final : public COWHelper* res_ptr) { for (size_t i = 0; i < sel_size; i++) { - VecDateTimeValue date; - date.from_olap_date(get_date_at(sel[i])); + VecDateTimeValue date = VecDateTimeValue::create_from_olap_date(get_date_at(sel[i])); res_ptr->insert_data(reinterpret_cast(&date), 0); } } @@ -68,8 +67,9 @@ class PredicateColumnType final : public COWHelper* res_ptr) { for (size_t i = 0; i < sel_size; i++) { uint64_t value = data[sel[i]]; - vectorized::VecDateTimeValue date(value); - res_ptr->insert_data(reinterpret_cast(&date), 0); + vectorized::VecDateTimeValue datetime = + VecDateTimeValue::create_from_olap_datetime(value); + res_ptr->insert_data(reinterpret_cast(&datetime), 0); } } diff --git a/be/src/vec/exec/volap_scanner.cpp b/be/src/vec/exec/volap_scanner.cpp index 3850a8ab0c480e..f6367311776cd7 100644 --- a/be/src/vec/exec/volap_scanner.cpp +++ b/be/src/vec/exec/volap_scanner.cpp @@ -82,139 +82,4 @@ Status VOlapScanner::get_block(RuntimeState* state, vectorized::Block* block, bo void VOlapScanner::set_tablet_reader() { _tablet_reader = std::make_unique(); } - -void VOlapScanner::_convert_row_to_block(std::vector* columns) { - size_t slots_size = _query_slots.size(); - for (int i = 0; i < slots_size; ++i) { - SlotDescriptor* slot_desc = _query_slots[i]; - auto cid = _return_columns[i]; - - auto* column_ptr = (*columns)[i].get(); - if (slot_desc->is_nullable()) { - auto* nullable_column = reinterpret_cast((*columns)[i].get()); - if (_read_row_cursor.is_null(cid)) { - nullable_column->insert_data(nullptr, 0); - continue; - } else { - nullable_column->get_null_map_data().push_back(0); - column_ptr = &nullable_column->get_nested_column(); - } - } - - char* ptr = (char*)_read_row_cursor.cell_ptr(cid); - switch (slot_desc->type().type) { - case TYPE_BOOLEAN: { - assert_cast*>(column_ptr)->insert_data(ptr, 0); - break; - } - case TYPE_TINYINT: { - assert_cast*>(column_ptr)->insert_data(ptr, 0); - break; - } - case TYPE_SMALLINT: { - assert_cast*>(column_ptr)->insert_data(ptr, 0); - break; - } - case TYPE_INT: { - assert_cast*>(column_ptr)->insert_data(ptr, 0); - break; - } - case TYPE_BIGINT: { - assert_cast*>(column_ptr)->insert_data(ptr, 0); - break; - } - case TYPE_LARGEINT: { - assert_cast*>(column_ptr)->insert_data(ptr, 0); - break; - } - case TYPE_FLOAT: { - assert_cast*>(column_ptr)->insert_data(ptr, 0); - break; - } - case TYPE_DOUBLE: { - assert_cast*>(column_ptr)->insert_data(ptr, 0); - break; - } - case TYPE_CHAR: { - Slice* slice = reinterpret_cast(ptr); - assert_cast(column_ptr) - ->insert_data(slice->data, strnlen(slice->data, slice->size)); - break; - } - case TYPE_VARCHAR: - case TYPE_STRING: { - Slice* slice = reinterpret_cast(ptr); - assert_cast(column_ptr)->insert_data(slice->data, slice->size); - break; - } - case TYPE_OBJECT: { - Slice* slice = reinterpret_cast(ptr); - // insert_default() - auto* target_column = assert_cast(column_ptr); - - target_column->insert_default(); - BitmapValue* pvalue = nullptr; - int pos = target_column->size() - 1; - pvalue = &target_column->get_element(pos); - - if (slice->size != 0) { - BitmapValue value; - value.deserialize(slice->data); - *pvalue = std::move(value); - } else { - *pvalue = std::move(*reinterpret_cast(slice->data)); - } - break; - } - case TYPE_HLL: { - Slice* slice = reinterpret_cast(ptr); - auto* target_column = assert_cast(column_ptr); - - target_column->insert_default(); - HyperLogLog* pvalue = nullptr; - int pos = target_column->size() - 1; - pvalue = &target_column->get_element(pos); - if (slice->size != 0) { - HyperLogLog value; - value.deserialize(*slice); - *pvalue = std::move(value); - } else { - *pvalue = std::move(*reinterpret_cast(slice->data)); - } - break; - } - case TYPE_DECIMALV2: { - int64_t int_value = *(int64_t*)(ptr); - int32_t frac_value = *(int32_t*)(ptr + sizeof(int64_t)); - DecimalV2Value data(int_value, frac_value); - assert_cast*>(column_ptr) - ->insert_data(reinterpret_cast(&data), 0); - break; - } - case TYPE_DATETIME: { - uint64_t value = *reinterpret_cast(ptr); - VecDateTimeValue data(value); - assert_cast*>(column_ptr) - ->insert_data(reinterpret_cast(&data), 0); - break; - } - case TYPE_DATE: { - uint64_t value = 0; - value = *(unsigned char*)(ptr + 2); - value <<= 8; - value |= *(unsigned char*)(ptr + 1); - value <<= 8; - value |= *(unsigned char*)(ptr); - VecDateTimeValue date; - date.from_olap_date(value); - assert_cast*>(column_ptr) - ->insert_data(reinterpret_cast(&date), 0); - break; - } - default: { - break; - } - } - } -} } // namespace doris::vectorized diff --git a/be/src/vec/exec/volap_scanner.h b/be/src/vec/exec/volap_scanner.h index b6ef7e32ff8250..8c1ccca99e97da 100644 --- a/be/src/vec/exec/volap_scanner.h +++ b/be/src/vec/exec/volap_scanner.h @@ -52,8 +52,6 @@ class VOlapScanner : public OlapScanner { virtual void set_tablet_reader() override; private: - // TODO: Remove this function after we finish reader vec - void _convert_row_to_block(std::vector* columns); VExprContext* _vconjunct_ctx = nullptr; bool _need_to_close = false; }; diff --git a/be/src/vec/functions/function_rpc.cpp b/be/src/vec/functions/function_rpc.cpp index 9208ae2295fa04..da8b43d715561a 100644 --- a/be/src/vec/functions/function_rpc.cpp +++ b/be/src/vec/functions/function_rpc.cpp @@ -231,13 +231,15 @@ void convert_col_to_pvalue(const ColumnPtr& column, const DataTypePtr& data_type PDateTime* date_time = arg->add_datetime_value(); if constexpr (nullable) { if (!column->is_null_at(row_num)) { - VecDateTimeValue v = VecDateTimeValue(column->get_int(row_num)); + VecDateTimeValue v = + VecDateTimeValue::create_from_normal_date(column->get_int(row_num)); date_time->set_day(v.day()); date_time->set_month(v.month()); date_time->set_year(v.year()); } } else { - VecDateTimeValue v = VecDateTimeValue(column->get_int(row_num)); + VecDateTimeValue v = + VecDateTimeValue::create_from_normal_date(column->get_int(row_num)); date_time->set_day(v.day()); date_time->set_month(v.month()); date_time->set_year(v.year()); @@ -252,7 +254,8 @@ void convert_col_to_pvalue(const ColumnPtr& column, const DataTypePtr& data_type PDateTime* date_time = arg->add_datetime_value(); if constexpr (nullable) { if (!column->is_null_at(row_num)) { - VecDateTimeValue v = VecDateTimeValue(column->get_int(row_num)); + VecDateTimeValue v = + VecDateTimeValue::create_from_normal_datetime(column->get_int(row_num)); date_time->set_day(v.day()); date_time->set_month(v.month()); date_time->set_year(v.year()); @@ -261,7 +264,8 @@ void convert_col_to_pvalue(const ColumnPtr& column, const DataTypePtr& data_type date_time->set_second(v.second()); } } else { - VecDateTimeValue v = VecDateTimeValue(column->get_int(row_num)); + VecDateTimeValue v = + VecDateTimeValue::create_from_normal_datetime(column->get_int(row_num)); date_time->set_day(v.day()); date_time->set_month(v.month()); date_time->set_year(v.year()); diff --git a/be/src/vec/functions/function_timestamp.cpp b/be/src/vec/functions/function_timestamp.cpp index 45dc20a43f7e7d..884b36b24f33c3 100644 --- a/be/src/vec/functions/function_timestamp.cpp +++ b/be/src/vec/functions/function_timestamp.cpp @@ -89,8 +89,8 @@ struct MakeDateImpl { auto& res_val = *reinterpret_cast(&res[i]); - VecDateTimeValue ts_value {l * 10000000000 + 101000000}; - ts_value.set_type(TIME_DATE); + VecDateTimeValue ts_value = + VecDateTimeValue::create_from_normal_date(l * 10000000000 + 101000000); DateTimeVal ts_val; ts_value.to_datetime_val(&ts_val); if (ts_val.is_null) { diff --git a/be/src/vec/runtime/vdatetime_value.h b/be/src/vec/runtime/vdatetime_value.h index 6a77cdce98f781..50612ed4200153 100644 --- a/be/src/vec/runtime/vdatetime_value.h +++ b/be/src/vec/runtime/vdatetime_value.h @@ -134,10 +134,10 @@ constexpr size_t max_char_length(const char* const* name, size_t end) { static constexpr const char* s_month_name[] = { "", "January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December", NULL}; + "July", "August", "September", "October", "November", "December", nullptr}; static constexpr const char* s_day_name[] = {"Monday", "Tuesday", "Wednesday", "Thursday", - "Friday", "Saturday", "Sunday", NULL}; + "Friday", "Saturday", "Sunday", nullptr}; static constexpr size_t MAX_DAY_NAME_LEN = max_char_length(s_day_name, std::size(s_day_name)); static constexpr size_t MAX_MONTH_NAME_LEN = max_char_length(s_month_name, std::size(s_month_name)); @@ -157,7 +157,30 @@ class VecDateTimeValue { // Now this type is a temp solution with little changes _month(0), // so this is a difference between Vectorization mode and Rowbatch mode with DateTimeValue; _year(0) {} // before int128 16 bytes ---> after int64 8 bytes - explicit VecDateTimeValue(int64_t t) { from_date_int64(t); } + static VecDateTimeValue create_from_olap_date(uint64_t value) { + VecDateTimeValue date; + date.from_olap_date(value); + return date; + } + + static VecDateTimeValue create_from_olap_datetime(uint64_t value) { + VecDateTimeValue datetime; + datetime.from_olap_datetime(value); + return datetime; + } + + static VecDateTimeValue create_from_normal_date(uint64_t value) { + VecDateTimeValue date; + date.from_date_int64(value); + return date; + } + + static VecDateTimeValue create_from_normal_datetime(uint64_t value) { + VecDateTimeValue datetime; + datetime.from_date_int64(value); + datetime.to_datetime(); + return datetime; + } void set_time(uint32_t year, uint32_t month, uint32_t day, uint32_t hour, uint32_t minute, uint32_t second); From 97f706248719144775d1b522b102557a85213401 Mon Sep 17 00:00:00 2001 From: BiteTheDDDDt <952130278@qq.com> Date: Thu, 7 Apr 2022 16:21:25 +0800 Subject: [PATCH 2/6] add commit on create_from_xxx_xxx --- be/src/vec/runtime/vdatetime_value.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/be/src/vec/runtime/vdatetime_value.h b/be/src/vec/runtime/vdatetime_value.h index 50612ed4200153..87170e1ffad300 100644 --- a/be/src/vec/runtime/vdatetime_value.h +++ b/be/src/vec/runtime/vdatetime_value.h @@ -157,6 +157,8 @@ class VecDateTimeValue { // Now this type is a temp solution with little changes _month(0), // so this is a difference between Vectorization mode and Rowbatch mode with DateTimeValue; _year(0) {} // before int128 16 bytes ---> after int64 8 bytes + // The data format of DATE/DATETIME is different in storage layer and execute layer. + // So we should use diffrent creator to get data from value. static VecDateTimeValue create_from_olap_date(uint64_t value) { VecDateTimeValue date; date.from_olap_date(value); From 05e8ceaed03eac3b59231f755e971ef4fbad383e Mon Sep 17 00:00:00 2001 From: BiteTheDDDDt <952130278@qq.com> Date: Mon, 11 Apr 2022 11:25:50 +0800 Subject: [PATCH 3/6] add comment --- be/src/vec/runtime/vdatetime_value.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/be/src/vec/runtime/vdatetime_value.h b/be/src/vec/runtime/vdatetime_value.h index 87170e1ffad300..24570aa2385ef6 100644 --- a/be/src/vec/runtime/vdatetime_value.h +++ b/be/src/vec/runtime/vdatetime_value.h @@ -159,6 +159,8 @@ class VecDateTimeValue { // Now this type is a temp solution with little changes // The data format of DATE/DATETIME is different in storage layer and execute layer. // So we should use diffrent creator to get data from value. + // We should use create_from_olap_xxx only at binary data scaned from storage engine and convert to typed data. + // At other case, we just use create_from_normal_xxx. static VecDateTimeValue create_from_olap_date(uint64_t value) { VecDateTimeValue date; date.from_olap_date(value); From dc9f8751ed35fae3f91b86fc28ffed49fb1ff6bd Mon Sep 17 00:00:00 2001 From: BiteTheDDDDt <952130278@qq.com> Date: Mon, 11 Apr 2022 13:07:58 +0800 Subject: [PATCH 4/6] add comment --- be/src/vec/runtime/vdatetime_value.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/be/src/vec/runtime/vdatetime_value.h b/be/src/vec/runtime/vdatetime_value.h index 24570aa2385ef6..f72d2bcf2860d9 100644 --- a/be/src/vec/runtime/vdatetime_value.h +++ b/be/src/vec/runtime/vdatetime_value.h @@ -161,6 +161,12 @@ class VecDateTimeValue { // Now this type is a temp solution with little changes // So we should use diffrent creator to get data from value. // We should use create_from_olap_xxx only at binary data scaned from storage engine and convert to typed data. // At other case, we just use create_from_normal_xxx. + + // olap storage layer date data format: + // 64 bits binary data [year(remaining bits), month(4 bits), day(5 bits)] + // execute layer date/datetime and olap storage layer datetime data format: + // 16 bytes interger data [year(remaining digits), month(2 digits), day(2 digits), hour(2 digits), minute(2 digits) ,second(2 digits)] + static VecDateTimeValue create_from_olap_date(uint64_t value) { VecDateTimeValue date; date.from_olap_date(value); From 420cc018e8974adf66deebba136075ed294cc6a7 Mon Sep 17 00:00:00 2001 From: BiteTheDDDDt <952130278@qq.com> Date: Mon, 11 Apr 2022 20:54:03 +0800 Subject: [PATCH 5/6] remove normal function --- .../aggregate_function_window_funnel.h | 6 ++-- be/src/vec/functions/function_rpc.cpp | 14 +++++---- be/src/vec/functions/function_timestamp.cpp | 4 +-- be/src/vec/runtime/vdatetime_value.h | 30 +++++++++---------- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/be/src/vec/aggregate_functions/aggregate_function_window_funnel.h b/be/src/vec/aggregate_functions/aggregate_function_window_funnel.h index f3078b74d40fd4..8f42a3398c988e 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_window_funnel.h +++ b/be/src/vec/aggregate_functions/aggregate_function_window_funnel.h @@ -132,7 +132,8 @@ struct WindowFunnelState { write_var_int(events.size(), out); for (int64_t i = 0; i < events.size(); i++) { - int64_t timestamp = events[i].first; + int64_t timestamp = + binary_cast(events[i].first); int event_idx = events[i].second; write_var_int(timestamp, out); write_var_int(event_idx, out); @@ -152,7 +153,8 @@ struct WindowFunnelState { read_var_int(timestamp, in); read_var_int(event_idx, in); - VecDateTimeValue time_value = VecDateTimeValue::create_from_normal_datetime(timestamp); + VecDateTimeValue time_value = + binary_cast(timestamp); add(time_value, (int)event_idx, max_event_level, window); } } diff --git a/be/src/vec/functions/function_rpc.cpp b/be/src/vec/functions/function_rpc.cpp index da8b43d715561a..9b2e11d08ae9c9 100644 --- a/be/src/vec/functions/function_rpc.cpp +++ b/be/src/vec/functions/function_rpc.cpp @@ -232,14 +232,15 @@ void convert_col_to_pvalue(const ColumnPtr& column, const DataTypePtr& data_type if constexpr (nullable) { if (!column->is_null_at(row_num)) { VecDateTimeValue v = - VecDateTimeValue::create_from_normal_date(column->get_int(row_num)); + binary_cast( + column->get_int(row_num)); date_time->set_day(v.day()); date_time->set_month(v.month()); date_time->set_year(v.year()); } } else { - VecDateTimeValue v = - VecDateTimeValue::create_from_normal_date(column->get_int(row_num)); + VecDateTimeValue v = binary_cast( + column->get_int(row_num)); date_time->set_day(v.day()); date_time->set_month(v.month()); date_time->set_year(v.year()); @@ -255,7 +256,8 @@ void convert_col_to_pvalue(const ColumnPtr& column, const DataTypePtr& data_type if constexpr (nullable) { if (!column->is_null_at(row_num)) { VecDateTimeValue v = - VecDateTimeValue::create_from_normal_datetime(column->get_int(row_num)); + binary_cast( + column->get_int(row_num)); date_time->set_day(v.day()); date_time->set_month(v.month()); date_time->set_year(v.year()); @@ -264,8 +266,8 @@ void convert_col_to_pvalue(const ColumnPtr& column, const DataTypePtr& data_type date_time->set_second(v.second()); } } else { - VecDateTimeValue v = - VecDateTimeValue::create_from_normal_datetime(column->get_int(row_num)); + VecDateTimeValue v = binary_cast( + column->get_int(row_num)); date_time->set_day(v.day()); date_time->set_month(v.month()); date_time->set_year(v.year()); diff --git a/be/src/vec/functions/function_timestamp.cpp b/be/src/vec/functions/function_timestamp.cpp index 884b36b24f33c3..14c0a59b78de1b 100644 --- a/be/src/vec/functions/function_timestamp.cpp +++ b/be/src/vec/functions/function_timestamp.cpp @@ -89,8 +89,8 @@ struct MakeDateImpl { auto& res_val = *reinterpret_cast(&res[i]); - VecDateTimeValue ts_value = - VecDateTimeValue::create_from_normal_date(l * 10000000000 + 101000000); + VecDateTimeValue ts_value = VecDateTimeValue(l); + DateTimeVal ts_val; ts_value.to_datetime_val(&ts_val); if (ts_val.is_null) { diff --git a/be/src/vec/runtime/vdatetime_value.h b/be/src/vec/runtime/vdatetime_value.h index f72d2bcf2860d9..ca9b41c227ca63 100644 --- a/be/src/vec/runtime/vdatetime_value.h +++ b/be/src/vec/runtime/vdatetime_value.h @@ -157,15 +157,26 @@ class VecDateTimeValue { // Now this type is a temp solution with little changes _month(0), // so this is a difference between Vectorization mode and Rowbatch mode with DateTimeValue; _year(0) {} // before int128 16 bytes ---> after int64 8 bytes + // only used on function makedate + VecDateTimeValue(int year) + : _neg(0), + _type(TIME_DATETIME), + _second(0), + _minute(0), + _hour(0), + _day(1), + _month(1), + _year(year) {} + // The data format of DATE/DATETIME is different in storage layer and execute layer. // So we should use diffrent creator to get data from value. // We should use create_from_olap_xxx only at binary data scaned from storage engine and convert to typed data. - // At other case, we just use create_from_normal_xxx. + // At other case, we just use binary_cast. // olap storage layer date data format: // 64 bits binary data [year(remaining bits), month(4 bits), day(5 bits)] // execute layer date/datetime and olap storage layer datetime data format: - // 16 bytes interger data [year(remaining digits), month(2 digits), day(2 digits), hour(2 digits), minute(2 digits) ,second(2 digits)] + // 8 bytes interger data [year(remaining digits), month(2 digits), day(2 digits), hour(2 digits), minute(2 digits) ,second(2 digits)] static VecDateTimeValue create_from_olap_date(uint64_t value) { VecDateTimeValue date; @@ -179,19 +190,6 @@ class VecDateTimeValue { // Now this type is a temp solution with little changes return datetime; } - static VecDateTimeValue create_from_normal_date(uint64_t value) { - VecDateTimeValue date; - date.from_date_int64(value); - return date; - } - - static VecDateTimeValue create_from_normal_datetime(uint64_t value) { - VecDateTimeValue datetime; - datetime.from_date_int64(value); - datetime.to_datetime(); - return datetime; - } - void set_time(uint32_t year, uint32_t month, uint32_t day, uint32_t hour, uint32_t minute, uint32_t second); @@ -627,7 +625,7 @@ class VecDateTimeValue { // Now this type is a temp solution with little changes char* to_date_buffer(char* to) const; char* to_time_buffer(char* to) const; - // Used to convert to uint64_t + // Used to convert to int64_t int64_t to_datetime_int64() const; int64_t to_date_int64() const; int64_t to_time_int64() const; From 0f1d01f8891e7ff57c5384092da3076936cb5c7b Mon Sep 17 00:00:00 2001 From: BiteTheDDDDt <952130278@qq.com> Date: Tue, 12 Apr 2022 14:02:48 +0800 Subject: [PATCH 6/6] remove constructor --- be/src/vec/functions/function_timestamp.cpp | 3 ++- be/src/vec/runtime/vdatetime_value.h | 11 ----------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/be/src/vec/functions/function_timestamp.cpp b/be/src/vec/functions/function_timestamp.cpp index 14c0a59b78de1b..22f159bd8ec651 100644 --- a/be/src/vec/functions/function_timestamp.cpp +++ b/be/src/vec/functions/function_timestamp.cpp @@ -89,7 +89,8 @@ struct MakeDateImpl { auto& res_val = *reinterpret_cast(&res[i]); - VecDateTimeValue ts_value = VecDateTimeValue(l); + VecDateTimeValue ts_value = VecDateTimeValue(); + ts_value.set_time(l, 1, 1, 0, 0, 0); DateTimeVal ts_val; ts_value.to_datetime_val(&ts_val); diff --git a/be/src/vec/runtime/vdatetime_value.h b/be/src/vec/runtime/vdatetime_value.h index ca9b41c227ca63..a51be2e41ffa00 100644 --- a/be/src/vec/runtime/vdatetime_value.h +++ b/be/src/vec/runtime/vdatetime_value.h @@ -157,17 +157,6 @@ class VecDateTimeValue { // Now this type is a temp solution with little changes _month(0), // so this is a difference between Vectorization mode and Rowbatch mode with DateTimeValue; _year(0) {} // before int128 16 bytes ---> after int64 8 bytes - // only used on function makedate - VecDateTimeValue(int year) - : _neg(0), - _type(TIME_DATETIME), - _second(0), - _minute(0), - _hour(0), - _day(1), - _month(1), - _year(year) {} - // The data format of DATE/DATETIME is different in storage layer and execute layer. // So we should use diffrent creator to get data from value. // We should use create_from_olap_xxx only at binary data scaned from storage engine and convert to typed data.