be/src/exprs/function/cast/cast_to_date.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <sys/types.h> |
21 | | |
22 | | #include <cstdint> |
23 | | #include <cstdlib> |
24 | | #include <type_traits> |
25 | | |
26 | | #include "common/status.h" |
27 | | #include "core/binary_cast.hpp" |
28 | | #include "core/column/column_nullable.h" |
29 | | #include "core/data_type/data_type_date_or_datetime_v2.h" |
30 | | #include "core/data_type/data_type_date_time.h" |
31 | | #include "core/data_type/data_type_decimal.h" // IWYU pragma: keep |
32 | | #include "core/data_type/data_type_number.h" |
33 | | #include "core/data_type/data_type_string.h" |
34 | | #include "core/data_type/data_type_time.h" |
35 | | #include "core/data_type/primitive_type.h" |
36 | | #include "core/data_type_serde/data_type_serde.h" |
37 | | #include "core/types.h" |
38 | | #include "core/value/time_value.h" |
39 | | #include "core/value/vdatetime_value.h" |
40 | | #include "exprs/function/cast/cast_base.h" |
41 | | #include "exprs/function/cast/cast_to_datetimev2_impl.hpp" |
42 | | #include "runtime/runtime_state.h" |
43 | | |
44 | | namespace doris { |
45 | | template <CastModeType CastMode, typename FromDataType, typename ToDataType> |
46 | | requires(IsStringType<FromDataType> && IsDatelikeTypes<ToDataType>) |
47 | | class CastToImpl<CastMode, FromDataType, ToDataType> : public CastToBase { |
48 | | public: |
49 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
50 | | uint32_t result, size_t input_rows_count, |
51 | 113 | const NullMap::value_type* null_map = nullptr) const override { |
52 | 113 | const auto& named_from = block.get_by_position(arguments[0]); |
53 | 113 | if (!named_from.column) { |
54 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); |
55 | 0 | } |
56 | 113 | const auto* col_from = |
57 | 113 | check_and_get_column<DataTypeString::ColumnType>(named_from.column.get()); |
58 | 113 | if (!col_from) { |
59 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", |
60 | 0 | named_from.column->get_name()); |
61 | 0 | } |
62 | | |
63 | 113 | auto to_type = block.get_by_position(result).type; |
64 | 113 | auto serde = remove_nullable(to_type)->get_serde(); |
65 | | |
66 | 113 | DataTypeSerDe::FormatOptions options; |
67 | 113 | options.timezone = &context->state()->timezone_obj(); |
68 | | |
69 | | // by default framework, to_type is already unwrapped nullable |
70 | 113 | MutableColumnPtr column_to = to_type->create_column(); |
71 | 113 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( |
72 | 113 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); |
73 | | |
74 | 113 | if constexpr (CastMode == CastModeType::StrictMode) { |
75 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows |
76 | 107 | RETURN_IF_ERROR(serde->from_string_strict_mode_batch( |
77 | 107 | *col_from, nullable_col_to->get_nested_column(), options, null_map)); |
78 | 107 | } else { |
79 | | // may write nulls to nullable_col_to |
80 | 6 | RETURN_IF_ERROR(serde->from_string_batch(*col_from, *nullable_col_to, options)); |
81 | 6 | } |
82 | | |
83 | 9 | block.get_by_position(result).column = std::move(nullable_col_to); |
84 | 113 | return Status::OK(); |
85 | 113 | } Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeStringENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeStringENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeStringENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeStringENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeStringENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 51 | 48 | const NullMap::value_type* null_map = nullptr) const override { | 52 | 48 | const auto& named_from = block.get_by_position(arguments[0]); | 53 | 48 | if (!named_from.column) { | 54 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 55 | 0 | } | 56 | 48 | const auto* col_from = | 57 | 48 | check_and_get_column<DataTypeString::ColumnType>(named_from.column.get()); | 58 | 48 | if (!col_from) { | 59 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 60 | 0 | named_from.column->get_name()); | 61 | 0 | } | 62 | | | 63 | 48 | auto to_type = block.get_by_position(result).type; | 64 | 48 | auto serde = remove_nullable(to_type)->get_serde(); | 65 | | | 66 | 48 | DataTypeSerDe::FormatOptions options; | 67 | 48 | options.timezone = &context->state()->timezone_obj(); | 68 | | | 69 | | // by default framework, to_type is already unwrapped nullable | 70 | 48 | MutableColumnPtr column_to = to_type->create_column(); | 71 | 48 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 72 | 48 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 73 | | | 74 | 48 | if constexpr (CastMode == CastModeType::StrictMode) { | 75 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 76 | 48 | RETURN_IF_ERROR(serde->from_string_strict_mode_batch( | 77 | 48 | *col_from, nullable_col_to->get_nested_column(), options, null_map)); | 78 | | } else { | 79 | | // may write nulls to nullable_col_to | 80 | | RETURN_IF_ERROR(serde->from_string_batch(*col_from, *nullable_col_to, options)); | 81 | | } | 82 | | | 83 | 1 | block.get_by_position(result).column = std::move(nullable_col_to); | 84 | 48 | return Status::OK(); | 85 | 48 | } |
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeStringENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 51 | 3 | const NullMap::value_type* null_map = nullptr) const override { | 52 | 3 | const auto& named_from = block.get_by_position(arguments[0]); | 53 | 3 | if (!named_from.column) { | 54 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 55 | 0 | } | 56 | 3 | const auto* col_from = | 57 | 3 | check_and_get_column<DataTypeString::ColumnType>(named_from.column.get()); | 58 | 3 | if (!col_from) { | 59 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 60 | 0 | named_from.column->get_name()); | 61 | 0 | } | 62 | | | 63 | 3 | auto to_type = block.get_by_position(result).type; | 64 | 3 | auto serde = remove_nullable(to_type)->get_serde(); | 65 | | | 66 | 3 | DataTypeSerDe::FormatOptions options; | 67 | 3 | options.timezone = &context->state()->timezone_obj(); | 68 | | | 69 | | // by default framework, to_type is already unwrapped nullable | 70 | 3 | MutableColumnPtr column_to = to_type->create_column(); | 71 | 3 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 72 | 3 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 73 | | | 74 | | if constexpr (CastMode == CastModeType::StrictMode) { | 75 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 76 | | RETURN_IF_ERROR(serde->from_string_strict_mode_batch( | 77 | | *col_from, nullable_col_to->get_nested_column(), options, null_map)); | 78 | 3 | } else { | 79 | | // may write nulls to nullable_col_to | 80 | 3 | RETURN_IF_ERROR(serde->from_string_batch(*col_from, *nullable_col_to, options)); | 81 | 3 | } | 82 | | | 83 | 3 | block.get_by_position(result).column = std::move(nullable_col_to); | 84 | 3 | return Status::OK(); | 85 | 3 | } |
_ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeStringENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 51 | 48 | const NullMap::value_type* null_map = nullptr) const override { | 52 | 48 | const auto& named_from = block.get_by_position(arguments[0]); | 53 | 48 | if (!named_from.column) { | 54 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 55 | 0 | } | 56 | 48 | const auto* col_from = | 57 | 48 | check_and_get_column<DataTypeString::ColumnType>(named_from.column.get()); | 58 | 48 | if (!col_from) { | 59 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 60 | 0 | named_from.column->get_name()); | 61 | 0 | } | 62 | | | 63 | 48 | auto to_type = block.get_by_position(result).type; | 64 | 48 | auto serde = remove_nullable(to_type)->get_serde(); | 65 | | | 66 | 48 | DataTypeSerDe::FormatOptions options; | 67 | 48 | options.timezone = &context->state()->timezone_obj(); | 68 | | | 69 | | // by default framework, to_type is already unwrapped nullable | 70 | 48 | MutableColumnPtr column_to = to_type->create_column(); | 71 | 48 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 72 | 48 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 73 | | | 74 | 48 | if constexpr (CastMode == CastModeType::StrictMode) { | 75 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 76 | 48 | RETURN_IF_ERROR(serde->from_string_strict_mode_batch( | 77 | 48 | *col_from, nullable_col_to->get_nested_column(), options, null_map)); | 78 | | } else { | 79 | | // may write nulls to nullable_col_to | 80 | | RETURN_IF_ERROR(serde->from_string_batch(*col_from, *nullable_col_to, options)); | 81 | | } | 82 | | | 83 | 1 | block.get_by_position(result).column = std::move(nullable_col_to); | 84 | 48 | return Status::OK(); | 85 | 48 | } |
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeStringENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 51 | 2 | const NullMap::value_type* null_map = nullptr) const override { | 52 | 2 | const auto& named_from = block.get_by_position(arguments[0]); | 53 | 2 | if (!named_from.column) { | 54 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 55 | 0 | } | 56 | 2 | const auto* col_from = | 57 | 2 | check_and_get_column<DataTypeString::ColumnType>(named_from.column.get()); | 58 | 2 | if (!col_from) { | 59 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 60 | 0 | named_from.column->get_name()); | 61 | 0 | } | 62 | | | 63 | 2 | auto to_type = block.get_by_position(result).type; | 64 | 2 | auto serde = remove_nullable(to_type)->get_serde(); | 65 | | | 66 | 2 | DataTypeSerDe::FormatOptions options; | 67 | 2 | options.timezone = &context->state()->timezone_obj(); | 68 | | | 69 | | // by default framework, to_type is already unwrapped nullable | 70 | 2 | MutableColumnPtr column_to = to_type->create_column(); | 71 | 2 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 72 | 2 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 73 | | | 74 | | if constexpr (CastMode == CastModeType::StrictMode) { | 75 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 76 | | RETURN_IF_ERROR(serde->from_string_strict_mode_batch( | 77 | | *col_from, nullable_col_to->get_nested_column(), options, null_map)); | 78 | 2 | } else { | 79 | | // may write nulls to nullable_col_to | 80 | 2 | RETURN_IF_ERROR(serde->from_string_batch(*col_from, *nullable_col_to, options)); | 81 | 2 | } | 82 | | | 83 | 2 | block.get_by_position(result).column = std::move(nullable_col_to); | 84 | 2 | return Status::OK(); | 85 | 2 | } |
_ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeStringENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 51 | 11 | const NullMap::value_type* null_map = nullptr) const override { | 52 | 11 | const auto& named_from = block.get_by_position(arguments[0]); | 53 | 11 | if (!named_from.column) { | 54 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 55 | 0 | } | 56 | 11 | const auto* col_from = | 57 | 11 | check_and_get_column<DataTypeString::ColumnType>(named_from.column.get()); | 58 | 11 | if (!col_from) { | 59 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 60 | 0 | named_from.column->get_name()); | 61 | 0 | } | 62 | | | 63 | 11 | auto to_type = block.get_by_position(result).type; | 64 | 11 | auto serde = remove_nullable(to_type)->get_serde(); | 65 | | | 66 | 11 | DataTypeSerDe::FormatOptions options; | 67 | 11 | options.timezone = &context->state()->timezone_obj(); | 68 | | | 69 | | // by default framework, to_type is already unwrapped nullable | 70 | 11 | MutableColumnPtr column_to = to_type->create_column(); | 71 | 11 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 72 | 11 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 73 | | | 74 | 11 | if constexpr (CastMode == CastModeType::StrictMode) { | 75 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 76 | 11 | RETURN_IF_ERROR(serde->from_string_strict_mode_batch( | 77 | 11 | *col_from, nullable_col_to->get_nested_column(), options, null_map)); | 78 | | } else { | 79 | | // may write nulls to nullable_col_to | 80 | | RETURN_IF_ERROR(serde->from_string_batch(*col_from, *nullable_col_to, options)); | 81 | | } | 82 | | | 83 | 1 | block.get_by_position(result).column = std::move(nullable_col_to); | 84 | 11 | return Status::OK(); | 85 | 11 | } |
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeStringENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 51 | 1 | const NullMap::value_type* null_map = nullptr) const override { | 52 | 1 | const auto& named_from = block.get_by_position(arguments[0]); | 53 | 1 | if (!named_from.column) { | 54 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 55 | 0 | } | 56 | 1 | const auto* col_from = | 57 | 1 | check_and_get_column<DataTypeString::ColumnType>(named_from.column.get()); | 58 | 1 | if (!col_from) { | 59 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 60 | 0 | named_from.column->get_name()); | 61 | 0 | } | 62 | | | 63 | 1 | auto to_type = block.get_by_position(result).type; | 64 | 1 | auto serde = remove_nullable(to_type)->get_serde(); | 65 | | | 66 | 1 | DataTypeSerDe::FormatOptions options; | 67 | 1 | options.timezone = &context->state()->timezone_obj(); | 68 | | | 69 | | // by default framework, to_type is already unwrapped nullable | 70 | 1 | MutableColumnPtr column_to = to_type->create_column(); | 71 | 1 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 72 | 1 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 73 | | | 74 | | if constexpr (CastMode == CastModeType::StrictMode) { | 75 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 76 | | RETURN_IF_ERROR(serde->from_string_strict_mode_batch( | 77 | | *col_from, nullable_col_to->get_nested_column(), options, null_map)); | 78 | 1 | } else { | 79 | | // may write nulls to nullable_col_to | 80 | 1 | RETURN_IF_ERROR(serde->from_string_batch(*col_from, *nullable_col_to, options)); | 81 | 1 | } | 82 | | | 83 | 1 | block.get_by_position(result).column = std::move(nullable_col_to); | 84 | 1 | return Status::OK(); | 85 | 1 | } |
|
86 | | }; |
87 | | |
88 | | template <CastModeType CastMode, typename FromDataType, typename ToDataType> |
89 | | requires(CastUtil::IsPureDigitType<FromDataType> && IsDatelikeTypes<ToDataType>) |
90 | | class CastToImpl<CastMode, FromDataType, ToDataType> : public CastToBase { |
91 | | public: |
92 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
93 | | uint32_t result, size_t input_rows_count, |
94 | 37 | const NullMap::value_type* null_map = nullptr) const override { |
95 | 37 | const auto& named_from = block.get_by_position(arguments[0]); |
96 | 37 | if (!named_from.column) { |
97 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); |
98 | 0 | } |
99 | 37 | const auto* col_from = |
100 | 37 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); |
101 | 37 | if (!col_from) { |
102 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", |
103 | 0 | named_from.column->get_name()); |
104 | 0 | } |
105 | 37 | auto to_type = block.get_by_position(result).type; |
106 | 37 | auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>( |
107 | 37 | remove_nullable(to_type)->get_serde()); |
108 | | |
109 | | // by default framework, to_type is already unwrapped nullable |
110 | 37 | MutableColumnPtr column_to = to_type->create_column(); |
111 | 37 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( |
112 | 37 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); |
113 | | |
114 | | // datelike types serde must have template functions for those types. but because of they need to be |
115 | | // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before. |
116 | 37 | if constexpr (CastMode == CastModeType::StrictMode) { |
117 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows |
118 | 21 | if constexpr (IsDataTypeInt<FromDataType>) { |
119 | 10 | RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>( |
120 | 10 | *col_from, nullable_col_to->get_nested_column())); |
121 | 10 | } else if constexpr (IsDataTypeFloat<FromDataType>) { |
122 | 10 | RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>( |
123 | 10 | *col_from, nullable_col_to->get_nested_column())); |
124 | 10 | } else { |
125 | 1 | static_assert(IsDataTypeDecimal<FromDataType>); |
126 | 1 | RETURN_IF_ERROR( |
127 | 1 | concrete_serde->template from_decimal_strict_mode_batch<FromDataType>( |
128 | 1 | *col_from, nullable_col_to->get_nested_column())); |
129 | 1 | } |
130 | 21 | } else { |
131 | | // may write nulls to nullable_col_to |
132 | 16 | if constexpr (IsDataTypeInt<FromDataType>) { |
133 | 5 | RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>( |
134 | 5 | *col_from, *nullable_col_to)); |
135 | 5 | } else if constexpr (IsDataTypeFloat<FromDataType>) { |
136 | 5 | RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>( |
137 | 5 | *col_from, *nullable_col_to)); |
138 | 6 | } else { |
139 | 6 | static_assert(IsDataTypeDecimal<FromDataType>); |
140 | 6 | RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>( |
141 | 6 | *col_from, *nullable_col_to)); |
142 | 6 | } |
143 | 16 | } |
144 | | |
145 | 16 | block.get_by_position(result).column = std::move(nullable_col_to); |
146 | 37 | return Status::OK(); |
147 | 37 | } Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 94 | 5 | const NullMap::value_type* null_map = nullptr) const override { | 95 | 5 | const auto& named_from = block.get_by_position(arguments[0]); | 96 | 5 | if (!named_from.column) { | 97 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 98 | 0 | } | 99 | 5 | const auto* col_from = | 100 | 5 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 101 | 5 | if (!col_from) { | 102 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 103 | 0 | named_from.column->get_name()); | 104 | 0 | } | 105 | 5 | auto to_type = block.get_by_position(result).type; | 106 | 5 | auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>( | 107 | 5 | remove_nullable(to_type)->get_serde()); | 108 | | | 109 | | // by default framework, to_type is already unwrapped nullable | 110 | 5 | MutableColumnPtr column_to = to_type->create_column(); | 111 | 5 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 112 | 5 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 113 | | | 114 | | // datelike types serde must have template functions for those types. but because of they need to be | 115 | | // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before. | 116 | 5 | if constexpr (CastMode == CastModeType::StrictMode) { | 117 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 118 | 5 | if constexpr (IsDataTypeInt<FromDataType>) { | 119 | 5 | RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>( | 120 | 5 | *col_from, nullable_col_to->get_nested_column())); | 121 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 122 | | RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>( | 123 | | *col_from, nullable_col_to->get_nested_column())); | 124 | | } else { | 125 | | static_assert(IsDataTypeDecimal<FromDataType>); | 126 | | RETURN_IF_ERROR( | 127 | | concrete_serde->template from_decimal_strict_mode_batch<FromDataType>( | 128 | | *col_from, nullable_col_to->get_nested_column())); | 129 | | } | 130 | | } else { | 131 | | // may write nulls to nullable_col_to | 132 | | if constexpr (IsDataTypeInt<FromDataType>) { | 133 | | RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>( | 134 | | *col_from, *nullable_col_to)); | 135 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 136 | | RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>( | 137 | | *col_from, *nullable_col_to)); | 138 | | } else { | 139 | | static_assert(IsDataTypeDecimal<FromDataType>); | 140 | | RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>( | 141 | | *col_from, *nullable_col_to)); | 142 | | } | 143 | | } | 144 | | | 145 | 0 | block.get_by_position(result).column = std::move(nullable_col_to); | 146 | 5 | return Status::OK(); | 147 | 5 | } |
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 94 | 2 | const NullMap::value_type* null_map = nullptr) const override { | 95 | 2 | const auto& named_from = block.get_by_position(arguments[0]); | 96 | 2 | if (!named_from.column) { | 97 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 98 | 0 | } | 99 | 2 | const auto* col_from = | 100 | 2 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 101 | 2 | if (!col_from) { | 102 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 103 | 0 | named_from.column->get_name()); | 104 | 0 | } | 105 | 2 | auto to_type = block.get_by_position(result).type; | 106 | 2 | auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>( | 107 | 2 | remove_nullable(to_type)->get_serde()); | 108 | | | 109 | | // by default framework, to_type is already unwrapped nullable | 110 | 2 | MutableColumnPtr column_to = to_type->create_column(); | 111 | 2 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 112 | 2 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 113 | | | 114 | | // datelike types serde must have template functions for those types. but because of they need to be | 115 | | // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before. | 116 | | if constexpr (CastMode == CastModeType::StrictMode) { | 117 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 118 | | if constexpr (IsDataTypeInt<FromDataType>) { | 119 | | RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>( | 120 | | *col_from, nullable_col_to->get_nested_column())); | 121 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 122 | | RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>( | 123 | | *col_from, nullable_col_to->get_nested_column())); | 124 | | } else { | 125 | | static_assert(IsDataTypeDecimal<FromDataType>); | 126 | | RETURN_IF_ERROR( | 127 | | concrete_serde->template from_decimal_strict_mode_batch<FromDataType>( | 128 | | *col_from, nullable_col_to->get_nested_column())); | 129 | | } | 130 | 2 | } else { | 131 | | // may write nulls to nullable_col_to | 132 | 2 | if constexpr (IsDataTypeInt<FromDataType>) { | 133 | 2 | RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>( | 134 | 2 | *col_from, *nullable_col_to)); | 135 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 136 | | RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>( | 137 | | *col_from, *nullable_col_to)); | 138 | | } else { | 139 | | static_assert(IsDataTypeDecimal<FromDataType>); | 140 | | RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>( | 141 | | *col_from, *nullable_col_to)); | 142 | | } | 143 | 2 | } | 144 | | | 145 | 2 | block.get_by_position(result).column = std::move(nullable_col_to); | 146 | 2 | return Status::OK(); | 147 | 2 | } |
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 94 | 5 | const NullMap::value_type* null_map = nullptr) const override { | 95 | 5 | const auto& named_from = block.get_by_position(arguments[0]); | 96 | 5 | if (!named_from.column) { | 97 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 98 | 0 | } | 99 | 5 | const auto* col_from = | 100 | 5 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 101 | 5 | if (!col_from) { | 102 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 103 | 0 | named_from.column->get_name()); | 104 | 0 | } | 105 | 5 | auto to_type = block.get_by_position(result).type; | 106 | 5 | auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>( | 107 | 5 | remove_nullable(to_type)->get_serde()); | 108 | | | 109 | | // by default framework, to_type is already unwrapped nullable | 110 | 5 | MutableColumnPtr column_to = to_type->create_column(); | 111 | 5 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 112 | 5 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 113 | | | 114 | | // datelike types serde must have template functions for those types. but because of they need to be | 115 | | // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before. | 116 | 5 | if constexpr (CastMode == CastModeType::StrictMode) { | 117 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 118 | | if constexpr (IsDataTypeInt<FromDataType>) { | 119 | | RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>( | 120 | | *col_from, nullable_col_to->get_nested_column())); | 121 | 5 | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 122 | 5 | RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>( | 123 | 5 | *col_from, nullable_col_to->get_nested_column())); | 124 | | } else { | 125 | | static_assert(IsDataTypeDecimal<FromDataType>); | 126 | | RETURN_IF_ERROR( | 127 | | concrete_serde->template from_decimal_strict_mode_batch<FromDataType>( | 128 | | *col_from, nullable_col_to->get_nested_column())); | 129 | | } | 130 | | } else { | 131 | | // may write nulls to nullable_col_to | 132 | | if constexpr (IsDataTypeInt<FromDataType>) { | 133 | | RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>( | 134 | | *col_from, *nullable_col_to)); | 135 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 136 | | RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>( | 137 | | *col_from, *nullable_col_to)); | 138 | | } else { | 139 | | static_assert(IsDataTypeDecimal<FromDataType>); | 140 | | RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>( | 141 | | *col_from, *nullable_col_to)); | 142 | | } | 143 | | } | 144 | | | 145 | 0 | block.get_by_position(result).column = std::move(nullable_col_to); | 146 | 5 | return Status::OK(); | 147 | 5 | } |
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 94 | 2 | const NullMap::value_type* null_map = nullptr) const override { | 95 | 2 | const auto& named_from = block.get_by_position(arguments[0]); | 96 | 2 | if (!named_from.column) { | 97 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 98 | 0 | } | 99 | 2 | const auto* col_from = | 100 | 2 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 101 | 2 | if (!col_from) { | 102 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 103 | 0 | named_from.column->get_name()); | 104 | 0 | } | 105 | 2 | auto to_type = block.get_by_position(result).type; | 106 | 2 | auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>( | 107 | 2 | remove_nullable(to_type)->get_serde()); | 108 | | | 109 | | // by default framework, to_type is already unwrapped nullable | 110 | 2 | MutableColumnPtr column_to = to_type->create_column(); | 111 | 2 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 112 | 2 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 113 | | | 114 | | // datelike types serde must have template functions for those types. but because of they need to be | 115 | | // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before. | 116 | | if constexpr (CastMode == CastModeType::StrictMode) { | 117 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 118 | | if constexpr (IsDataTypeInt<FromDataType>) { | 119 | | RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>( | 120 | | *col_from, nullable_col_to->get_nested_column())); | 121 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 122 | | RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>( | 123 | | *col_from, nullable_col_to->get_nested_column())); | 124 | | } else { | 125 | | static_assert(IsDataTypeDecimal<FromDataType>); | 126 | | RETURN_IF_ERROR( | 127 | | concrete_serde->template from_decimal_strict_mode_batch<FromDataType>( | 128 | | *col_from, nullable_col_to->get_nested_column())); | 129 | | } | 130 | 2 | } else { | 131 | | // may write nulls to nullable_col_to | 132 | | if constexpr (IsDataTypeInt<FromDataType>) { | 133 | | RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>( | 134 | | *col_from, *nullable_col_to)); | 135 | 2 | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 136 | 2 | RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>( | 137 | 2 | *col_from, *nullable_col_to)); | 138 | | } else { | 139 | | static_assert(IsDataTypeDecimal<FromDataType>); | 140 | | RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>( | 141 | | *col_from, *nullable_col_to)); | 142 | | } | 143 | 2 | } | 144 | | | 145 | 2 | block.get_by_position(result).column = std::move(nullable_col_to); | 146 | 2 | return Status::OK(); | 147 | 2 | } |
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 94 | 2 | const NullMap::value_type* null_map = nullptr) const override { | 95 | 2 | const auto& named_from = block.get_by_position(arguments[0]); | 96 | 2 | if (!named_from.column) { | 97 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 98 | 0 | } | 99 | 2 | const auto* col_from = | 100 | 2 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 101 | 2 | if (!col_from) { | 102 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 103 | 0 | named_from.column->get_name()); | 104 | 0 | } | 105 | 2 | auto to_type = block.get_by_position(result).type; | 106 | 2 | auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>( | 107 | 2 | remove_nullable(to_type)->get_serde()); | 108 | | | 109 | | // by default framework, to_type is already unwrapped nullable | 110 | 2 | MutableColumnPtr column_to = to_type->create_column(); | 111 | 2 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 112 | 2 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 113 | | | 114 | | // datelike types serde must have template functions for those types. but because of they need to be | 115 | | // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before. | 116 | | if constexpr (CastMode == CastModeType::StrictMode) { | 117 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 118 | | if constexpr (IsDataTypeInt<FromDataType>) { | 119 | | RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>( | 120 | | *col_from, nullable_col_to->get_nested_column())); | 121 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 122 | | RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>( | 123 | | *col_from, nullable_col_to->get_nested_column())); | 124 | | } else { | 125 | | static_assert(IsDataTypeDecimal<FromDataType>); | 126 | | RETURN_IF_ERROR( | 127 | | concrete_serde->template from_decimal_strict_mode_batch<FromDataType>( | 128 | | *col_from, nullable_col_to->get_nested_column())); | 129 | | } | 130 | 2 | } else { | 131 | | // may write nulls to nullable_col_to | 132 | | if constexpr (IsDataTypeInt<FromDataType>) { | 133 | | RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>( | 134 | | *col_from, *nullable_col_to)); | 135 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 136 | | RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>( | 137 | | *col_from, *nullable_col_to)); | 138 | 2 | } else { | 139 | 2 | static_assert(IsDataTypeDecimal<FromDataType>); | 140 | 2 | RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>( | 141 | 2 | *col_from, *nullable_col_to)); | 142 | 2 | } | 143 | 2 | } | 144 | | | 145 | 2 | block.get_by_position(result).column = std::move(nullable_col_to); | 146 | 2 | return Status::OK(); | 147 | 2 | } |
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 94 | 5 | const NullMap::value_type* null_map = nullptr) const override { | 95 | 5 | const auto& named_from = block.get_by_position(arguments[0]); | 96 | 5 | if (!named_from.column) { | 97 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 98 | 0 | } | 99 | 5 | const auto* col_from = | 100 | 5 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 101 | 5 | if (!col_from) { | 102 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 103 | 0 | named_from.column->get_name()); | 104 | 0 | } | 105 | 5 | auto to_type = block.get_by_position(result).type; | 106 | 5 | auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>( | 107 | 5 | remove_nullable(to_type)->get_serde()); | 108 | | | 109 | | // by default framework, to_type is already unwrapped nullable | 110 | 5 | MutableColumnPtr column_to = to_type->create_column(); | 111 | 5 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 112 | 5 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 113 | | | 114 | | // datelike types serde must have template functions for those types. but because of they need to be | 115 | | // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before. | 116 | 5 | if constexpr (CastMode == CastModeType::StrictMode) { | 117 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 118 | 5 | if constexpr (IsDataTypeInt<FromDataType>) { | 119 | 5 | RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>( | 120 | 5 | *col_from, nullable_col_to->get_nested_column())); | 121 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 122 | | RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>( | 123 | | *col_from, nullable_col_to->get_nested_column())); | 124 | | } else { | 125 | | static_assert(IsDataTypeDecimal<FromDataType>); | 126 | | RETURN_IF_ERROR( | 127 | | concrete_serde->template from_decimal_strict_mode_batch<FromDataType>( | 128 | | *col_from, nullable_col_to->get_nested_column())); | 129 | | } | 130 | | } else { | 131 | | // may write nulls to nullable_col_to | 132 | | if constexpr (IsDataTypeInt<FromDataType>) { | 133 | | RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>( | 134 | | *col_from, *nullable_col_to)); | 135 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 136 | | RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>( | 137 | | *col_from, *nullable_col_to)); | 138 | | } else { | 139 | | static_assert(IsDataTypeDecimal<FromDataType>); | 140 | | RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>( | 141 | | *col_from, *nullable_col_to)); | 142 | | } | 143 | | } | 144 | | | 145 | 0 | block.get_by_position(result).column = std::move(nullable_col_to); | 146 | 5 | return Status::OK(); | 147 | 5 | } |
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 94 | 2 | const NullMap::value_type* null_map = nullptr) const override { | 95 | 2 | const auto& named_from = block.get_by_position(arguments[0]); | 96 | 2 | if (!named_from.column) { | 97 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 98 | 0 | } | 99 | 2 | const auto* col_from = | 100 | 2 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 101 | 2 | if (!col_from) { | 102 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 103 | 0 | named_from.column->get_name()); | 104 | 0 | } | 105 | 2 | auto to_type = block.get_by_position(result).type; | 106 | 2 | auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>( | 107 | 2 | remove_nullable(to_type)->get_serde()); | 108 | | | 109 | | // by default framework, to_type is already unwrapped nullable | 110 | 2 | MutableColumnPtr column_to = to_type->create_column(); | 111 | 2 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 112 | 2 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 113 | | | 114 | | // datelike types serde must have template functions for those types. but because of they need to be | 115 | | // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before. | 116 | | if constexpr (CastMode == CastModeType::StrictMode) { | 117 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 118 | | if constexpr (IsDataTypeInt<FromDataType>) { | 119 | | RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>( | 120 | | *col_from, nullable_col_to->get_nested_column())); | 121 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 122 | | RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>( | 123 | | *col_from, nullable_col_to->get_nested_column())); | 124 | | } else { | 125 | | static_assert(IsDataTypeDecimal<FromDataType>); | 126 | | RETURN_IF_ERROR( | 127 | | concrete_serde->template from_decimal_strict_mode_batch<FromDataType>( | 128 | | *col_from, nullable_col_to->get_nested_column())); | 129 | | } | 130 | 2 | } else { | 131 | | // may write nulls to nullable_col_to | 132 | 2 | if constexpr (IsDataTypeInt<FromDataType>) { | 133 | 2 | RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>( | 134 | 2 | *col_from, *nullable_col_to)); | 135 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 136 | | RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>( | 137 | | *col_from, *nullable_col_to)); | 138 | | } else { | 139 | | static_assert(IsDataTypeDecimal<FromDataType>); | 140 | | RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>( | 141 | | *col_from, *nullable_col_to)); | 142 | | } | 143 | 2 | } | 144 | | | 145 | 2 | block.get_by_position(result).column = std::move(nullable_col_to); | 146 | 2 | return Status::OK(); | 147 | 2 | } |
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 94 | 5 | const NullMap::value_type* null_map = nullptr) const override { | 95 | 5 | const auto& named_from = block.get_by_position(arguments[0]); | 96 | 5 | if (!named_from.column) { | 97 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 98 | 0 | } | 99 | 5 | const auto* col_from = | 100 | 5 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 101 | 5 | if (!col_from) { | 102 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 103 | 0 | named_from.column->get_name()); | 104 | 0 | } | 105 | 5 | auto to_type = block.get_by_position(result).type; | 106 | 5 | auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>( | 107 | 5 | remove_nullable(to_type)->get_serde()); | 108 | | | 109 | | // by default framework, to_type is already unwrapped nullable | 110 | 5 | MutableColumnPtr column_to = to_type->create_column(); | 111 | 5 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 112 | 5 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 113 | | | 114 | | // datelike types serde must have template functions for those types. but because of they need to be | 115 | | // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before. | 116 | 5 | if constexpr (CastMode == CastModeType::StrictMode) { | 117 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 118 | | if constexpr (IsDataTypeInt<FromDataType>) { | 119 | | RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>( | 120 | | *col_from, nullable_col_to->get_nested_column())); | 121 | 5 | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 122 | 5 | RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>( | 123 | 5 | *col_from, nullable_col_to->get_nested_column())); | 124 | | } else { | 125 | | static_assert(IsDataTypeDecimal<FromDataType>); | 126 | | RETURN_IF_ERROR( | 127 | | concrete_serde->template from_decimal_strict_mode_batch<FromDataType>( | 128 | | *col_from, nullable_col_to->get_nested_column())); | 129 | | } | 130 | | } else { | 131 | | // may write nulls to nullable_col_to | 132 | | if constexpr (IsDataTypeInt<FromDataType>) { | 133 | | RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>( | 134 | | *col_from, *nullable_col_to)); | 135 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 136 | | RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>( | 137 | | *col_from, *nullable_col_to)); | 138 | | } else { | 139 | | static_assert(IsDataTypeDecimal<FromDataType>); | 140 | | RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>( | 141 | | *col_from, *nullable_col_to)); | 142 | | } | 143 | | } | 144 | | | 145 | 0 | block.get_by_position(result).column = std::move(nullable_col_to); | 146 | 5 | return Status::OK(); | 147 | 5 | } |
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 94 | 2 | const NullMap::value_type* null_map = nullptr) const override { | 95 | 2 | const auto& named_from = block.get_by_position(arguments[0]); | 96 | 2 | if (!named_from.column) { | 97 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 98 | 0 | } | 99 | 2 | const auto* col_from = | 100 | 2 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 101 | 2 | if (!col_from) { | 102 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 103 | 0 | named_from.column->get_name()); | 104 | 0 | } | 105 | 2 | auto to_type = block.get_by_position(result).type; | 106 | 2 | auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>( | 107 | 2 | remove_nullable(to_type)->get_serde()); | 108 | | | 109 | | // by default framework, to_type is already unwrapped nullable | 110 | 2 | MutableColumnPtr column_to = to_type->create_column(); | 111 | 2 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 112 | 2 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 113 | | | 114 | | // datelike types serde must have template functions for those types. but because of they need to be | 115 | | // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before. | 116 | | if constexpr (CastMode == CastModeType::StrictMode) { | 117 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 118 | | if constexpr (IsDataTypeInt<FromDataType>) { | 119 | | RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>( | 120 | | *col_from, nullable_col_to->get_nested_column())); | 121 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 122 | | RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>( | 123 | | *col_from, nullable_col_to->get_nested_column())); | 124 | | } else { | 125 | | static_assert(IsDataTypeDecimal<FromDataType>); | 126 | | RETURN_IF_ERROR( | 127 | | concrete_serde->template from_decimal_strict_mode_batch<FromDataType>( | 128 | | *col_from, nullable_col_to->get_nested_column())); | 129 | | } | 130 | 2 | } else { | 131 | | // may write nulls to nullable_col_to | 132 | | if constexpr (IsDataTypeInt<FromDataType>) { | 133 | | RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>( | 134 | | *col_from, *nullable_col_to)); | 135 | 2 | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 136 | 2 | RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>( | 137 | 2 | *col_from, *nullable_col_to)); | 138 | | } else { | 139 | | static_assert(IsDataTypeDecimal<FromDataType>); | 140 | | RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>( | 141 | | *col_from, *nullable_col_to)); | 142 | | } | 143 | 2 | } | 144 | | | 145 | 2 | block.get_by_position(result).column = std::move(nullable_col_to); | 146 | 2 | return Status::OK(); | 147 | 2 | } |
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 94 | 1 | const NullMap::value_type* null_map = nullptr) const override { | 95 | 1 | const auto& named_from = block.get_by_position(arguments[0]); | 96 | 1 | if (!named_from.column) { | 97 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 98 | 0 | } | 99 | 1 | const auto* col_from = | 100 | 1 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 101 | 1 | if (!col_from) { | 102 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 103 | 0 | named_from.column->get_name()); | 104 | 0 | } | 105 | 1 | auto to_type = block.get_by_position(result).type; | 106 | 1 | auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>( | 107 | 1 | remove_nullable(to_type)->get_serde()); | 108 | | | 109 | | // by default framework, to_type is already unwrapped nullable | 110 | 1 | MutableColumnPtr column_to = to_type->create_column(); | 111 | 1 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 112 | 1 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 113 | | | 114 | | // datelike types serde must have template functions for those types. but because of they need to be | 115 | | // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before. | 116 | 1 | if constexpr (CastMode == CastModeType::StrictMode) { | 117 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 118 | | if constexpr (IsDataTypeInt<FromDataType>) { | 119 | | RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>( | 120 | | *col_from, nullable_col_to->get_nested_column())); | 121 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 122 | | RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>( | 123 | | *col_from, nullable_col_to->get_nested_column())); | 124 | 1 | } else { | 125 | 1 | static_assert(IsDataTypeDecimal<FromDataType>); | 126 | 1 | RETURN_IF_ERROR( | 127 | 1 | concrete_serde->template from_decimal_strict_mode_batch<FromDataType>( | 128 | 1 | *col_from, nullable_col_to->get_nested_column())); | 129 | 1 | } | 130 | | } else { | 131 | | // may write nulls to nullable_col_to | 132 | | if constexpr (IsDataTypeInt<FromDataType>) { | 133 | | RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>( | 134 | | *col_from, *nullable_col_to)); | 135 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 136 | | RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>( | 137 | | *col_from, *nullable_col_to)); | 138 | | } else { | 139 | | static_assert(IsDataTypeDecimal<FromDataType>); | 140 | | RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>( | 141 | | *col_from, *nullable_col_to)); | 142 | | } | 143 | | } | 144 | | | 145 | 0 | block.get_by_position(result).column = std::move(nullable_col_to); | 146 | 1 | return Status::OK(); | 147 | 1 | } |
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 94 | 3 | const NullMap::value_type* null_map = nullptr) const override { | 95 | 3 | const auto& named_from = block.get_by_position(arguments[0]); | 96 | 3 | if (!named_from.column) { | 97 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 98 | 0 | } | 99 | 3 | const auto* col_from = | 100 | 3 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 101 | 3 | if (!col_from) { | 102 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 103 | 0 | named_from.column->get_name()); | 104 | 0 | } | 105 | 3 | auto to_type = block.get_by_position(result).type; | 106 | 3 | auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>( | 107 | 3 | remove_nullable(to_type)->get_serde()); | 108 | | | 109 | | // by default framework, to_type is already unwrapped nullable | 110 | 3 | MutableColumnPtr column_to = to_type->create_column(); | 111 | 3 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 112 | 3 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 113 | | | 114 | | // datelike types serde must have template functions for those types. but because of they need to be | 115 | | // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before. | 116 | | if constexpr (CastMode == CastModeType::StrictMode) { | 117 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 118 | | if constexpr (IsDataTypeInt<FromDataType>) { | 119 | | RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>( | 120 | | *col_from, nullable_col_to->get_nested_column())); | 121 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 122 | | RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>( | 123 | | *col_from, nullable_col_to->get_nested_column())); | 124 | | } else { | 125 | | static_assert(IsDataTypeDecimal<FromDataType>); | 126 | | RETURN_IF_ERROR( | 127 | | concrete_serde->template from_decimal_strict_mode_batch<FromDataType>( | 128 | | *col_from, nullable_col_to->get_nested_column())); | 129 | | } | 130 | 3 | } else { | 131 | | // may write nulls to nullable_col_to | 132 | | if constexpr (IsDataTypeInt<FromDataType>) { | 133 | | RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>( | 134 | | *col_from, *nullable_col_to)); | 135 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 136 | | RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>( | 137 | | *col_from, *nullable_col_to)); | 138 | 3 | } else { | 139 | 3 | static_assert(IsDataTypeDecimal<FromDataType>); | 140 | 3 | RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>( | 141 | 3 | *col_from, *nullable_col_to)); | 142 | 3 | } | 143 | 3 | } | 144 | | | 145 | 3 | block.get_by_position(result).column = std::move(nullable_col_to); | 146 | 3 | return Status::OK(); | 147 | 3 | } |
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 94 | 1 | const NullMap::value_type* null_map = nullptr) const override { | 95 | 1 | const auto& named_from = block.get_by_position(arguments[0]); | 96 | 1 | if (!named_from.column) { | 97 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 98 | 0 | } | 99 | 1 | const auto* col_from = | 100 | 1 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 101 | 1 | if (!col_from) { | 102 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 103 | 0 | named_from.column->get_name()); | 104 | 0 | } | 105 | 1 | auto to_type = block.get_by_position(result).type; | 106 | 1 | auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>( | 107 | 1 | remove_nullable(to_type)->get_serde()); | 108 | | | 109 | | // by default framework, to_type is already unwrapped nullable | 110 | 1 | MutableColumnPtr column_to = to_type->create_column(); | 111 | 1 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 112 | 1 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 113 | | | 114 | | // datelike types serde must have template functions for those types. but because of they need to be | 115 | | // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before. | 116 | | if constexpr (CastMode == CastModeType::StrictMode) { | 117 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 118 | | if constexpr (IsDataTypeInt<FromDataType>) { | 119 | | RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>( | 120 | | *col_from, nullable_col_to->get_nested_column())); | 121 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 122 | | RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>( | 123 | | *col_from, nullable_col_to->get_nested_column())); | 124 | | } else { | 125 | | static_assert(IsDataTypeDecimal<FromDataType>); | 126 | | RETURN_IF_ERROR( | 127 | | concrete_serde->template from_decimal_strict_mode_batch<FromDataType>( | 128 | | *col_from, nullable_col_to->get_nested_column())); | 129 | | } | 130 | 1 | } else { | 131 | | // may write nulls to nullable_col_to | 132 | 1 | if constexpr (IsDataTypeInt<FromDataType>) { | 133 | 1 | RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>( | 134 | 1 | *col_from, *nullable_col_to)); | 135 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 136 | | RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>( | 137 | | *col_from, *nullable_col_to)); | 138 | | } else { | 139 | | static_assert(IsDataTypeDecimal<FromDataType>); | 140 | | RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>( | 141 | | *col_from, *nullable_col_to)); | 142 | | } | 143 | 1 | } | 144 | | | 145 | 1 | block.get_by_position(result).column = std::move(nullable_col_to); | 146 | 1 | return Status::OK(); | 147 | 1 | } |
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 94 | 1 | const NullMap::value_type* null_map = nullptr) const override { | 95 | 1 | const auto& named_from = block.get_by_position(arguments[0]); | 96 | 1 | if (!named_from.column) { | 97 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 98 | 0 | } | 99 | 1 | const auto* col_from = | 100 | 1 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 101 | 1 | if (!col_from) { | 102 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 103 | 0 | named_from.column->get_name()); | 104 | 0 | } | 105 | 1 | auto to_type = block.get_by_position(result).type; | 106 | 1 | auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>( | 107 | 1 | remove_nullable(to_type)->get_serde()); | 108 | | | 109 | | // by default framework, to_type is already unwrapped nullable | 110 | 1 | MutableColumnPtr column_to = to_type->create_column(); | 111 | 1 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 112 | 1 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 113 | | | 114 | | // datelike types serde must have template functions for those types. but because of they need to be | 115 | | // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before. | 116 | | if constexpr (CastMode == CastModeType::StrictMode) { | 117 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 118 | | if constexpr (IsDataTypeInt<FromDataType>) { | 119 | | RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>( | 120 | | *col_from, nullable_col_to->get_nested_column())); | 121 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 122 | | RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>( | 123 | | *col_from, nullable_col_to->get_nested_column())); | 124 | | } else { | 125 | | static_assert(IsDataTypeDecimal<FromDataType>); | 126 | | RETURN_IF_ERROR( | 127 | | concrete_serde->template from_decimal_strict_mode_batch<FromDataType>( | 128 | | *col_from, nullable_col_to->get_nested_column())); | 129 | | } | 130 | 1 | } else { | 131 | | // may write nulls to nullable_col_to | 132 | | if constexpr (IsDataTypeInt<FromDataType>) { | 133 | | RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>( | 134 | | *col_from, *nullable_col_to)); | 135 | 1 | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 136 | 1 | RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>( | 137 | 1 | *col_from, *nullable_col_to)); | 138 | | } else { | 139 | | static_assert(IsDataTypeDecimal<FromDataType>); | 140 | | RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>( | 141 | | *col_from, *nullable_col_to)); | 142 | | } | 143 | 1 | } | 144 | | | 145 | 1 | block.get_by_position(result).column = std::move(nullable_col_to); | 146 | 1 | return Status::OK(); | 147 | 1 | } |
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 94 | 1 | const NullMap::value_type* null_map = nullptr) const override { | 95 | 1 | const auto& named_from = block.get_by_position(arguments[0]); | 96 | 1 | if (!named_from.column) { | 97 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 98 | 0 | } | 99 | 1 | const auto* col_from = | 100 | 1 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 101 | 1 | if (!col_from) { | 102 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 103 | 0 | named_from.column->get_name()); | 104 | 0 | } | 105 | 1 | auto to_type = block.get_by_position(result).type; | 106 | 1 | auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>( | 107 | 1 | remove_nullable(to_type)->get_serde()); | 108 | | | 109 | | // by default framework, to_type is already unwrapped nullable | 110 | 1 | MutableColumnPtr column_to = to_type->create_column(); | 111 | 1 | ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create( | 112 | 1 | std::move(column_to), ColumnUInt8::create(input_rows_count, 0)); | 113 | | | 114 | | // datelike types serde must have template functions for those types. but because of they need to be | 115 | | // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before. | 116 | | if constexpr (CastMode == CastModeType::StrictMode) { | 117 | | // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows | 118 | | if constexpr (IsDataTypeInt<FromDataType>) { | 119 | | RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>( | 120 | | *col_from, nullable_col_to->get_nested_column())); | 121 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 122 | | RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>( | 123 | | *col_from, nullable_col_to->get_nested_column())); | 124 | | } else { | 125 | | static_assert(IsDataTypeDecimal<FromDataType>); | 126 | | RETURN_IF_ERROR( | 127 | | concrete_serde->template from_decimal_strict_mode_batch<FromDataType>( | 128 | | *col_from, nullable_col_to->get_nested_column())); | 129 | | } | 130 | 1 | } else { | 131 | | // may write nulls to nullable_col_to | 132 | | if constexpr (IsDataTypeInt<FromDataType>) { | 133 | | RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>( | 134 | | *col_from, *nullable_col_to)); | 135 | | } else if constexpr (IsDataTypeFloat<FromDataType>) { | 136 | | RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>( | 137 | | *col_from, *nullable_col_to)); | 138 | 1 | } else { | 139 | 1 | static_assert(IsDataTypeDecimal<FromDataType>); | 140 | 1 | RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>( | 141 | 1 | *col_from, *nullable_col_to)); | 142 | 1 | } | 143 | 1 | } | 144 | | | 145 | 1 | block.get_by_position(result).column = std::move(nullable_col_to); | 146 | 1 | return Status::OK(); | 147 | 1 | } |
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh |
148 | | }; |
149 | | |
150 | | template <CastModeType CastMode, typename FromDataType, typename ToDataType> |
151 | | requires(IsDatelikeTypes<FromDataType> && IsDatelikeTypes<ToDataType>) |
152 | | class CastToImpl<CastMode, FromDataType, ToDataType> : public CastToBase { |
153 | | public: |
154 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
155 | | uint32_t result, size_t input_rows_count, |
156 | 9 | const NullMap::value_type* null_map = nullptr) const override { |
157 | 9 | constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> && |
158 | 9 | (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>); |
159 | | |
160 | 9 | const auto& named_from = block.get_by_position(arguments[0]); |
161 | 9 | if (!named_from.column) { |
162 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); |
163 | 0 | } |
164 | 9 | const auto* col_from = |
165 | 9 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); |
166 | 9 | if (!col_from) { |
167 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", |
168 | 0 | named_from.column->get_name()); |
169 | 0 | } |
170 | 9 | auto col_to = ToDataType::ColumnType::create(input_rows_count); |
171 | 9 | ColumnUInt8::MutablePtr col_nullmap; |
172 | | |
173 | 9 | if constexpr (Nullable) { |
174 | 0 | col_nullmap = ColumnUInt8::create(input_rows_count, 0); |
175 | 0 | } |
176 | | |
177 | 34 | for (size_t i = 0; i < input_rows_count; ++i) { |
178 | 25 | if (null_map && null_map[i]) { |
179 | 8 | continue; |
180 | 8 | } |
181 | 17 | if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) { |
182 | | // from Date to Date |
183 | 0 | auto dtv1 = col_from->get_data()[i]; |
184 | 0 | dtv1.cast_to_date(); |
185 | 0 | col_to->get_data()[i] = |
186 | 0 | binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2()); |
187 | 0 | } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) { |
188 | 0 | DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]); |
189 | 0 | } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) { |
190 | | // from Datetime to Date |
191 | 0 | col_to->get_data()[i] = col_from->get_data()[i]; |
192 | 0 | DataTypeDate::cast_to_date(col_to->get_data()[i]); |
193 | 0 | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) { |
194 | 0 | DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]); |
195 | 0 | } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) { |
196 | 0 | auto dtmv1 = col_from->get_data()[i]; |
197 | 0 | col_to->get_data()[i] = |
198 | 0 | binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2()); |
199 | 2 | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) { |
200 | 2 | DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]); |
201 | 2 | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) { |
202 | | // from Time to Date |
203 | 0 | VecDateTimeValue dtv; |
204 | 0 | dtv.cast_to_date(); |
205 | 0 | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, |
206 | 0 | context->state()->timezone_obj()); |
207 | |
|
208 | 0 | auto time_value = col_from->get_data()[i]; |
209 | 0 | int32_t hour = TimeValue::hour(time_value); |
210 | 0 | int32_t minute = TimeValue::minute(time_value); |
211 | 0 | int32_t second = TimeValue::second(time_value); |
212 | 0 | bool neg = TimeValue::sign(time_value) < 0; |
213 | |
|
214 | 0 | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); |
215 | 0 | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); |
216 | 0 | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); |
217 | |
|
218 | 0 | col_to->get_data()[i] = dtv; |
219 | 6 | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) { |
220 | 6 | DateV2Value<DateV2ValueType> dtv; |
221 | 6 | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, |
222 | 6 | context->state()->timezone_obj()); |
223 | | |
224 | 6 | auto time_value = col_from->get_data()[i]; |
225 | 6 | int32_t hour = TimeValue::hour(time_value); |
226 | 6 | int32_t minute = TimeValue::minute(time_value); |
227 | 6 | int32_t second = TimeValue::second(time_value); |
228 | 6 | bool neg = TimeValue::sign(time_value) < 0; |
229 | | |
230 | 6 | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); |
231 | 6 | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); |
232 | 6 | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); |
233 | | |
234 | 6 | col_to->get_data()[i] = dtv; |
235 | 6 | } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) { |
236 | | // from Date to Datetime |
237 | 0 | col_to->get_data()[i] = col_from->get_data()[i]; |
238 | 0 | DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]); |
239 | 0 | } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) { |
240 | 0 | DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]); |
241 | 0 | } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) { |
242 | 0 | auto dtv1 = col_from->get_data()[i]; |
243 | 0 | col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( |
244 | 0 | dtv1.to_datetime_v2()); |
245 | 2 | } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { |
246 | 2 | DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i], |
247 | 2 | col_to->get_data()[i]); |
248 | 2 | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) { |
249 | | // from Time to Datetime |
250 | 0 | VecDateTimeValue dtv; // datetime by default |
251 | 0 | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, |
252 | 0 | context->state()->timezone_obj()); |
253 | 0 | dtv.reset_time_part(); |
254 | |
|
255 | 0 | auto time_value = col_from->get_data()[i]; |
256 | 0 | int32_t hour = TimeValue::hour(time_value); |
257 | 0 | int32_t minute = TimeValue::minute(time_value); |
258 | 0 | int32_t second = TimeValue::second(time_value); |
259 | 0 | bool neg = TimeValue::sign(time_value) < 0; |
260 | |
|
261 | 0 | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); |
262 | 0 | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); |
263 | 0 | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); |
264 | |
|
265 | 0 | col_to->get_data()[i] = dtv; |
266 | 6 | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { |
267 | 6 | const auto* type = assert_cast<const DataTypeTimeV2*>( |
268 | 6 | block.get_by_position(arguments[0]).type.get()); |
269 | 6 | auto scale = type->get_scale(); |
270 | | |
271 | 6 | DateV2Value<DateTimeV2ValueType> dtmv2; |
272 | 6 | dtmv2.from_unixtime(context->state()->timestamp_ms() / 1000, |
273 | 6 | context->state()->nano_seconds(), |
274 | 6 | context->state()->timezone_obj(), scale); |
275 | 6 | dtmv2.reset_time_part(); |
276 | | |
277 | 6 | auto time_value = col_from->get_data()[i]; |
278 | 6 | int32_t hour = TimeValue::hour(time_value); |
279 | 6 | int32_t minute = TimeValue::minute(time_value); |
280 | 6 | int32_t second = TimeValue::second(time_value); |
281 | 6 | int32_t microsecond = TimeValue::microsecond(time_value); |
282 | 6 | bool neg = TimeValue::sign(time_value) < 0; |
283 | | |
284 | 6 | dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); |
285 | 6 | dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); |
286 | 6 | dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); |
287 | 6 | dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>( |
288 | 6 | TimeInterval(MICROSECOND, microsecond, neg)); |
289 | | |
290 | 6 | col_to->get_data()[i] = dtmv2; |
291 | 6 | } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) { |
292 | | // from Datetime to Datetime |
293 | 0 | auto dtmv1 = col_from->get_data()[i]; |
294 | 0 | col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( |
295 | 0 | dtmv1.to_datetime_v2()); |
296 | 0 | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) { |
297 | 0 | DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i], |
298 | 0 | col_to->get_data()[i]); |
299 | 0 | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { |
300 | 0 | const auto* type = assert_cast<const DataTypeDateTimeV2*>( |
301 | 0 | block.get_by_position(arguments[0]).type.get()); |
302 | 0 | auto scale = type->get_scale(); |
303 | |
|
304 | 0 | const auto* to_type = assert_cast<const DataTypeDateTimeV2*>( |
305 | 0 | block.get_by_position(result).type.get()); |
306 | 0 | UInt32 to_scale = to_type->get_scale(); |
307 | |
|
308 | 0 | bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i], |
309 | 0 | col_from->get_data()[i]); |
310 | 0 | if (!success) { |
311 | 0 | if constexpr (CastMode == CastModeType::StrictMode) { |
312 | 0 | auto format_options = DataTypeSerDe::get_default_format_options(); |
313 | 0 | auto time_zone = cctz::utc_time_zone(); |
314 | 0 | format_options.timezone = (context && context->state()) |
315 | 0 | ? &context->state()->timezone_obj() |
316 | 0 | : &time_zone; |
317 | 0 | return Status::InvalidArgument( |
318 | 0 | "DatetimeV2 overflow when casting {} from {} to {}", |
319 | 0 | type->to_string(*col_from, i, format_options), type->get_name(), |
320 | 0 | to_type->get_name()); |
321 | 0 | } else { |
322 | 0 | col_nullmap->get_data()[i] = true; |
323 | | //TODO: maybe we can remove all set operations on nested of null cell. |
324 | | // the correctness should be keep by downstream user with replace_... or manually |
325 | | // process null data if need. |
326 | 0 | col_to->get_data()[i] = |
327 | 0 | binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( |
328 | 0 | MIN_DATETIME_V2); |
329 | 0 | } |
330 | 0 | } |
331 | |
|
332 | 0 | } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) { |
333 | 0 | const auto* type = assert_cast<const DataTypeTimeV2*>( |
334 | 0 | block.get_by_position(arguments[0]).type.get()); |
335 | 0 | auto scale = type->get_scale(); |
336 | |
|
337 | 0 | const auto* to_type = assert_cast<const DataTypeTimeV2*>( |
338 | 0 | block.get_by_position(result).type.get()); |
339 | 0 | UInt32 to_scale = to_type->get_scale(); |
340 | |
|
341 | 0 | if (to_scale >= scale) { |
342 | | // nothing to do, just copy |
343 | 0 | col_to->get_data()[i] = col_from->get_data()[i]; |
344 | 0 | } else { |
345 | 0 | double time = col_from->get_data()[i]; |
346 | 0 | auto sign = TimeValue::sign(time); |
347 | 0 | time = std::abs(time); |
348 | | // e.g. scale reduce to 4, means we need to round the last 2 digits |
349 | | // 999956: 56 > 100/2, then round up to 1000000 |
350 | 0 | uint32_t microseconds = TimeValue::microsecond(time); |
351 | 0 | auto divisor = (uint32_t)common::exp10_i64(6 - to_scale); |
352 | 0 | uint32_t remainder = microseconds % divisor; |
353 | |
|
354 | 0 | if (remainder >= divisor / 2) { // need to round up |
355 | | // do rounding up |
356 | 0 | uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor; |
357 | | // need carry on |
358 | 0 | if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) { |
359 | 0 | DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS); |
360 | 0 | time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) * |
361 | 0 | TimeValue::ONE_SECOND_MICROSECONDS; |
362 | | |
363 | | // the input data must be valid, so max to '838:59:59.0'. this value won't carry on |
364 | | // to second. |
365 | 0 | DCHECK(TimeValue::valid(time)) << col_from->get_data()[i]; |
366 | 0 | } else { |
367 | 0 | time = TimeValue::reset_microsecond(time, rounded_microseconds); |
368 | 0 | } |
369 | 0 | } else { |
370 | | // truncate |
371 | 0 | time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor); |
372 | 0 | } |
373 | 0 | col_to->get_data()[i] = sign * time; |
374 | 0 | } |
375 | 1 | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) { |
376 | | // from Datetime to Time |
377 | 1 | auto dtmv2 = col_from->get_data()[i]; |
378 | | |
379 | 1 | const auto* type = assert_cast<const DataTypeDateTimeV2*>( |
380 | 1 | block.get_by_position(arguments[0]).type.get()); |
381 | 1 | auto scale = type->get_scale(); |
382 | 1 | const auto* to_type = assert_cast<const DataTypeTimeV2*>( |
383 | 1 | block.get_by_position(result).type.get()); |
384 | 1 | UInt32 to_scale = to_type->get_scale(); |
385 | | |
386 | 1 | uint32_t hour = dtmv2.hour(); |
387 | 1 | uint32_t minute = dtmv2.minute(); |
388 | 1 | uint32_t second = dtmv2.second(); |
389 | 1 | uint32_t microseconds = dtmv2.microsecond(); |
390 | 1 | if (to_scale < scale) { // need to round |
391 | | // e.g. scale reduce to 4, means we need to round the last 2 digits |
392 | | // 999956: 56 > 100/2, then round up to 1000000 |
393 | 1 | DCHECK(to_scale <= 6) |
394 | 0 | << "to_scale should be in range [0, 6], but got " << to_scale; |
395 | 1 | auto divisor = (uint32_t)common::exp10_i64(6 - to_scale); |
396 | 1 | uint32_t remainder = microseconds % divisor; |
397 | 1 | microseconds = (microseconds / divisor) * divisor; |
398 | 1 | if (remainder >= divisor / 2) { |
399 | | // do rounding up |
400 | 1 | microseconds += divisor; |
401 | 1 | } |
402 | 1 | } |
403 | | |
404 | | // carry on if microseconds >= 1000000 |
405 | 1 | if (microseconds >= 1000000) { |
406 | 0 | microseconds -= 1000000; |
407 | 0 | second += 1; |
408 | 0 | if (second >= 60) { |
409 | 0 | second -= 60; |
410 | 0 | minute += 1; |
411 | 0 | if (minute >= 60) { |
412 | 0 | minute -= 60; |
413 | 0 | hour += 1; |
414 | 0 | } |
415 | 0 | } |
416 | 0 | } |
417 | | |
418 | 1 | auto time = TimeValue::limit_with_bound( |
419 | 1 | TimeValue::make_time(hour, minute, second, microseconds)); |
420 | 1 | col_to->get_data()[i] = time; |
421 | 1 | } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) { |
422 | 0 | auto dtmv1 = col_from->get_data()[i]; |
423 | 0 | auto time = TimeValue::limit_with_bound( |
424 | 0 | TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second())); |
425 | 0 | col_to->get_data()[i] = time; |
426 | 0 | } |
427 | 17 | } |
428 | | |
429 | 9 | if constexpr (Nullable) { |
430 | 0 | block.get_by_position(result).column = |
431 | 0 | ColumnNullable::create(std::move(col_to), std::move(col_nullmap)); |
432 | 9 | } else { |
433 | 9 | block.get_by_position(result).column = std::move(col_to); |
434 | 9 | } |
435 | 9 | return Status::OK(); |
436 | 9 | } Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_12DataTypeDateES2_E12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_12DataTypeDateES2_E12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeDateV2ENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeDateV2ENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_18DataTypeDateTimeV2ENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_18DataTypeDateTimeV2ENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_16DataTypeDateTimeENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_16DataTypeDateTimeENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeTimeV2ENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeTimeV2ENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_12DataTypeDateENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_12DataTypeDateENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeDateV2ENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeDateV2ENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_18DataTypeDateTimeV2ENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_18DataTypeDateTimeV2ENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_16DataTypeDateTimeES2_E12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_16DataTypeDateTimeES2_E12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeTimeV2ENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeTimeV2ENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_12DataTypeDateENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_12DataTypeDateENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeDateV2ES2_E12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeDateV2ES2_E12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_18DataTypeDateTimeV2ENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_18DataTypeDateTimeV2ENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 156 | 2 | const NullMap::value_type* null_map = nullptr) const override { | 157 | 2 | constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> && | 158 | 2 | (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>); | 159 | | | 160 | 2 | const auto& named_from = block.get_by_position(arguments[0]); | 161 | 2 | if (!named_from.column) { | 162 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 163 | 0 | } | 164 | 2 | const auto* col_from = | 165 | 2 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 166 | 2 | if (!col_from) { | 167 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 168 | 0 | named_from.column->get_name()); | 169 | 0 | } | 170 | 2 | auto col_to = ToDataType::ColumnType::create(input_rows_count); | 171 | 2 | ColumnUInt8::MutablePtr col_nullmap; | 172 | | | 173 | | if constexpr (Nullable) { | 174 | | col_nullmap = ColumnUInt8::create(input_rows_count, 0); | 175 | | } | 176 | | | 177 | 6 | for (size_t i = 0; i < input_rows_count; ++i) { | 178 | 4 | if (null_map && null_map[i]) { | 179 | 2 | continue; | 180 | 2 | } | 181 | | if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) { | 182 | | // from Date to Date | 183 | | auto dtv1 = col_from->get_data()[i]; | 184 | | dtv1.cast_to_date(); | 185 | | col_to->get_data()[i] = | 186 | | binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2()); | 187 | | } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) { | 188 | | DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]); | 189 | | } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) { | 190 | | // from Datetime to Date | 191 | | col_to->get_data()[i] = col_from->get_data()[i]; | 192 | | DataTypeDate::cast_to_date(col_to->get_data()[i]); | 193 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) { | 194 | | DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]); | 195 | | } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) { | 196 | | auto dtmv1 = col_from->get_data()[i]; | 197 | | col_to->get_data()[i] = | 198 | | binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2()); | 199 | 2 | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) { | 200 | 2 | DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]); | 201 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) { | 202 | | // from Time to Date | 203 | | VecDateTimeValue dtv; | 204 | | dtv.cast_to_date(); | 205 | | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, | 206 | | context->state()->timezone_obj()); | 207 | | | 208 | | auto time_value = col_from->get_data()[i]; | 209 | | int32_t hour = TimeValue::hour(time_value); | 210 | | int32_t minute = TimeValue::minute(time_value); | 211 | | int32_t second = TimeValue::second(time_value); | 212 | | bool neg = TimeValue::sign(time_value) < 0; | 213 | | | 214 | | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 215 | | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 216 | | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 217 | | | 218 | | col_to->get_data()[i] = dtv; | 219 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) { | 220 | | DateV2Value<DateV2ValueType> dtv; | 221 | | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, | 222 | | context->state()->timezone_obj()); | 223 | | | 224 | | auto time_value = col_from->get_data()[i]; | 225 | | int32_t hour = TimeValue::hour(time_value); | 226 | | int32_t minute = TimeValue::minute(time_value); | 227 | | int32_t second = TimeValue::second(time_value); | 228 | | bool neg = TimeValue::sign(time_value) < 0; | 229 | | | 230 | | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 231 | | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 232 | | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 233 | | | 234 | | col_to->get_data()[i] = dtv; | 235 | | } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) { | 236 | | // from Date to Datetime | 237 | | col_to->get_data()[i] = col_from->get_data()[i]; | 238 | | DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]); | 239 | | } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) { | 240 | | DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]); | 241 | | } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 242 | | auto dtv1 = col_from->get_data()[i]; | 243 | | col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( | 244 | | dtv1.to_datetime_v2()); | 245 | | } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 246 | | DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i], | 247 | | col_to->get_data()[i]); | 248 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) { | 249 | | // from Time to Datetime | 250 | | VecDateTimeValue dtv; // datetime by default | 251 | | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, | 252 | | context->state()->timezone_obj()); | 253 | | dtv.reset_time_part(); | 254 | | | 255 | | auto time_value = col_from->get_data()[i]; | 256 | | int32_t hour = TimeValue::hour(time_value); | 257 | | int32_t minute = TimeValue::minute(time_value); | 258 | | int32_t second = TimeValue::second(time_value); | 259 | | bool neg = TimeValue::sign(time_value) < 0; | 260 | | | 261 | | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 262 | | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 263 | | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 264 | | | 265 | | col_to->get_data()[i] = dtv; | 266 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 267 | | const auto* type = assert_cast<const DataTypeTimeV2*>( | 268 | | block.get_by_position(arguments[0]).type.get()); | 269 | | auto scale = type->get_scale(); | 270 | | | 271 | | DateV2Value<DateTimeV2ValueType> dtmv2; | 272 | | dtmv2.from_unixtime(context->state()->timestamp_ms() / 1000, | 273 | | context->state()->nano_seconds(), | 274 | | context->state()->timezone_obj(), scale); | 275 | | dtmv2.reset_time_part(); | 276 | | | 277 | | auto time_value = col_from->get_data()[i]; | 278 | | int32_t hour = TimeValue::hour(time_value); | 279 | | int32_t minute = TimeValue::minute(time_value); | 280 | | int32_t second = TimeValue::second(time_value); | 281 | | int32_t microsecond = TimeValue::microsecond(time_value); | 282 | | bool neg = TimeValue::sign(time_value) < 0; | 283 | | | 284 | | dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 285 | | dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 286 | | dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 287 | | dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>( | 288 | | TimeInterval(MICROSECOND, microsecond, neg)); | 289 | | | 290 | | col_to->get_data()[i] = dtmv2; | 291 | | } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 292 | | // from Datetime to Datetime | 293 | | auto dtmv1 = col_from->get_data()[i]; | 294 | | col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( | 295 | | dtmv1.to_datetime_v2()); | 296 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) { | 297 | | DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i], | 298 | | col_to->get_data()[i]); | 299 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 300 | | const auto* type = assert_cast<const DataTypeDateTimeV2*>( | 301 | | block.get_by_position(arguments[0]).type.get()); | 302 | | auto scale = type->get_scale(); | 303 | | | 304 | | const auto* to_type = assert_cast<const DataTypeDateTimeV2*>( | 305 | | block.get_by_position(result).type.get()); | 306 | | UInt32 to_scale = to_type->get_scale(); | 307 | | | 308 | | bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i], | 309 | | col_from->get_data()[i]); | 310 | | if (!success) { | 311 | | if constexpr (CastMode == CastModeType::StrictMode) { | 312 | | auto format_options = DataTypeSerDe::get_default_format_options(); | 313 | | auto time_zone = cctz::utc_time_zone(); | 314 | | format_options.timezone = (context && context->state()) | 315 | | ? &context->state()->timezone_obj() | 316 | | : &time_zone; | 317 | | return Status::InvalidArgument( | 318 | | "DatetimeV2 overflow when casting {} from {} to {}", | 319 | | type->to_string(*col_from, i, format_options), type->get_name(), | 320 | | to_type->get_name()); | 321 | | } else { | 322 | | col_nullmap->get_data()[i] = true; | 323 | | //TODO: maybe we can remove all set operations on nested of null cell. | 324 | | // the correctness should be keep by downstream user with replace_... or manually | 325 | | // process null data if need. | 326 | | col_to->get_data()[i] = | 327 | | binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( | 328 | | MIN_DATETIME_V2); | 329 | | } | 330 | | } | 331 | | | 332 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) { | 333 | | const auto* type = assert_cast<const DataTypeTimeV2*>( | 334 | | block.get_by_position(arguments[0]).type.get()); | 335 | | auto scale = type->get_scale(); | 336 | | | 337 | | const auto* to_type = assert_cast<const DataTypeTimeV2*>( | 338 | | block.get_by_position(result).type.get()); | 339 | | UInt32 to_scale = to_type->get_scale(); | 340 | | | 341 | | if (to_scale >= scale) { | 342 | | // nothing to do, just copy | 343 | | col_to->get_data()[i] = col_from->get_data()[i]; | 344 | | } else { | 345 | | double time = col_from->get_data()[i]; | 346 | | auto sign = TimeValue::sign(time); | 347 | | time = std::abs(time); | 348 | | // e.g. scale reduce to 4, means we need to round the last 2 digits | 349 | | // 999956: 56 > 100/2, then round up to 1000000 | 350 | | uint32_t microseconds = TimeValue::microsecond(time); | 351 | | auto divisor = (uint32_t)common::exp10_i64(6 - to_scale); | 352 | | uint32_t remainder = microseconds % divisor; | 353 | | | 354 | | if (remainder >= divisor / 2) { // need to round up | 355 | | // do rounding up | 356 | | uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor; | 357 | | // need carry on | 358 | | if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) { | 359 | | DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS); | 360 | | time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) * | 361 | | TimeValue::ONE_SECOND_MICROSECONDS; | 362 | | | 363 | | // the input data must be valid, so max to '838:59:59.0'. this value won't carry on | 364 | | // to second. | 365 | | DCHECK(TimeValue::valid(time)) << col_from->get_data()[i]; | 366 | | } else { | 367 | | time = TimeValue::reset_microsecond(time, rounded_microseconds); | 368 | | } | 369 | | } else { | 370 | | // truncate | 371 | | time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor); | 372 | | } | 373 | | col_to->get_data()[i] = sign * time; | 374 | | } | 375 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) { | 376 | | // from Datetime to Time | 377 | | auto dtmv2 = col_from->get_data()[i]; | 378 | | | 379 | | const auto* type = assert_cast<const DataTypeDateTimeV2*>( | 380 | | block.get_by_position(arguments[0]).type.get()); | 381 | | auto scale = type->get_scale(); | 382 | | const auto* to_type = assert_cast<const DataTypeTimeV2*>( | 383 | | block.get_by_position(result).type.get()); | 384 | | UInt32 to_scale = to_type->get_scale(); | 385 | | | 386 | | uint32_t hour = dtmv2.hour(); | 387 | | uint32_t minute = dtmv2.minute(); | 388 | | uint32_t second = dtmv2.second(); | 389 | | uint32_t microseconds = dtmv2.microsecond(); | 390 | | if (to_scale < scale) { // need to round | 391 | | // e.g. scale reduce to 4, means we need to round the last 2 digits | 392 | | // 999956: 56 > 100/2, then round up to 1000000 | 393 | | DCHECK(to_scale <= 6) | 394 | | << "to_scale should be in range [0, 6], but got " << to_scale; | 395 | | auto divisor = (uint32_t)common::exp10_i64(6 - to_scale); | 396 | | uint32_t remainder = microseconds % divisor; | 397 | | microseconds = (microseconds / divisor) * divisor; | 398 | | if (remainder >= divisor / 2) { | 399 | | // do rounding up | 400 | | microseconds += divisor; | 401 | | } | 402 | | } | 403 | | | 404 | | // carry on if microseconds >= 1000000 | 405 | | if (microseconds >= 1000000) { | 406 | | microseconds -= 1000000; | 407 | | second += 1; | 408 | | if (second >= 60) { | 409 | | second -= 60; | 410 | | minute += 1; | 411 | | if (minute >= 60) { | 412 | | minute -= 60; | 413 | | hour += 1; | 414 | | } | 415 | | } | 416 | | } | 417 | | | 418 | | auto time = TimeValue::limit_with_bound( | 419 | | TimeValue::make_time(hour, minute, second, microseconds)); | 420 | | col_to->get_data()[i] = time; | 421 | | } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) { | 422 | | auto dtmv1 = col_from->get_data()[i]; | 423 | | auto time = TimeValue::limit_with_bound( | 424 | | TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second())); | 425 | | col_to->get_data()[i] = time; | 426 | | } | 427 | 2 | } | 428 | | | 429 | | if constexpr (Nullable) { | 430 | | block.get_by_position(result).column = | 431 | | ColumnNullable::create(std::move(col_to), std::move(col_nullmap)); | 432 | 2 | } else { | 433 | 2 | block.get_by_position(result).column = std::move(col_to); | 434 | 2 | } | 435 | 2 | return Status::OK(); | 436 | 2 | } |
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_16DataTypeDateTimeENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_16DataTypeDateTimeENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeTimeV2ENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeTimeV2ENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 156 | 2 | const NullMap::value_type* null_map = nullptr) const override { | 157 | 2 | constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> && | 158 | 2 | (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>); | 159 | | | 160 | 2 | const auto& named_from = block.get_by_position(arguments[0]); | 161 | 2 | if (!named_from.column) { | 162 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 163 | 0 | } | 164 | 2 | const auto* col_from = | 165 | 2 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 166 | 2 | if (!col_from) { | 167 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 168 | 0 | named_from.column->get_name()); | 169 | 0 | } | 170 | 2 | auto col_to = ToDataType::ColumnType::create(input_rows_count); | 171 | 2 | ColumnUInt8::MutablePtr col_nullmap; | 172 | | | 173 | | if constexpr (Nullable) { | 174 | | col_nullmap = ColumnUInt8::create(input_rows_count, 0); | 175 | | } | 176 | | | 177 | 10 | for (size_t i = 0; i < input_rows_count; ++i) { | 178 | 8 | if (null_map && null_map[i]) { | 179 | 2 | continue; | 180 | 2 | } | 181 | | if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) { | 182 | | // from Date to Date | 183 | | auto dtv1 = col_from->get_data()[i]; | 184 | | dtv1.cast_to_date(); | 185 | | col_to->get_data()[i] = | 186 | | binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2()); | 187 | | } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) { | 188 | | DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]); | 189 | | } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) { | 190 | | // from Datetime to Date | 191 | | col_to->get_data()[i] = col_from->get_data()[i]; | 192 | | DataTypeDate::cast_to_date(col_to->get_data()[i]); | 193 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) { | 194 | | DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]); | 195 | | } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) { | 196 | | auto dtmv1 = col_from->get_data()[i]; | 197 | | col_to->get_data()[i] = | 198 | | binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2()); | 199 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) { | 200 | | DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]); | 201 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) { | 202 | | // from Time to Date | 203 | | VecDateTimeValue dtv; | 204 | | dtv.cast_to_date(); | 205 | | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, | 206 | | context->state()->timezone_obj()); | 207 | | | 208 | | auto time_value = col_from->get_data()[i]; | 209 | | int32_t hour = TimeValue::hour(time_value); | 210 | | int32_t minute = TimeValue::minute(time_value); | 211 | | int32_t second = TimeValue::second(time_value); | 212 | | bool neg = TimeValue::sign(time_value) < 0; | 213 | | | 214 | | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 215 | | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 216 | | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 217 | | | 218 | | col_to->get_data()[i] = dtv; | 219 | 6 | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) { | 220 | 6 | DateV2Value<DateV2ValueType> dtv; | 221 | 6 | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, | 222 | 6 | context->state()->timezone_obj()); | 223 | | | 224 | 6 | auto time_value = col_from->get_data()[i]; | 225 | 6 | int32_t hour = TimeValue::hour(time_value); | 226 | 6 | int32_t minute = TimeValue::minute(time_value); | 227 | 6 | int32_t second = TimeValue::second(time_value); | 228 | 6 | bool neg = TimeValue::sign(time_value) < 0; | 229 | | | 230 | 6 | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 231 | 6 | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 232 | 6 | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 233 | | | 234 | 6 | col_to->get_data()[i] = dtv; | 235 | | } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) { | 236 | | // from Date to Datetime | 237 | | col_to->get_data()[i] = col_from->get_data()[i]; | 238 | | DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]); | 239 | | } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) { | 240 | | DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]); | 241 | | } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 242 | | auto dtv1 = col_from->get_data()[i]; | 243 | | col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( | 244 | | dtv1.to_datetime_v2()); | 245 | | } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 246 | | DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i], | 247 | | col_to->get_data()[i]); | 248 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) { | 249 | | // from Time to Datetime | 250 | | VecDateTimeValue dtv; // datetime by default | 251 | | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, | 252 | | context->state()->timezone_obj()); | 253 | | dtv.reset_time_part(); | 254 | | | 255 | | auto time_value = col_from->get_data()[i]; | 256 | | int32_t hour = TimeValue::hour(time_value); | 257 | | int32_t minute = TimeValue::minute(time_value); | 258 | | int32_t second = TimeValue::second(time_value); | 259 | | bool neg = TimeValue::sign(time_value) < 0; | 260 | | | 261 | | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 262 | | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 263 | | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 264 | | | 265 | | col_to->get_data()[i] = dtv; | 266 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 267 | | const auto* type = assert_cast<const DataTypeTimeV2*>( | 268 | | block.get_by_position(arguments[0]).type.get()); | 269 | | auto scale = type->get_scale(); | 270 | | | 271 | | DateV2Value<DateTimeV2ValueType> dtmv2; | 272 | | dtmv2.from_unixtime(context->state()->timestamp_ms() / 1000, | 273 | | context->state()->nano_seconds(), | 274 | | context->state()->timezone_obj(), scale); | 275 | | dtmv2.reset_time_part(); | 276 | | | 277 | | auto time_value = col_from->get_data()[i]; | 278 | | int32_t hour = TimeValue::hour(time_value); | 279 | | int32_t minute = TimeValue::minute(time_value); | 280 | | int32_t second = TimeValue::second(time_value); | 281 | | int32_t microsecond = TimeValue::microsecond(time_value); | 282 | | bool neg = TimeValue::sign(time_value) < 0; | 283 | | | 284 | | dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 285 | | dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 286 | | dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 287 | | dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>( | 288 | | TimeInterval(MICROSECOND, microsecond, neg)); | 289 | | | 290 | | col_to->get_data()[i] = dtmv2; | 291 | | } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 292 | | // from Datetime to Datetime | 293 | | auto dtmv1 = col_from->get_data()[i]; | 294 | | col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( | 295 | | dtmv1.to_datetime_v2()); | 296 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) { | 297 | | DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i], | 298 | | col_to->get_data()[i]); | 299 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 300 | | const auto* type = assert_cast<const DataTypeDateTimeV2*>( | 301 | | block.get_by_position(arguments[0]).type.get()); | 302 | | auto scale = type->get_scale(); | 303 | | | 304 | | const auto* to_type = assert_cast<const DataTypeDateTimeV2*>( | 305 | | block.get_by_position(result).type.get()); | 306 | | UInt32 to_scale = to_type->get_scale(); | 307 | | | 308 | | bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i], | 309 | | col_from->get_data()[i]); | 310 | | if (!success) { | 311 | | if constexpr (CastMode == CastModeType::StrictMode) { | 312 | | auto format_options = DataTypeSerDe::get_default_format_options(); | 313 | | auto time_zone = cctz::utc_time_zone(); | 314 | | format_options.timezone = (context && context->state()) | 315 | | ? &context->state()->timezone_obj() | 316 | | : &time_zone; | 317 | | return Status::InvalidArgument( | 318 | | "DatetimeV2 overflow when casting {} from {} to {}", | 319 | | type->to_string(*col_from, i, format_options), type->get_name(), | 320 | | to_type->get_name()); | 321 | | } else { | 322 | | col_nullmap->get_data()[i] = true; | 323 | | //TODO: maybe we can remove all set operations on nested of null cell. | 324 | | // the correctness should be keep by downstream user with replace_... or manually | 325 | | // process null data if need. | 326 | | col_to->get_data()[i] = | 327 | | binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( | 328 | | MIN_DATETIME_V2); | 329 | | } | 330 | | } | 331 | | | 332 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) { | 333 | | const auto* type = assert_cast<const DataTypeTimeV2*>( | 334 | | block.get_by_position(arguments[0]).type.get()); | 335 | | auto scale = type->get_scale(); | 336 | | | 337 | | const auto* to_type = assert_cast<const DataTypeTimeV2*>( | 338 | | block.get_by_position(result).type.get()); | 339 | | UInt32 to_scale = to_type->get_scale(); | 340 | | | 341 | | if (to_scale >= scale) { | 342 | | // nothing to do, just copy | 343 | | col_to->get_data()[i] = col_from->get_data()[i]; | 344 | | } else { | 345 | | double time = col_from->get_data()[i]; | 346 | | auto sign = TimeValue::sign(time); | 347 | | time = std::abs(time); | 348 | | // e.g. scale reduce to 4, means we need to round the last 2 digits | 349 | | // 999956: 56 > 100/2, then round up to 1000000 | 350 | | uint32_t microseconds = TimeValue::microsecond(time); | 351 | | auto divisor = (uint32_t)common::exp10_i64(6 - to_scale); | 352 | | uint32_t remainder = microseconds % divisor; | 353 | | | 354 | | if (remainder >= divisor / 2) { // need to round up | 355 | | // do rounding up | 356 | | uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor; | 357 | | // need carry on | 358 | | if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) { | 359 | | DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS); | 360 | | time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) * | 361 | | TimeValue::ONE_SECOND_MICROSECONDS; | 362 | | | 363 | | // the input data must be valid, so max to '838:59:59.0'. this value won't carry on | 364 | | // to second. | 365 | | DCHECK(TimeValue::valid(time)) << col_from->get_data()[i]; | 366 | | } else { | 367 | | time = TimeValue::reset_microsecond(time, rounded_microseconds); | 368 | | } | 369 | | } else { | 370 | | // truncate | 371 | | time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor); | 372 | | } | 373 | | col_to->get_data()[i] = sign * time; | 374 | | } | 375 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) { | 376 | | // from Datetime to Time | 377 | | auto dtmv2 = col_from->get_data()[i]; | 378 | | | 379 | | const auto* type = assert_cast<const DataTypeDateTimeV2*>( | 380 | | block.get_by_position(arguments[0]).type.get()); | 381 | | auto scale = type->get_scale(); | 382 | | const auto* to_type = assert_cast<const DataTypeTimeV2*>( | 383 | | block.get_by_position(result).type.get()); | 384 | | UInt32 to_scale = to_type->get_scale(); | 385 | | | 386 | | uint32_t hour = dtmv2.hour(); | 387 | | uint32_t minute = dtmv2.minute(); | 388 | | uint32_t second = dtmv2.second(); | 389 | | uint32_t microseconds = dtmv2.microsecond(); | 390 | | if (to_scale < scale) { // need to round | 391 | | // e.g. scale reduce to 4, means we need to round the last 2 digits | 392 | | // 999956: 56 > 100/2, then round up to 1000000 | 393 | | DCHECK(to_scale <= 6) | 394 | | << "to_scale should be in range [0, 6], but got " << to_scale; | 395 | | auto divisor = (uint32_t)common::exp10_i64(6 - to_scale); | 396 | | uint32_t remainder = microseconds % divisor; | 397 | | microseconds = (microseconds / divisor) * divisor; | 398 | | if (remainder >= divisor / 2) { | 399 | | // do rounding up | 400 | | microseconds += divisor; | 401 | | } | 402 | | } | 403 | | | 404 | | // carry on if microseconds >= 1000000 | 405 | | if (microseconds >= 1000000) { | 406 | | microseconds -= 1000000; | 407 | | second += 1; | 408 | | if (second >= 60) { | 409 | | second -= 60; | 410 | | minute += 1; | 411 | | if (minute >= 60) { | 412 | | minute -= 60; | 413 | | hour += 1; | 414 | | } | 415 | | } | 416 | | } | 417 | | | 418 | | auto time = TimeValue::limit_with_bound( | 419 | | TimeValue::make_time(hour, minute, second, microseconds)); | 420 | | col_to->get_data()[i] = time; | 421 | | } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) { | 422 | | auto dtmv1 = col_from->get_data()[i]; | 423 | | auto time = TimeValue::limit_with_bound( | 424 | | TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second())); | 425 | | col_to->get_data()[i] = time; | 426 | | } | 427 | 6 | } | 428 | | | 429 | | if constexpr (Nullable) { | 430 | | block.get_by_position(result).column = | 431 | | ColumnNullable::create(std::move(col_to), std::move(col_nullmap)); | 432 | 2 | } else { | 433 | 2 | block.get_by_position(result).column = std::move(col_to); | 434 | 2 | } | 435 | 2 | return Status::OK(); | 436 | 2 | } |
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_12DataTypeDateENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_12DataTypeDateENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeDateV2ENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeDateV2ENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 156 | 2 | const NullMap::value_type* null_map = nullptr) const override { | 157 | 2 | constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> && | 158 | 2 | (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>); | 159 | | | 160 | 2 | const auto& named_from = block.get_by_position(arguments[0]); | 161 | 2 | if (!named_from.column) { | 162 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 163 | 0 | } | 164 | 2 | const auto* col_from = | 165 | 2 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 166 | 2 | if (!col_from) { | 167 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 168 | 0 | named_from.column->get_name()); | 169 | 0 | } | 170 | 2 | auto col_to = ToDataType::ColumnType::create(input_rows_count); | 171 | 2 | ColumnUInt8::MutablePtr col_nullmap; | 172 | | | 173 | | if constexpr (Nullable) { | 174 | | col_nullmap = ColumnUInt8::create(input_rows_count, 0); | 175 | | } | 176 | | | 177 | 6 | for (size_t i = 0; i < input_rows_count; ++i) { | 178 | 4 | if (null_map && null_map[i]) { | 179 | 2 | continue; | 180 | 2 | } | 181 | | if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) { | 182 | | // from Date to Date | 183 | | auto dtv1 = col_from->get_data()[i]; | 184 | | dtv1.cast_to_date(); | 185 | | col_to->get_data()[i] = | 186 | | binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2()); | 187 | | } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) { | 188 | | DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]); | 189 | | } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) { | 190 | | // from Datetime to Date | 191 | | col_to->get_data()[i] = col_from->get_data()[i]; | 192 | | DataTypeDate::cast_to_date(col_to->get_data()[i]); | 193 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) { | 194 | | DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]); | 195 | | } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) { | 196 | | auto dtmv1 = col_from->get_data()[i]; | 197 | | col_to->get_data()[i] = | 198 | | binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2()); | 199 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) { | 200 | | DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]); | 201 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) { | 202 | | // from Time to Date | 203 | | VecDateTimeValue dtv; | 204 | | dtv.cast_to_date(); | 205 | | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, | 206 | | context->state()->timezone_obj()); | 207 | | | 208 | | auto time_value = col_from->get_data()[i]; | 209 | | int32_t hour = TimeValue::hour(time_value); | 210 | | int32_t minute = TimeValue::minute(time_value); | 211 | | int32_t second = TimeValue::second(time_value); | 212 | | bool neg = TimeValue::sign(time_value) < 0; | 213 | | | 214 | | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 215 | | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 216 | | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 217 | | | 218 | | col_to->get_data()[i] = dtv; | 219 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) { | 220 | | DateV2Value<DateV2ValueType> dtv; | 221 | | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, | 222 | | context->state()->timezone_obj()); | 223 | | | 224 | | auto time_value = col_from->get_data()[i]; | 225 | | int32_t hour = TimeValue::hour(time_value); | 226 | | int32_t minute = TimeValue::minute(time_value); | 227 | | int32_t second = TimeValue::second(time_value); | 228 | | bool neg = TimeValue::sign(time_value) < 0; | 229 | | | 230 | | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 231 | | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 232 | | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 233 | | | 234 | | col_to->get_data()[i] = dtv; | 235 | | } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) { | 236 | | // from Date to Datetime | 237 | | col_to->get_data()[i] = col_from->get_data()[i]; | 238 | | DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]); | 239 | | } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) { | 240 | | DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]); | 241 | | } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 242 | | auto dtv1 = col_from->get_data()[i]; | 243 | | col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( | 244 | | dtv1.to_datetime_v2()); | 245 | 2 | } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 246 | 2 | DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i], | 247 | 2 | col_to->get_data()[i]); | 248 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) { | 249 | | // from Time to Datetime | 250 | | VecDateTimeValue dtv; // datetime by default | 251 | | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, | 252 | | context->state()->timezone_obj()); | 253 | | dtv.reset_time_part(); | 254 | | | 255 | | auto time_value = col_from->get_data()[i]; | 256 | | int32_t hour = TimeValue::hour(time_value); | 257 | | int32_t minute = TimeValue::minute(time_value); | 258 | | int32_t second = TimeValue::second(time_value); | 259 | | bool neg = TimeValue::sign(time_value) < 0; | 260 | | | 261 | | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 262 | | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 263 | | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 264 | | | 265 | | col_to->get_data()[i] = dtv; | 266 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 267 | | const auto* type = assert_cast<const DataTypeTimeV2*>( | 268 | | block.get_by_position(arguments[0]).type.get()); | 269 | | auto scale = type->get_scale(); | 270 | | | 271 | | DateV2Value<DateTimeV2ValueType> dtmv2; | 272 | | dtmv2.from_unixtime(context->state()->timestamp_ms() / 1000, | 273 | | context->state()->nano_seconds(), | 274 | | context->state()->timezone_obj(), scale); | 275 | | dtmv2.reset_time_part(); | 276 | | | 277 | | auto time_value = col_from->get_data()[i]; | 278 | | int32_t hour = TimeValue::hour(time_value); | 279 | | int32_t minute = TimeValue::minute(time_value); | 280 | | int32_t second = TimeValue::second(time_value); | 281 | | int32_t microsecond = TimeValue::microsecond(time_value); | 282 | | bool neg = TimeValue::sign(time_value) < 0; | 283 | | | 284 | | dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 285 | | dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 286 | | dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 287 | | dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>( | 288 | | TimeInterval(MICROSECOND, microsecond, neg)); | 289 | | | 290 | | col_to->get_data()[i] = dtmv2; | 291 | | } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 292 | | // from Datetime to Datetime | 293 | | auto dtmv1 = col_from->get_data()[i]; | 294 | | col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( | 295 | | dtmv1.to_datetime_v2()); | 296 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) { | 297 | | DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i], | 298 | | col_to->get_data()[i]); | 299 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 300 | | const auto* type = assert_cast<const DataTypeDateTimeV2*>( | 301 | | block.get_by_position(arguments[0]).type.get()); | 302 | | auto scale = type->get_scale(); | 303 | | | 304 | | const auto* to_type = assert_cast<const DataTypeDateTimeV2*>( | 305 | | block.get_by_position(result).type.get()); | 306 | | UInt32 to_scale = to_type->get_scale(); | 307 | | | 308 | | bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i], | 309 | | col_from->get_data()[i]); | 310 | | if (!success) { | 311 | | if constexpr (CastMode == CastModeType::StrictMode) { | 312 | | auto format_options = DataTypeSerDe::get_default_format_options(); | 313 | | auto time_zone = cctz::utc_time_zone(); | 314 | | format_options.timezone = (context && context->state()) | 315 | | ? &context->state()->timezone_obj() | 316 | | : &time_zone; | 317 | | return Status::InvalidArgument( | 318 | | "DatetimeV2 overflow when casting {} from {} to {}", | 319 | | type->to_string(*col_from, i, format_options), type->get_name(), | 320 | | to_type->get_name()); | 321 | | } else { | 322 | | col_nullmap->get_data()[i] = true; | 323 | | //TODO: maybe we can remove all set operations on nested of null cell. | 324 | | // the correctness should be keep by downstream user with replace_... or manually | 325 | | // process null data if need. | 326 | | col_to->get_data()[i] = | 327 | | binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( | 328 | | MIN_DATETIME_V2); | 329 | | } | 330 | | } | 331 | | | 332 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) { | 333 | | const auto* type = assert_cast<const DataTypeTimeV2*>( | 334 | | block.get_by_position(arguments[0]).type.get()); | 335 | | auto scale = type->get_scale(); | 336 | | | 337 | | const auto* to_type = assert_cast<const DataTypeTimeV2*>( | 338 | | block.get_by_position(result).type.get()); | 339 | | UInt32 to_scale = to_type->get_scale(); | 340 | | | 341 | | if (to_scale >= scale) { | 342 | | // nothing to do, just copy | 343 | | col_to->get_data()[i] = col_from->get_data()[i]; | 344 | | } else { | 345 | | double time = col_from->get_data()[i]; | 346 | | auto sign = TimeValue::sign(time); | 347 | | time = std::abs(time); | 348 | | // e.g. scale reduce to 4, means we need to round the last 2 digits | 349 | | // 999956: 56 > 100/2, then round up to 1000000 | 350 | | uint32_t microseconds = TimeValue::microsecond(time); | 351 | | auto divisor = (uint32_t)common::exp10_i64(6 - to_scale); | 352 | | uint32_t remainder = microseconds % divisor; | 353 | | | 354 | | if (remainder >= divisor / 2) { // need to round up | 355 | | // do rounding up | 356 | | uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor; | 357 | | // need carry on | 358 | | if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) { | 359 | | DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS); | 360 | | time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) * | 361 | | TimeValue::ONE_SECOND_MICROSECONDS; | 362 | | | 363 | | // the input data must be valid, so max to '838:59:59.0'. this value won't carry on | 364 | | // to second. | 365 | | DCHECK(TimeValue::valid(time)) << col_from->get_data()[i]; | 366 | | } else { | 367 | | time = TimeValue::reset_microsecond(time, rounded_microseconds); | 368 | | } | 369 | | } else { | 370 | | // truncate | 371 | | time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor); | 372 | | } | 373 | | col_to->get_data()[i] = sign * time; | 374 | | } | 375 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) { | 376 | | // from Datetime to Time | 377 | | auto dtmv2 = col_from->get_data()[i]; | 378 | | | 379 | | const auto* type = assert_cast<const DataTypeDateTimeV2*>( | 380 | | block.get_by_position(arguments[0]).type.get()); | 381 | | auto scale = type->get_scale(); | 382 | | const auto* to_type = assert_cast<const DataTypeTimeV2*>( | 383 | | block.get_by_position(result).type.get()); | 384 | | UInt32 to_scale = to_type->get_scale(); | 385 | | | 386 | | uint32_t hour = dtmv2.hour(); | 387 | | uint32_t minute = dtmv2.minute(); | 388 | | uint32_t second = dtmv2.second(); | 389 | | uint32_t microseconds = dtmv2.microsecond(); | 390 | | if (to_scale < scale) { // need to round | 391 | | // e.g. scale reduce to 4, means we need to round the last 2 digits | 392 | | // 999956: 56 > 100/2, then round up to 1000000 | 393 | | DCHECK(to_scale <= 6) | 394 | | << "to_scale should be in range [0, 6], but got " << to_scale; | 395 | | auto divisor = (uint32_t)common::exp10_i64(6 - to_scale); | 396 | | uint32_t remainder = microseconds % divisor; | 397 | | microseconds = (microseconds / divisor) * divisor; | 398 | | if (remainder >= divisor / 2) { | 399 | | // do rounding up | 400 | | microseconds += divisor; | 401 | | } | 402 | | } | 403 | | | 404 | | // carry on if microseconds >= 1000000 | 405 | | if (microseconds >= 1000000) { | 406 | | microseconds -= 1000000; | 407 | | second += 1; | 408 | | if (second >= 60) { | 409 | | second -= 60; | 410 | | minute += 1; | 411 | | if (minute >= 60) { | 412 | | minute -= 60; | 413 | | hour += 1; | 414 | | } | 415 | | } | 416 | | } | 417 | | | 418 | | auto time = TimeValue::limit_with_bound( | 419 | | TimeValue::make_time(hour, minute, second, microseconds)); | 420 | | col_to->get_data()[i] = time; | 421 | | } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) { | 422 | | auto dtmv1 = col_from->get_data()[i]; | 423 | | auto time = TimeValue::limit_with_bound( | 424 | | TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second())); | 425 | | col_to->get_data()[i] = time; | 426 | | } | 427 | 2 | } | 428 | | | 429 | | if constexpr (Nullable) { | 430 | | block.get_by_position(result).column = | 431 | | ColumnNullable::create(std::move(col_to), std::move(col_nullmap)); | 432 | 2 | } else { | 433 | 2 | block.get_by_position(result).column = std::move(col_to); | 434 | 2 | } | 435 | 2 | return Status::OK(); | 436 | 2 | } |
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_18DataTypeDateTimeV2ES2_E12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_18DataTypeDateTimeV2ES2_E12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_16DataTypeDateTimeENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_16DataTypeDateTimeENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeTimeV2ENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeTimeV2ENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 156 | 2 | const NullMap::value_type* null_map = nullptr) const override { | 157 | 2 | constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> && | 158 | 2 | (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>); | 159 | | | 160 | 2 | const auto& named_from = block.get_by_position(arguments[0]); | 161 | 2 | if (!named_from.column) { | 162 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 163 | 0 | } | 164 | 2 | const auto* col_from = | 165 | 2 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 166 | 2 | if (!col_from) { | 167 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 168 | 0 | named_from.column->get_name()); | 169 | 0 | } | 170 | 2 | auto col_to = ToDataType::ColumnType::create(input_rows_count); | 171 | 2 | ColumnUInt8::MutablePtr col_nullmap; | 172 | | | 173 | | if constexpr (Nullable) { | 174 | | col_nullmap = ColumnUInt8::create(input_rows_count, 0); | 175 | | } | 176 | | | 177 | 10 | for (size_t i = 0; i < input_rows_count; ++i) { | 178 | 8 | if (null_map && null_map[i]) { | 179 | 2 | continue; | 180 | 2 | } | 181 | | if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) { | 182 | | // from Date to Date | 183 | | auto dtv1 = col_from->get_data()[i]; | 184 | | dtv1.cast_to_date(); | 185 | | col_to->get_data()[i] = | 186 | | binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2()); | 187 | | } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) { | 188 | | DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]); | 189 | | } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) { | 190 | | // from Datetime to Date | 191 | | col_to->get_data()[i] = col_from->get_data()[i]; | 192 | | DataTypeDate::cast_to_date(col_to->get_data()[i]); | 193 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) { | 194 | | DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]); | 195 | | } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) { | 196 | | auto dtmv1 = col_from->get_data()[i]; | 197 | | col_to->get_data()[i] = | 198 | | binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2()); | 199 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) { | 200 | | DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]); | 201 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) { | 202 | | // from Time to Date | 203 | | VecDateTimeValue dtv; | 204 | | dtv.cast_to_date(); | 205 | | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, | 206 | | context->state()->timezone_obj()); | 207 | | | 208 | | auto time_value = col_from->get_data()[i]; | 209 | | int32_t hour = TimeValue::hour(time_value); | 210 | | int32_t minute = TimeValue::minute(time_value); | 211 | | int32_t second = TimeValue::second(time_value); | 212 | | bool neg = TimeValue::sign(time_value) < 0; | 213 | | | 214 | | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 215 | | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 216 | | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 217 | | | 218 | | col_to->get_data()[i] = dtv; | 219 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) { | 220 | | DateV2Value<DateV2ValueType> dtv; | 221 | | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, | 222 | | context->state()->timezone_obj()); | 223 | | | 224 | | auto time_value = col_from->get_data()[i]; | 225 | | int32_t hour = TimeValue::hour(time_value); | 226 | | int32_t minute = TimeValue::minute(time_value); | 227 | | int32_t second = TimeValue::second(time_value); | 228 | | bool neg = TimeValue::sign(time_value) < 0; | 229 | | | 230 | | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 231 | | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 232 | | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 233 | | | 234 | | col_to->get_data()[i] = dtv; | 235 | | } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) { | 236 | | // from Date to Datetime | 237 | | col_to->get_data()[i] = col_from->get_data()[i]; | 238 | | DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]); | 239 | | } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) { | 240 | | DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]); | 241 | | } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 242 | | auto dtv1 = col_from->get_data()[i]; | 243 | | col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( | 244 | | dtv1.to_datetime_v2()); | 245 | | } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 246 | | DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i], | 247 | | col_to->get_data()[i]); | 248 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) { | 249 | | // from Time to Datetime | 250 | | VecDateTimeValue dtv; // datetime by default | 251 | | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, | 252 | | context->state()->timezone_obj()); | 253 | | dtv.reset_time_part(); | 254 | | | 255 | | auto time_value = col_from->get_data()[i]; | 256 | | int32_t hour = TimeValue::hour(time_value); | 257 | | int32_t minute = TimeValue::minute(time_value); | 258 | | int32_t second = TimeValue::second(time_value); | 259 | | bool neg = TimeValue::sign(time_value) < 0; | 260 | | | 261 | | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 262 | | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 263 | | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 264 | | | 265 | | col_to->get_data()[i] = dtv; | 266 | 6 | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 267 | 6 | const auto* type = assert_cast<const DataTypeTimeV2*>( | 268 | 6 | block.get_by_position(arguments[0]).type.get()); | 269 | 6 | auto scale = type->get_scale(); | 270 | | | 271 | 6 | DateV2Value<DateTimeV2ValueType> dtmv2; | 272 | 6 | dtmv2.from_unixtime(context->state()->timestamp_ms() / 1000, | 273 | 6 | context->state()->nano_seconds(), | 274 | 6 | context->state()->timezone_obj(), scale); | 275 | 6 | dtmv2.reset_time_part(); | 276 | | | 277 | 6 | auto time_value = col_from->get_data()[i]; | 278 | 6 | int32_t hour = TimeValue::hour(time_value); | 279 | 6 | int32_t minute = TimeValue::minute(time_value); | 280 | 6 | int32_t second = TimeValue::second(time_value); | 281 | 6 | int32_t microsecond = TimeValue::microsecond(time_value); | 282 | 6 | bool neg = TimeValue::sign(time_value) < 0; | 283 | | | 284 | 6 | dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 285 | 6 | dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 286 | 6 | dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 287 | 6 | dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>( | 288 | 6 | TimeInterval(MICROSECOND, microsecond, neg)); | 289 | | | 290 | 6 | col_to->get_data()[i] = dtmv2; | 291 | | } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 292 | | // from Datetime to Datetime | 293 | | auto dtmv1 = col_from->get_data()[i]; | 294 | | col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( | 295 | | dtmv1.to_datetime_v2()); | 296 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) { | 297 | | DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i], | 298 | | col_to->get_data()[i]); | 299 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 300 | | const auto* type = assert_cast<const DataTypeDateTimeV2*>( | 301 | | block.get_by_position(arguments[0]).type.get()); | 302 | | auto scale = type->get_scale(); | 303 | | | 304 | | const auto* to_type = assert_cast<const DataTypeDateTimeV2*>( | 305 | | block.get_by_position(result).type.get()); | 306 | | UInt32 to_scale = to_type->get_scale(); | 307 | | | 308 | | bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i], | 309 | | col_from->get_data()[i]); | 310 | | if (!success) { | 311 | | if constexpr (CastMode == CastModeType::StrictMode) { | 312 | | auto format_options = DataTypeSerDe::get_default_format_options(); | 313 | | auto time_zone = cctz::utc_time_zone(); | 314 | | format_options.timezone = (context && context->state()) | 315 | | ? &context->state()->timezone_obj() | 316 | | : &time_zone; | 317 | | return Status::InvalidArgument( | 318 | | "DatetimeV2 overflow when casting {} from {} to {}", | 319 | | type->to_string(*col_from, i, format_options), type->get_name(), | 320 | | to_type->get_name()); | 321 | | } else { | 322 | | col_nullmap->get_data()[i] = true; | 323 | | //TODO: maybe we can remove all set operations on nested of null cell. | 324 | | // the correctness should be keep by downstream user with replace_... or manually | 325 | | // process null data if need. | 326 | | col_to->get_data()[i] = | 327 | | binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( | 328 | | MIN_DATETIME_V2); | 329 | | } | 330 | | } | 331 | | | 332 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) { | 333 | | const auto* type = assert_cast<const DataTypeTimeV2*>( | 334 | | block.get_by_position(arguments[0]).type.get()); | 335 | | auto scale = type->get_scale(); | 336 | | | 337 | | const auto* to_type = assert_cast<const DataTypeTimeV2*>( | 338 | | block.get_by_position(result).type.get()); | 339 | | UInt32 to_scale = to_type->get_scale(); | 340 | | | 341 | | if (to_scale >= scale) { | 342 | | // nothing to do, just copy | 343 | | col_to->get_data()[i] = col_from->get_data()[i]; | 344 | | } else { | 345 | | double time = col_from->get_data()[i]; | 346 | | auto sign = TimeValue::sign(time); | 347 | | time = std::abs(time); | 348 | | // e.g. scale reduce to 4, means we need to round the last 2 digits | 349 | | // 999956: 56 > 100/2, then round up to 1000000 | 350 | | uint32_t microseconds = TimeValue::microsecond(time); | 351 | | auto divisor = (uint32_t)common::exp10_i64(6 - to_scale); | 352 | | uint32_t remainder = microseconds % divisor; | 353 | | | 354 | | if (remainder >= divisor / 2) { // need to round up | 355 | | // do rounding up | 356 | | uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor; | 357 | | // need carry on | 358 | | if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) { | 359 | | DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS); | 360 | | time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) * | 361 | | TimeValue::ONE_SECOND_MICROSECONDS; | 362 | | | 363 | | // the input data must be valid, so max to '838:59:59.0'. this value won't carry on | 364 | | // to second. | 365 | | DCHECK(TimeValue::valid(time)) << col_from->get_data()[i]; | 366 | | } else { | 367 | | time = TimeValue::reset_microsecond(time, rounded_microseconds); | 368 | | } | 369 | | } else { | 370 | | // truncate | 371 | | time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor); | 372 | | } | 373 | | col_to->get_data()[i] = sign * time; | 374 | | } | 375 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) { | 376 | | // from Datetime to Time | 377 | | auto dtmv2 = col_from->get_data()[i]; | 378 | | | 379 | | const auto* type = assert_cast<const DataTypeDateTimeV2*>( | 380 | | block.get_by_position(arguments[0]).type.get()); | 381 | | auto scale = type->get_scale(); | 382 | | const auto* to_type = assert_cast<const DataTypeTimeV2*>( | 383 | | block.get_by_position(result).type.get()); | 384 | | UInt32 to_scale = to_type->get_scale(); | 385 | | | 386 | | uint32_t hour = dtmv2.hour(); | 387 | | uint32_t minute = dtmv2.minute(); | 388 | | uint32_t second = dtmv2.second(); | 389 | | uint32_t microseconds = dtmv2.microsecond(); | 390 | | if (to_scale < scale) { // need to round | 391 | | // e.g. scale reduce to 4, means we need to round the last 2 digits | 392 | | // 999956: 56 > 100/2, then round up to 1000000 | 393 | | DCHECK(to_scale <= 6) | 394 | | << "to_scale should be in range [0, 6], but got " << to_scale; | 395 | | auto divisor = (uint32_t)common::exp10_i64(6 - to_scale); | 396 | | uint32_t remainder = microseconds % divisor; | 397 | | microseconds = (microseconds / divisor) * divisor; | 398 | | if (remainder >= divisor / 2) { | 399 | | // do rounding up | 400 | | microseconds += divisor; | 401 | | } | 402 | | } | 403 | | | 404 | | // carry on if microseconds >= 1000000 | 405 | | if (microseconds >= 1000000) { | 406 | | microseconds -= 1000000; | 407 | | second += 1; | 408 | | if (second >= 60) { | 409 | | second -= 60; | 410 | | minute += 1; | 411 | | if (minute >= 60) { | 412 | | minute -= 60; | 413 | | hour += 1; | 414 | | } | 415 | | } | 416 | | } | 417 | | | 418 | | auto time = TimeValue::limit_with_bound( | 419 | | TimeValue::make_time(hour, minute, second, microseconds)); | 420 | | col_to->get_data()[i] = time; | 421 | | } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) { | 422 | | auto dtmv1 = col_from->get_data()[i]; | 423 | | auto time = TimeValue::limit_with_bound( | 424 | | TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second())); | 425 | | col_to->get_data()[i] = time; | 426 | | } | 427 | 6 | } | 428 | | | 429 | | if constexpr (Nullable) { | 430 | | block.get_by_position(result).column = | 431 | | ColumnNullable::create(std::move(col_to), std::move(col_nullmap)); | 432 | 2 | } else { | 433 | 2 | block.get_by_position(result).column = std::move(col_to); | 434 | 2 | } | 435 | 2 | return Status::OK(); | 436 | 2 | } |
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_12DataTypeDateENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_12DataTypeDateENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeDateV2ENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeDateV2ENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_18DataTypeDateTimeV2ENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_18DataTypeDateTimeV2ENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Line | Count | Source | 156 | 1 | const NullMap::value_type* null_map = nullptr) const override { | 157 | 1 | constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> && | 158 | 1 | (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>); | 159 | | | 160 | 1 | const auto& named_from = block.get_by_position(arguments[0]); | 161 | 1 | if (!named_from.column) { | 162 | 0 | return Status::RuntimeError("Illegal null column of first argument of function cast"); | 163 | 0 | } | 164 | 1 | const auto* col_from = | 165 | 1 | check_and_get_column<typename FromDataType::ColumnType>(named_from.column.get()); | 166 | 1 | if (!col_from) { | 167 | 0 | return Status::RuntimeError("Illegal column {} of first argument of function cast", | 168 | 0 | named_from.column->get_name()); | 169 | 0 | } | 170 | 1 | auto col_to = ToDataType::ColumnType::create(input_rows_count); | 171 | 1 | ColumnUInt8::MutablePtr col_nullmap; | 172 | | | 173 | | if constexpr (Nullable) { | 174 | | col_nullmap = ColumnUInt8::create(input_rows_count, 0); | 175 | | } | 176 | | | 177 | 2 | for (size_t i = 0; i < input_rows_count; ++i) { | 178 | 1 | if (null_map && null_map[i]) { | 179 | 0 | continue; | 180 | 0 | } | 181 | | if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) { | 182 | | // from Date to Date | 183 | | auto dtv1 = col_from->get_data()[i]; | 184 | | dtv1.cast_to_date(); | 185 | | col_to->get_data()[i] = | 186 | | binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2()); | 187 | | } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) { | 188 | | DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]); | 189 | | } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) { | 190 | | // from Datetime to Date | 191 | | col_to->get_data()[i] = col_from->get_data()[i]; | 192 | | DataTypeDate::cast_to_date(col_to->get_data()[i]); | 193 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) { | 194 | | DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]); | 195 | | } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) { | 196 | | auto dtmv1 = col_from->get_data()[i]; | 197 | | col_to->get_data()[i] = | 198 | | binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2()); | 199 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) { | 200 | | DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]); | 201 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) { | 202 | | // from Time to Date | 203 | | VecDateTimeValue dtv; | 204 | | dtv.cast_to_date(); | 205 | | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, | 206 | | context->state()->timezone_obj()); | 207 | | | 208 | | auto time_value = col_from->get_data()[i]; | 209 | | int32_t hour = TimeValue::hour(time_value); | 210 | | int32_t minute = TimeValue::minute(time_value); | 211 | | int32_t second = TimeValue::second(time_value); | 212 | | bool neg = TimeValue::sign(time_value) < 0; | 213 | | | 214 | | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 215 | | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 216 | | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 217 | | | 218 | | col_to->get_data()[i] = dtv; | 219 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) { | 220 | | DateV2Value<DateV2ValueType> dtv; | 221 | | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, | 222 | | context->state()->timezone_obj()); | 223 | | | 224 | | auto time_value = col_from->get_data()[i]; | 225 | | int32_t hour = TimeValue::hour(time_value); | 226 | | int32_t minute = TimeValue::minute(time_value); | 227 | | int32_t second = TimeValue::second(time_value); | 228 | | bool neg = TimeValue::sign(time_value) < 0; | 229 | | | 230 | | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 231 | | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 232 | | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 233 | | | 234 | | col_to->get_data()[i] = dtv; | 235 | | } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) { | 236 | | // from Date to Datetime | 237 | | col_to->get_data()[i] = col_from->get_data()[i]; | 238 | | DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]); | 239 | | } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) { | 240 | | DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]); | 241 | | } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 242 | | auto dtv1 = col_from->get_data()[i]; | 243 | | col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( | 244 | | dtv1.to_datetime_v2()); | 245 | | } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 246 | | DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i], | 247 | | col_to->get_data()[i]); | 248 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) { | 249 | | // from Time to Datetime | 250 | | VecDateTimeValue dtv; // datetime by default | 251 | | dtv.from_unixtime(context->state()->timestamp_ms() / 1000, | 252 | | context->state()->timezone_obj()); | 253 | | dtv.reset_time_part(); | 254 | | | 255 | | auto time_value = col_from->get_data()[i]; | 256 | | int32_t hour = TimeValue::hour(time_value); | 257 | | int32_t minute = TimeValue::minute(time_value); | 258 | | int32_t second = TimeValue::second(time_value); | 259 | | bool neg = TimeValue::sign(time_value) < 0; | 260 | | | 261 | | dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 262 | | dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 263 | | dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 264 | | | 265 | | col_to->get_data()[i] = dtv; | 266 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 267 | | const auto* type = assert_cast<const DataTypeTimeV2*>( | 268 | | block.get_by_position(arguments[0]).type.get()); | 269 | | auto scale = type->get_scale(); | 270 | | | 271 | | DateV2Value<DateTimeV2ValueType> dtmv2; | 272 | | dtmv2.from_unixtime(context->state()->timestamp_ms() / 1000, | 273 | | context->state()->nano_seconds(), | 274 | | context->state()->timezone_obj(), scale); | 275 | | dtmv2.reset_time_part(); | 276 | | | 277 | | auto time_value = col_from->get_data()[i]; | 278 | | int32_t hour = TimeValue::hour(time_value); | 279 | | int32_t minute = TimeValue::minute(time_value); | 280 | | int32_t second = TimeValue::second(time_value); | 281 | | int32_t microsecond = TimeValue::microsecond(time_value); | 282 | | bool neg = TimeValue::sign(time_value) < 0; | 283 | | | 284 | | dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg)); | 285 | | dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg)); | 286 | | dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg)); | 287 | | dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>( | 288 | | TimeInterval(MICROSECOND, microsecond, neg)); | 289 | | | 290 | | col_to->get_data()[i] = dtmv2; | 291 | | } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 292 | | // from Datetime to Datetime | 293 | | auto dtmv1 = col_from->get_data()[i]; | 294 | | col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( | 295 | | dtmv1.to_datetime_v2()); | 296 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) { | 297 | | DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i], | 298 | | col_to->get_data()[i]); | 299 | | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) { | 300 | | const auto* type = assert_cast<const DataTypeDateTimeV2*>( | 301 | | block.get_by_position(arguments[0]).type.get()); | 302 | | auto scale = type->get_scale(); | 303 | | | 304 | | const auto* to_type = assert_cast<const DataTypeDateTimeV2*>( | 305 | | block.get_by_position(result).type.get()); | 306 | | UInt32 to_scale = to_type->get_scale(); | 307 | | | 308 | | bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i], | 309 | | col_from->get_data()[i]); | 310 | | if (!success) { | 311 | | if constexpr (CastMode == CastModeType::StrictMode) { | 312 | | auto format_options = DataTypeSerDe::get_default_format_options(); | 313 | | auto time_zone = cctz::utc_time_zone(); | 314 | | format_options.timezone = (context && context->state()) | 315 | | ? &context->state()->timezone_obj() | 316 | | : &time_zone; | 317 | | return Status::InvalidArgument( | 318 | | "DatetimeV2 overflow when casting {} from {} to {}", | 319 | | type->to_string(*col_from, i, format_options), type->get_name(), | 320 | | to_type->get_name()); | 321 | | } else { | 322 | | col_nullmap->get_data()[i] = true; | 323 | | //TODO: maybe we can remove all set operations on nested of null cell. | 324 | | // the correctness should be keep by downstream user with replace_... or manually | 325 | | // process null data if need. | 326 | | col_to->get_data()[i] = | 327 | | binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>( | 328 | | MIN_DATETIME_V2); | 329 | | } | 330 | | } | 331 | | | 332 | | } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) { | 333 | | const auto* type = assert_cast<const DataTypeTimeV2*>( | 334 | | block.get_by_position(arguments[0]).type.get()); | 335 | | auto scale = type->get_scale(); | 336 | | | 337 | | const auto* to_type = assert_cast<const DataTypeTimeV2*>( | 338 | | block.get_by_position(result).type.get()); | 339 | | UInt32 to_scale = to_type->get_scale(); | 340 | | | 341 | | if (to_scale >= scale) { | 342 | | // nothing to do, just copy | 343 | | col_to->get_data()[i] = col_from->get_data()[i]; | 344 | | } else { | 345 | | double time = col_from->get_data()[i]; | 346 | | auto sign = TimeValue::sign(time); | 347 | | time = std::abs(time); | 348 | | // e.g. scale reduce to 4, means we need to round the last 2 digits | 349 | | // 999956: 56 > 100/2, then round up to 1000000 | 350 | | uint32_t microseconds = TimeValue::microsecond(time); | 351 | | auto divisor = (uint32_t)common::exp10_i64(6 - to_scale); | 352 | | uint32_t remainder = microseconds % divisor; | 353 | | | 354 | | if (remainder >= divisor / 2) { // need to round up | 355 | | // do rounding up | 356 | | uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor; | 357 | | // need carry on | 358 | | if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) { | 359 | | DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS); | 360 | | time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) * | 361 | | TimeValue::ONE_SECOND_MICROSECONDS; | 362 | | | 363 | | // the input data must be valid, so max to '838:59:59.0'. this value won't carry on | 364 | | // to second. | 365 | | DCHECK(TimeValue::valid(time)) << col_from->get_data()[i]; | 366 | | } else { | 367 | | time = TimeValue::reset_microsecond(time, rounded_microseconds); | 368 | | } | 369 | | } else { | 370 | | // truncate | 371 | | time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor); | 372 | | } | 373 | | col_to->get_data()[i] = sign * time; | 374 | | } | 375 | 1 | } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) { | 376 | | // from Datetime to Time | 377 | 1 | auto dtmv2 = col_from->get_data()[i]; | 378 | | | 379 | 1 | const auto* type = assert_cast<const DataTypeDateTimeV2*>( | 380 | 1 | block.get_by_position(arguments[0]).type.get()); | 381 | 1 | auto scale = type->get_scale(); | 382 | 1 | const auto* to_type = assert_cast<const DataTypeTimeV2*>( | 383 | 1 | block.get_by_position(result).type.get()); | 384 | 1 | UInt32 to_scale = to_type->get_scale(); | 385 | | | 386 | 1 | uint32_t hour = dtmv2.hour(); | 387 | 1 | uint32_t minute = dtmv2.minute(); | 388 | 1 | uint32_t second = dtmv2.second(); | 389 | 1 | uint32_t microseconds = dtmv2.microsecond(); | 390 | 1 | if (to_scale < scale) { // need to round | 391 | | // e.g. scale reduce to 4, means we need to round the last 2 digits | 392 | | // 999956: 56 > 100/2, then round up to 1000000 | 393 | 1 | DCHECK(to_scale <= 6) | 394 | 0 | << "to_scale should be in range [0, 6], but got " << to_scale; | 395 | 1 | auto divisor = (uint32_t)common::exp10_i64(6 - to_scale); | 396 | 1 | uint32_t remainder = microseconds % divisor; | 397 | 1 | microseconds = (microseconds / divisor) * divisor; | 398 | 1 | if (remainder >= divisor / 2) { | 399 | | // do rounding up | 400 | 1 | microseconds += divisor; | 401 | 1 | } | 402 | 1 | } | 403 | | | 404 | | // carry on if microseconds >= 1000000 | 405 | 1 | if (microseconds >= 1000000) { | 406 | 0 | microseconds -= 1000000; | 407 | 0 | second += 1; | 408 | 0 | if (second >= 60) { | 409 | 0 | second -= 60; | 410 | 0 | minute += 1; | 411 | 0 | if (minute >= 60) { | 412 | 0 | minute -= 60; | 413 | 0 | hour += 1; | 414 | 0 | } | 415 | 0 | } | 416 | 0 | } | 417 | | | 418 | 1 | auto time = TimeValue::limit_with_bound( | 419 | 1 | TimeValue::make_time(hour, minute, second, microseconds)); | 420 | 1 | col_to->get_data()[i] = time; | 421 | | } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) { | 422 | | auto dtmv1 = col_from->get_data()[i]; | 423 | | auto time = TimeValue::limit_with_bound( | 424 | | TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second())); | 425 | | col_to->get_data()[i] = time; | 426 | | } | 427 | 1 | } | 428 | | | 429 | | if constexpr (Nullable) { | 430 | | block.get_by_position(result).column = | 431 | | ColumnNullable::create(std::move(col_to), std::move(col_nullmap)); | 432 | 1 | } else { | 433 | 1 | block.get_by_position(result).column = std::move(col_to); | 434 | 1 | } | 435 | 1 | return Status::OK(); | 436 | 1 | } |
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_16DataTypeDateTimeENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_16DataTypeDateTimeENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeTimeV2ES2_E12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeTimeV2ES2_E12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh |
437 | | }; |
438 | | |
439 | | template <> |
440 | | class CastToImpl<CastModeType::StrictMode, DataTypeTimeStampTz, DataTypeDateTimeV2> |
441 | | : public CastToBase { |
442 | | public: |
443 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
444 | | uint32_t result, size_t input_rows_count, |
445 | 2 | const NullMap::value_type* null_map = nullptr) const override { |
446 | 2 | const auto& col_from = |
447 | 2 | assert_cast<const ColumnTimeStampTz&>(*block.get_by_position(arguments[0]).column) |
448 | 2 | .get_data(); |
449 | | |
450 | 2 | auto col_to = ColumnDateTimeV2::create(input_rows_count); |
451 | 2 | auto& col_to_data = col_to->get_data(); |
452 | 2 | const auto& local_time_zone = context->state()->timezone_obj(); |
453 | | |
454 | 2 | const auto tz_scale = block.get_by_position(arguments[0]).type->get_scale(); |
455 | 2 | const auto dt_scale = block.get_by_position(result).type->get_scale(); |
456 | | |
457 | 9 | for (int i = 0; i < input_rows_count; ++i) { |
458 | 8 | if (null_map && null_map[i]) { |
459 | 0 | continue; |
460 | 0 | } |
461 | 8 | TimestampTzValue from_tz {col_from[i]}; |
462 | 8 | DateV2Value<DateTimeV2ValueType> dt; |
463 | 8 | if (!from_tz.to_datetime(dt, local_time_zone, dt_scale, tz_scale)) { |
464 | 1 | return Status::InternalError( |
465 | 1 | "can not cast from timestamptz : {} to datetime in timezone : {}", |
466 | 1 | from_tz.to_string(local_time_zone), context->state()->timezone()); |
467 | 1 | } |
468 | 7 | col_to_data[i] = dt.to_date_int_val(); |
469 | 7 | } |
470 | | |
471 | 1 | block.get_by_position(result).column = std::move(col_to); |
472 | 1 | return Status::OK(); |
473 | 2 | } |
474 | | }; |
475 | | |
476 | | template <> |
477 | | class CastToImpl<CastModeType::NonStrictMode, DataTypeTimeStampTz, DataTypeDateTimeV2> |
478 | | : public CastToBase { |
479 | | public: |
480 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
481 | | uint32_t result, size_t input_rows_count, |
482 | 2 | const NullMap::value_type*) const override { |
483 | 2 | const auto& col_from = |
484 | 2 | assert_cast<const ColumnTimeStampTz&>(*block.get_by_position(arguments[0]).column) |
485 | 2 | .get_data(); |
486 | | |
487 | 2 | auto col_to = ColumnDateTimeV2::create(input_rows_count); |
488 | 2 | auto& col_to_data = col_to->get_data(); |
489 | 2 | auto col_null = ColumnBool::create(input_rows_count, 0); |
490 | 2 | auto& col_null_map = col_null->get_data(); |
491 | 2 | const auto& local_time_zone = context->state()->timezone_obj(); |
492 | | |
493 | 2 | const auto tz_scale = block.get_by_position(arguments[0]).type->get_scale(); |
494 | 2 | const auto dt_scale = block.get_by_position(result).type->get_scale(); |
495 | | |
496 | 10 | for (int i = 0; i < input_rows_count; ++i) { |
497 | 8 | TimestampTzValue from_tz {col_from[i]}; |
498 | 8 | DateV2Value<DateTimeV2ValueType> dt; |
499 | 8 | if (from_tz.to_datetime(dt, local_time_zone, dt_scale, tz_scale)) { |
500 | 7 | col_to_data[i] = dt; |
501 | 7 | } else { |
502 | 1 | col_null_map[i] = 1; |
503 | 1 | col_to_data[i] = MIN_DATETIME_V2; |
504 | 1 | } |
505 | 8 | } |
506 | 2 | block.get_by_position(result).column = |
507 | 2 | ColumnNullable::create(std::move(col_to), std::move(col_null)); |
508 | 2 | return Status::OK(); |
509 | 2 | } |
510 | | }; |
511 | | } // namespace doris |