Coverage Report

Created: 2026-04-10 04:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
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* col_from = check_and_get_column<DataTypeString::ColumnType>(
53
113
                block.get_by_position(arguments[0]).column.get());
54
55
113
        auto to_type = block.get_by_position(result).type;
56
113
        auto serde = remove_nullable(to_type)->get_serde();
57
58
113
        DataTypeSerDe::FormatOptions options;
59
113
        options.timezone = &context->state()->timezone_obj();
60
61
        // by default framework, to_type is already unwrapped nullable
62
113
        MutableColumnPtr column_to = to_type->create_column();
63
113
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
64
113
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
65
66
113
        if constexpr (CastMode == CastModeType::StrictMode) {
67
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
68
107
            RETURN_IF_ERROR(serde->from_string_strict_mode_batch(
69
107
                    *col_from, nullable_col_to->get_nested_column(), options, null_map));
70
107
        } else {
71
            // may write nulls to nullable_col_to
72
6
            RETURN_IF_ERROR(serde->from_string_batch(*col_from, *nullable_col_to, options));
73
6
        }
74
75
9
        block.get_by_position(result).column = std::move(nullable_col_to);
76
113
        return Status::OK();
77
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* col_from = check_and_get_column<DataTypeString::ColumnType>(
53
48
                block.get_by_position(arguments[0]).column.get());
54
55
48
        auto to_type = block.get_by_position(result).type;
56
48
        auto serde = remove_nullable(to_type)->get_serde();
57
58
48
        DataTypeSerDe::FormatOptions options;
59
48
        options.timezone = &context->state()->timezone_obj();
60
61
        // by default framework, to_type is already unwrapped nullable
62
48
        MutableColumnPtr column_to = to_type->create_column();
63
48
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
64
48
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
65
66
48
        if constexpr (CastMode == CastModeType::StrictMode) {
67
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
68
48
            RETURN_IF_ERROR(serde->from_string_strict_mode_batch(
69
48
                    *col_from, nullable_col_to->get_nested_column(), options, null_map));
70
        } else {
71
            // may write nulls to nullable_col_to
72
            RETURN_IF_ERROR(serde->from_string_batch(*col_from, *nullable_col_to, options));
73
        }
74
75
1
        block.get_by_position(result).column = std::move(nullable_col_to);
76
48
        return Status::OK();
77
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* col_from = check_and_get_column<DataTypeString::ColumnType>(
53
3
                block.get_by_position(arguments[0]).column.get());
54
55
3
        auto to_type = block.get_by_position(result).type;
56
3
        auto serde = remove_nullable(to_type)->get_serde();
57
58
3
        DataTypeSerDe::FormatOptions options;
59
3
        options.timezone = &context->state()->timezone_obj();
60
61
        // by default framework, to_type is already unwrapped nullable
62
3
        MutableColumnPtr column_to = to_type->create_column();
63
3
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
64
3
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
65
66
        if constexpr (CastMode == CastModeType::StrictMode) {
67
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
68
            RETURN_IF_ERROR(serde->from_string_strict_mode_batch(
69
                    *col_from, nullable_col_to->get_nested_column(), options, null_map));
70
3
        } else {
71
            // may write nulls to nullable_col_to
72
3
            RETURN_IF_ERROR(serde->from_string_batch(*col_from, *nullable_col_to, options));
73
3
        }
74
75
3
        block.get_by_position(result).column = std::move(nullable_col_to);
76
3
        return Status::OK();
77
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* col_from = check_and_get_column<DataTypeString::ColumnType>(
53
48
                block.get_by_position(arguments[0]).column.get());
54
55
48
        auto to_type = block.get_by_position(result).type;
56
48
        auto serde = remove_nullable(to_type)->get_serde();
57
58
48
        DataTypeSerDe::FormatOptions options;
59
48
        options.timezone = &context->state()->timezone_obj();
60
61
        // by default framework, to_type is already unwrapped nullable
62
48
        MutableColumnPtr column_to = to_type->create_column();
63
48
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
64
48
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
65
66
48
        if constexpr (CastMode == CastModeType::StrictMode) {
67
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
68
48
            RETURN_IF_ERROR(serde->from_string_strict_mode_batch(
69
48
                    *col_from, nullable_col_to->get_nested_column(), options, null_map));
70
        } else {
71
            // may write nulls to nullable_col_to
72
            RETURN_IF_ERROR(serde->from_string_batch(*col_from, *nullable_col_to, options));
73
        }
74
75
1
        block.get_by_position(result).column = std::move(nullable_col_to);
76
48
        return Status::OK();
77
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* col_from = check_and_get_column<DataTypeString::ColumnType>(
53
2
                block.get_by_position(arguments[0]).column.get());
54
55
2
        auto to_type = block.get_by_position(result).type;
56
2
        auto serde = remove_nullable(to_type)->get_serde();
57
58
2
        DataTypeSerDe::FormatOptions options;
59
2
        options.timezone = &context->state()->timezone_obj();
60
61
        // by default framework, to_type is already unwrapped nullable
62
2
        MutableColumnPtr column_to = to_type->create_column();
63
2
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
64
2
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
65
66
        if constexpr (CastMode == CastModeType::StrictMode) {
67
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
68
            RETURN_IF_ERROR(serde->from_string_strict_mode_batch(
69
                    *col_from, nullable_col_to->get_nested_column(), options, null_map));
70
2
        } else {
71
            // may write nulls to nullable_col_to
72
2
            RETURN_IF_ERROR(serde->from_string_batch(*col_from, *nullable_col_to, options));
73
2
        }
74
75
2
        block.get_by_position(result).column = std::move(nullable_col_to);
76
2
        return Status::OK();
77
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* col_from = check_and_get_column<DataTypeString::ColumnType>(
53
11
                block.get_by_position(arguments[0]).column.get());
54
55
11
        auto to_type = block.get_by_position(result).type;
56
11
        auto serde = remove_nullable(to_type)->get_serde();
57
58
11
        DataTypeSerDe::FormatOptions options;
59
11
        options.timezone = &context->state()->timezone_obj();
60
61
        // by default framework, to_type is already unwrapped nullable
62
11
        MutableColumnPtr column_to = to_type->create_column();
63
11
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
64
11
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
65
66
11
        if constexpr (CastMode == CastModeType::StrictMode) {
67
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
68
11
            RETURN_IF_ERROR(serde->from_string_strict_mode_batch(
69
11
                    *col_from, nullable_col_to->get_nested_column(), options, null_map));
70
        } else {
71
            // may write nulls to nullable_col_to
72
            RETURN_IF_ERROR(serde->from_string_batch(*col_from, *nullable_col_to, options));
73
        }
74
75
1
        block.get_by_position(result).column = std::move(nullable_col_to);
76
11
        return Status::OK();
77
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* col_from = check_and_get_column<DataTypeString::ColumnType>(
53
1
                block.get_by_position(arguments[0]).column.get());
54
55
1
        auto to_type = block.get_by_position(result).type;
56
1
        auto serde = remove_nullable(to_type)->get_serde();
57
58
1
        DataTypeSerDe::FormatOptions options;
59
1
        options.timezone = &context->state()->timezone_obj();
60
61
        // by default framework, to_type is already unwrapped nullable
62
1
        MutableColumnPtr column_to = to_type->create_column();
63
1
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
64
1
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
65
66
        if constexpr (CastMode == CastModeType::StrictMode) {
67
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
68
            RETURN_IF_ERROR(serde->from_string_strict_mode_batch(
69
                    *col_from, nullable_col_to->get_nested_column(), options, null_map));
70
1
        } else {
71
            // may write nulls to nullable_col_to
72
1
            RETURN_IF_ERROR(serde->from_string_batch(*col_from, *nullable_col_to, options));
73
1
        }
74
75
1
        block.get_by_position(result).column = std::move(nullable_col_to);
76
1
        return Status::OK();
77
1
    }
78
};
79
80
template <CastModeType CastMode, typename FromDataType, typename ToDataType>
81
    requires(CastUtil::IsPureDigitType<FromDataType> && IsDatelikeTypes<ToDataType>)
82
class CastToImpl<CastMode, FromDataType, ToDataType> : public CastToBase {
83
public:
84
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
85
                        uint32_t result, size_t input_rows_count,
86
37
                        const NullMap::value_type* null_map = nullptr) const override {
87
37
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
88
37
                block.get_by_position(arguments[0]).column.get());
89
37
        auto to_type = block.get_by_position(result).type;
90
37
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
91
37
                remove_nullable(to_type)->get_serde());
92
93
        // by default framework, to_type is already unwrapped nullable
94
37
        MutableColumnPtr column_to = to_type->create_column();
95
37
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
96
37
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
97
98
        // datelike types serde must have template functions for those types. but because of they need to be
99
        // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before.
100
37
        if constexpr (CastMode == CastModeType::StrictMode) {
101
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
102
21
            if constexpr (IsDataTypeInt<FromDataType>) {
103
10
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
104
10
                        *col_from, nullable_col_to->get_nested_column()));
105
10
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
106
10
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
107
10
                        *col_from, nullable_col_to->get_nested_column()));
108
10
            } else {
109
1
                static_assert(IsDataTypeDecimal<FromDataType>);
110
1
                RETURN_IF_ERROR(
111
1
                        concrete_serde->template from_decimal_strict_mode_batch<FromDataType>(
112
1
                                *col_from, nullable_col_to->get_nested_column()));
113
1
            }
114
21
        } else {
115
            // may write nulls to nullable_col_to
116
16
            if constexpr (IsDataTypeInt<FromDataType>) {
117
5
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
5
                        *col_from, *nullable_col_to));
119
5
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
5
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
5
                        *col_from, *nullable_col_to));
122
6
            } else {
123
6
                static_assert(IsDataTypeDecimal<FromDataType>);
124
6
                RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>(
125
6
                        *col_from, *nullable_col_to));
126
6
            }
127
16
        }
128
129
16
        block.get_by_position(result).column = std::move(nullable_col_to);
130
37
        return Status::OK();
131
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
86
5
                        const NullMap::value_type* null_map = nullptr) const override {
87
5
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
88
5
                block.get_by_position(arguments[0]).column.get());
89
5
        auto to_type = block.get_by_position(result).type;
90
5
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
91
5
                remove_nullable(to_type)->get_serde());
92
93
        // by default framework, to_type is already unwrapped nullable
94
5
        MutableColumnPtr column_to = to_type->create_column();
95
5
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
96
5
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
97
98
        // datelike types serde must have template functions for those types. but because of they need to be
99
        // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before.
100
5
        if constexpr (CastMode == CastModeType::StrictMode) {
101
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
102
5
            if constexpr (IsDataTypeInt<FromDataType>) {
103
5
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
104
5
                        *col_from, nullable_col_to->get_nested_column()));
105
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
106
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
107
                        *col_from, nullable_col_to->get_nested_column()));
108
            } else {
109
                static_assert(IsDataTypeDecimal<FromDataType>);
110
                RETURN_IF_ERROR(
111
                        concrete_serde->template from_decimal_strict_mode_batch<FromDataType>(
112
                                *col_from, nullable_col_to->get_nested_column()));
113
            }
114
        } else {
115
            // may write nulls to nullable_col_to
116
            if constexpr (IsDataTypeInt<FromDataType>) {
117
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
                        *col_from, *nullable_col_to));
119
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
                        *col_from, *nullable_col_to));
122
            } else {
123
                static_assert(IsDataTypeDecimal<FromDataType>);
124
                RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>(
125
                        *col_from, *nullable_col_to));
126
            }
127
        }
128
129
0
        block.get_by_position(result).column = std::move(nullable_col_to);
130
5
        return Status::OK();
131
5
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
86
2
                        const NullMap::value_type* null_map = nullptr) const override {
87
2
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
88
2
                block.get_by_position(arguments[0]).column.get());
89
2
        auto to_type = block.get_by_position(result).type;
90
2
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
91
2
                remove_nullable(to_type)->get_serde());
92
93
        // by default framework, to_type is already unwrapped nullable
94
2
        MutableColumnPtr column_to = to_type->create_column();
95
2
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
96
2
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
97
98
        // datelike types serde must have template functions for those types. but because of they need to be
99
        // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before.
100
        if constexpr (CastMode == CastModeType::StrictMode) {
101
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
102
            if constexpr (IsDataTypeInt<FromDataType>) {
103
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
104
                        *col_from, nullable_col_to->get_nested_column()));
105
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
106
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
107
                        *col_from, nullable_col_to->get_nested_column()));
108
            } else {
109
                static_assert(IsDataTypeDecimal<FromDataType>);
110
                RETURN_IF_ERROR(
111
                        concrete_serde->template from_decimal_strict_mode_batch<FromDataType>(
112
                                *col_from, nullable_col_to->get_nested_column()));
113
            }
114
2
        } else {
115
            // may write nulls to nullable_col_to
116
2
            if constexpr (IsDataTypeInt<FromDataType>) {
117
2
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
2
                        *col_from, *nullable_col_to));
119
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
                        *col_from, *nullable_col_to));
122
            } else {
123
                static_assert(IsDataTypeDecimal<FromDataType>);
124
                RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>(
125
                        *col_from, *nullable_col_to));
126
            }
127
2
        }
128
129
2
        block.get_by_position(result).column = std::move(nullable_col_to);
130
2
        return Status::OK();
131
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
86
5
                        const NullMap::value_type* null_map = nullptr) const override {
87
5
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
88
5
                block.get_by_position(arguments[0]).column.get());
89
5
        auto to_type = block.get_by_position(result).type;
90
5
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
91
5
                remove_nullable(to_type)->get_serde());
92
93
        // by default framework, to_type is already unwrapped nullable
94
5
        MutableColumnPtr column_to = to_type->create_column();
95
5
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
96
5
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
97
98
        // datelike types serde must have template functions for those types. but because of they need to be
99
        // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before.
100
5
        if constexpr (CastMode == CastModeType::StrictMode) {
101
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
102
            if constexpr (IsDataTypeInt<FromDataType>) {
103
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
104
                        *col_from, nullable_col_to->get_nested_column()));
105
5
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
106
5
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
107
5
                        *col_from, nullable_col_to->get_nested_column()));
108
            } else {
109
                static_assert(IsDataTypeDecimal<FromDataType>);
110
                RETURN_IF_ERROR(
111
                        concrete_serde->template from_decimal_strict_mode_batch<FromDataType>(
112
                                *col_from, nullable_col_to->get_nested_column()));
113
            }
114
        } else {
115
            // may write nulls to nullable_col_to
116
            if constexpr (IsDataTypeInt<FromDataType>) {
117
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
                        *col_from, *nullable_col_to));
119
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
                        *col_from, *nullable_col_to));
122
            } else {
123
                static_assert(IsDataTypeDecimal<FromDataType>);
124
                RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>(
125
                        *col_from, *nullable_col_to));
126
            }
127
        }
128
129
0
        block.get_by_position(result).column = std::move(nullable_col_to);
130
5
        return Status::OK();
131
5
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
86
2
                        const NullMap::value_type* null_map = nullptr) const override {
87
2
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
88
2
                block.get_by_position(arguments[0]).column.get());
89
2
        auto to_type = block.get_by_position(result).type;
90
2
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
91
2
                remove_nullable(to_type)->get_serde());
92
93
        // by default framework, to_type is already unwrapped nullable
94
2
        MutableColumnPtr column_to = to_type->create_column();
95
2
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
96
2
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
97
98
        // datelike types serde must have template functions for those types. but because of they need to be
99
        // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before.
100
        if constexpr (CastMode == CastModeType::StrictMode) {
101
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
102
            if constexpr (IsDataTypeInt<FromDataType>) {
103
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
104
                        *col_from, nullable_col_to->get_nested_column()));
105
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
106
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
107
                        *col_from, nullable_col_to->get_nested_column()));
108
            } else {
109
                static_assert(IsDataTypeDecimal<FromDataType>);
110
                RETURN_IF_ERROR(
111
                        concrete_serde->template from_decimal_strict_mode_batch<FromDataType>(
112
                                *col_from, nullable_col_to->get_nested_column()));
113
            }
114
2
        } else {
115
            // may write nulls to nullable_col_to
116
            if constexpr (IsDataTypeInt<FromDataType>) {
117
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
                        *col_from, *nullable_col_to));
119
2
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
2
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
2
                        *col_from, *nullable_col_to));
122
            } else {
123
                static_assert(IsDataTypeDecimal<FromDataType>);
124
                RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>(
125
                        *col_from, *nullable_col_to));
126
            }
127
2
        }
128
129
2
        block.get_by_position(result).column = std::move(nullable_col_to);
130
2
        return Status::OK();
131
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
86
2
                        const NullMap::value_type* null_map = nullptr) const override {
87
2
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
88
2
                block.get_by_position(arguments[0]).column.get());
89
2
        auto to_type = block.get_by_position(result).type;
90
2
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
91
2
                remove_nullable(to_type)->get_serde());
92
93
        // by default framework, to_type is already unwrapped nullable
94
2
        MutableColumnPtr column_to = to_type->create_column();
95
2
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
96
2
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
97
98
        // datelike types serde must have template functions for those types. but because of they need to be
99
        // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before.
100
        if constexpr (CastMode == CastModeType::StrictMode) {
101
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
102
            if constexpr (IsDataTypeInt<FromDataType>) {
103
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
104
                        *col_from, nullable_col_to->get_nested_column()));
105
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
106
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
107
                        *col_from, nullable_col_to->get_nested_column()));
108
            } else {
109
                static_assert(IsDataTypeDecimal<FromDataType>);
110
                RETURN_IF_ERROR(
111
                        concrete_serde->template from_decimal_strict_mode_batch<FromDataType>(
112
                                *col_from, nullable_col_to->get_nested_column()));
113
            }
114
2
        } else {
115
            // may write nulls to nullable_col_to
116
            if constexpr (IsDataTypeInt<FromDataType>) {
117
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
                        *col_from, *nullable_col_to));
119
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
                        *col_from, *nullable_col_to));
122
2
            } else {
123
2
                static_assert(IsDataTypeDecimal<FromDataType>);
124
2
                RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>(
125
2
                        *col_from, *nullable_col_to));
126
2
            }
127
2
        }
128
129
2
        block.get_by_position(result).column = std::move(nullable_col_to);
130
2
        return Status::OK();
131
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
86
5
                        const NullMap::value_type* null_map = nullptr) const override {
87
5
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
88
5
                block.get_by_position(arguments[0]).column.get());
89
5
        auto to_type = block.get_by_position(result).type;
90
5
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
91
5
                remove_nullable(to_type)->get_serde());
92
93
        // by default framework, to_type is already unwrapped nullable
94
5
        MutableColumnPtr column_to = to_type->create_column();
95
5
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
96
5
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
97
98
        // datelike types serde must have template functions for those types. but because of they need to be
99
        // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before.
100
5
        if constexpr (CastMode == CastModeType::StrictMode) {
101
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
102
5
            if constexpr (IsDataTypeInt<FromDataType>) {
103
5
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
104
5
                        *col_from, nullable_col_to->get_nested_column()));
105
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
106
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
107
                        *col_from, nullable_col_to->get_nested_column()));
108
            } else {
109
                static_assert(IsDataTypeDecimal<FromDataType>);
110
                RETURN_IF_ERROR(
111
                        concrete_serde->template from_decimal_strict_mode_batch<FromDataType>(
112
                                *col_from, nullable_col_to->get_nested_column()));
113
            }
114
        } else {
115
            // may write nulls to nullable_col_to
116
            if constexpr (IsDataTypeInt<FromDataType>) {
117
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
                        *col_from, *nullable_col_to));
119
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
                        *col_from, *nullable_col_to));
122
            } else {
123
                static_assert(IsDataTypeDecimal<FromDataType>);
124
                RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>(
125
                        *col_from, *nullable_col_to));
126
            }
127
        }
128
129
0
        block.get_by_position(result).column = std::move(nullable_col_to);
130
5
        return Status::OK();
131
5
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
86
2
                        const NullMap::value_type* null_map = nullptr) const override {
87
2
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
88
2
                block.get_by_position(arguments[0]).column.get());
89
2
        auto to_type = block.get_by_position(result).type;
90
2
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
91
2
                remove_nullable(to_type)->get_serde());
92
93
        // by default framework, to_type is already unwrapped nullable
94
2
        MutableColumnPtr column_to = to_type->create_column();
95
2
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
96
2
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
97
98
        // datelike types serde must have template functions for those types. but because of they need to be
99
        // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before.
100
        if constexpr (CastMode == CastModeType::StrictMode) {
101
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
102
            if constexpr (IsDataTypeInt<FromDataType>) {
103
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
104
                        *col_from, nullable_col_to->get_nested_column()));
105
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
106
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
107
                        *col_from, nullable_col_to->get_nested_column()));
108
            } else {
109
                static_assert(IsDataTypeDecimal<FromDataType>);
110
                RETURN_IF_ERROR(
111
                        concrete_serde->template from_decimal_strict_mode_batch<FromDataType>(
112
                                *col_from, nullable_col_to->get_nested_column()));
113
            }
114
2
        } else {
115
            // may write nulls to nullable_col_to
116
2
            if constexpr (IsDataTypeInt<FromDataType>) {
117
2
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
2
                        *col_from, *nullable_col_to));
119
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
                        *col_from, *nullable_col_to));
122
            } else {
123
                static_assert(IsDataTypeDecimal<FromDataType>);
124
                RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>(
125
                        *col_from, *nullable_col_to));
126
            }
127
2
        }
128
129
2
        block.get_by_position(result).column = std::move(nullable_col_to);
130
2
        return Status::OK();
131
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
86
5
                        const NullMap::value_type* null_map = nullptr) const override {
87
5
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
88
5
                block.get_by_position(arguments[0]).column.get());
89
5
        auto to_type = block.get_by_position(result).type;
90
5
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
91
5
                remove_nullable(to_type)->get_serde());
92
93
        // by default framework, to_type is already unwrapped nullable
94
5
        MutableColumnPtr column_to = to_type->create_column();
95
5
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
96
5
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
97
98
        // datelike types serde must have template functions for those types. but because of they need to be
99
        // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before.
100
5
        if constexpr (CastMode == CastModeType::StrictMode) {
101
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
102
            if constexpr (IsDataTypeInt<FromDataType>) {
103
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
104
                        *col_from, nullable_col_to->get_nested_column()));
105
5
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
106
5
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
107
5
                        *col_from, nullable_col_to->get_nested_column()));
108
            } else {
109
                static_assert(IsDataTypeDecimal<FromDataType>);
110
                RETURN_IF_ERROR(
111
                        concrete_serde->template from_decimal_strict_mode_batch<FromDataType>(
112
                                *col_from, nullable_col_to->get_nested_column()));
113
            }
114
        } else {
115
            // may write nulls to nullable_col_to
116
            if constexpr (IsDataTypeInt<FromDataType>) {
117
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
                        *col_from, *nullable_col_to));
119
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
                        *col_from, *nullable_col_to));
122
            } else {
123
                static_assert(IsDataTypeDecimal<FromDataType>);
124
                RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>(
125
                        *col_from, *nullable_col_to));
126
            }
127
        }
128
129
0
        block.get_by_position(result).column = std::move(nullable_col_to);
130
5
        return Status::OK();
131
5
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
86
2
                        const NullMap::value_type* null_map = nullptr) const override {
87
2
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
88
2
                block.get_by_position(arguments[0]).column.get());
89
2
        auto to_type = block.get_by_position(result).type;
90
2
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
91
2
                remove_nullable(to_type)->get_serde());
92
93
        // by default framework, to_type is already unwrapped nullable
94
2
        MutableColumnPtr column_to = to_type->create_column();
95
2
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
96
2
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
97
98
        // datelike types serde must have template functions for those types. but because of they need to be
99
        // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before.
100
        if constexpr (CastMode == CastModeType::StrictMode) {
101
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
102
            if constexpr (IsDataTypeInt<FromDataType>) {
103
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
104
                        *col_from, nullable_col_to->get_nested_column()));
105
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
106
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
107
                        *col_from, nullable_col_to->get_nested_column()));
108
            } else {
109
                static_assert(IsDataTypeDecimal<FromDataType>);
110
                RETURN_IF_ERROR(
111
                        concrete_serde->template from_decimal_strict_mode_batch<FromDataType>(
112
                                *col_from, nullable_col_to->get_nested_column()));
113
            }
114
2
        } else {
115
            // may write nulls to nullable_col_to
116
            if constexpr (IsDataTypeInt<FromDataType>) {
117
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
                        *col_from, *nullable_col_to));
119
2
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
2
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
2
                        *col_from, *nullable_col_to));
122
            } else {
123
                static_assert(IsDataTypeDecimal<FromDataType>);
124
                RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>(
125
                        *col_from, *nullable_col_to));
126
            }
127
2
        }
128
129
2
        block.get_by_position(result).column = std::move(nullable_col_to);
130
2
        return Status::OK();
131
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
86
1
                        const NullMap::value_type* null_map = nullptr) const override {
87
1
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
88
1
                block.get_by_position(arguments[0]).column.get());
89
1
        auto to_type = block.get_by_position(result).type;
90
1
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
91
1
                remove_nullable(to_type)->get_serde());
92
93
        // by default framework, to_type is already unwrapped nullable
94
1
        MutableColumnPtr column_to = to_type->create_column();
95
1
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
96
1
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
97
98
        // datelike types serde must have template functions for those types. but because of they need to be
99
        // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before.
100
1
        if constexpr (CastMode == CastModeType::StrictMode) {
101
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
102
            if constexpr (IsDataTypeInt<FromDataType>) {
103
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
104
                        *col_from, nullable_col_to->get_nested_column()));
105
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
106
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
107
                        *col_from, nullable_col_to->get_nested_column()));
108
1
            } else {
109
1
                static_assert(IsDataTypeDecimal<FromDataType>);
110
1
                RETURN_IF_ERROR(
111
1
                        concrete_serde->template from_decimal_strict_mode_batch<FromDataType>(
112
1
                                *col_from, nullable_col_to->get_nested_column()));
113
1
            }
114
        } else {
115
            // may write nulls to nullable_col_to
116
            if constexpr (IsDataTypeInt<FromDataType>) {
117
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
                        *col_from, *nullable_col_to));
119
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
                        *col_from, *nullable_col_to));
122
            } else {
123
                static_assert(IsDataTypeDecimal<FromDataType>);
124
                RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>(
125
                        *col_from, *nullable_col_to));
126
            }
127
        }
128
129
0
        block.get_by_position(result).column = std::move(nullable_col_to);
130
1
        return Status::OK();
131
1
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
86
3
                        const NullMap::value_type* null_map = nullptr) const override {
87
3
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
88
3
                block.get_by_position(arguments[0]).column.get());
89
3
        auto to_type = block.get_by_position(result).type;
90
3
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
91
3
                remove_nullable(to_type)->get_serde());
92
93
        // by default framework, to_type is already unwrapped nullable
94
3
        MutableColumnPtr column_to = to_type->create_column();
95
3
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
96
3
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
97
98
        // datelike types serde must have template functions for those types. but because of they need to be
99
        // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before.
100
        if constexpr (CastMode == CastModeType::StrictMode) {
101
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
102
            if constexpr (IsDataTypeInt<FromDataType>) {
103
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
104
                        *col_from, nullable_col_to->get_nested_column()));
105
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
106
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
107
                        *col_from, nullable_col_to->get_nested_column()));
108
            } else {
109
                static_assert(IsDataTypeDecimal<FromDataType>);
110
                RETURN_IF_ERROR(
111
                        concrete_serde->template from_decimal_strict_mode_batch<FromDataType>(
112
                                *col_from, nullable_col_to->get_nested_column()));
113
            }
114
3
        } else {
115
            // may write nulls to nullable_col_to
116
            if constexpr (IsDataTypeInt<FromDataType>) {
117
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
                        *col_from, *nullable_col_to));
119
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
                        *col_from, *nullable_col_to));
122
3
            } else {
123
3
                static_assert(IsDataTypeDecimal<FromDataType>);
124
3
                RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>(
125
3
                        *col_from, *nullable_col_to));
126
3
            }
127
3
        }
128
129
3
        block.get_by_position(result).column = std::move(nullable_col_to);
130
3
        return Status::OK();
131
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
86
1
                        const NullMap::value_type* null_map = nullptr) const override {
87
1
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
88
1
                block.get_by_position(arguments[0]).column.get());
89
1
        auto to_type = block.get_by_position(result).type;
90
1
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
91
1
                remove_nullable(to_type)->get_serde());
92
93
        // by default framework, to_type is already unwrapped nullable
94
1
        MutableColumnPtr column_to = to_type->create_column();
95
1
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
96
1
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
97
98
        // datelike types serde must have template functions for those types. but because of they need to be
99
        // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before.
100
        if constexpr (CastMode == CastModeType::StrictMode) {
101
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
102
            if constexpr (IsDataTypeInt<FromDataType>) {
103
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
104
                        *col_from, nullable_col_to->get_nested_column()));
105
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
106
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
107
                        *col_from, nullable_col_to->get_nested_column()));
108
            } else {
109
                static_assert(IsDataTypeDecimal<FromDataType>);
110
                RETURN_IF_ERROR(
111
                        concrete_serde->template from_decimal_strict_mode_batch<FromDataType>(
112
                                *col_from, nullable_col_to->get_nested_column()));
113
            }
114
1
        } else {
115
            // may write nulls to nullable_col_to
116
1
            if constexpr (IsDataTypeInt<FromDataType>) {
117
1
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
1
                        *col_from, *nullable_col_to));
119
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
                        *col_from, *nullable_col_to));
122
            } else {
123
                static_assert(IsDataTypeDecimal<FromDataType>);
124
                RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>(
125
                        *col_from, *nullable_col_to));
126
            }
127
1
        }
128
129
1
        block.get_by_position(result).column = std::move(nullable_col_to);
130
1
        return Status::OK();
131
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
86
1
                        const NullMap::value_type* null_map = nullptr) const override {
87
1
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
88
1
                block.get_by_position(arguments[0]).column.get());
89
1
        auto to_type = block.get_by_position(result).type;
90
1
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
91
1
                remove_nullable(to_type)->get_serde());
92
93
        // by default framework, to_type is already unwrapped nullable
94
1
        MutableColumnPtr column_to = to_type->create_column();
95
1
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
96
1
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
97
98
        // datelike types serde must have template functions for those types. but because of they need to be
99
        // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before.
100
        if constexpr (CastMode == CastModeType::StrictMode) {
101
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
102
            if constexpr (IsDataTypeInt<FromDataType>) {
103
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
104
                        *col_from, nullable_col_to->get_nested_column()));
105
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
106
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
107
                        *col_from, nullable_col_to->get_nested_column()));
108
            } else {
109
                static_assert(IsDataTypeDecimal<FromDataType>);
110
                RETURN_IF_ERROR(
111
                        concrete_serde->template from_decimal_strict_mode_batch<FromDataType>(
112
                                *col_from, nullable_col_to->get_nested_column()));
113
            }
114
1
        } else {
115
            // may write nulls to nullable_col_to
116
            if constexpr (IsDataTypeInt<FromDataType>) {
117
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
                        *col_from, *nullable_col_to));
119
1
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
1
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
1
                        *col_from, *nullable_col_to));
122
            } else {
123
                static_assert(IsDataTypeDecimal<FromDataType>);
124
                RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>(
125
                        *col_from, *nullable_col_to));
126
            }
127
1
        }
128
129
1
        block.get_by_position(result).column = std::move(nullable_col_to);
130
1
        return Status::OK();
131
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
86
1
                        const NullMap::value_type* null_map = nullptr) const override {
87
1
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
88
1
                block.get_by_position(arguments[0]).column.get());
89
1
        auto to_type = block.get_by_position(result).type;
90
1
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
91
1
                remove_nullable(to_type)->get_serde());
92
93
        // by default framework, to_type is already unwrapped nullable
94
1
        MutableColumnPtr column_to = to_type->create_column();
95
1
        ColumnNullable::MutablePtr nullable_col_to = ColumnNullable::create(
96
1
                std::move(column_to), ColumnUInt8::create(input_rows_count, 0));
97
98
        // datelike types serde must have template functions for those types. but because of they need to be
99
        // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before.
100
        if constexpr (CastMode == CastModeType::StrictMode) {
101
            // WON'T write nulls to nullable_col_to, just raise errors. null_map is only used to skip invalid rows
102
            if constexpr (IsDataTypeInt<FromDataType>) {
103
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
104
                        *col_from, nullable_col_to->get_nested_column()));
105
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
106
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
107
                        *col_from, nullable_col_to->get_nested_column()));
108
            } else {
109
                static_assert(IsDataTypeDecimal<FromDataType>);
110
                RETURN_IF_ERROR(
111
                        concrete_serde->template from_decimal_strict_mode_batch<FromDataType>(
112
                                *col_from, nullable_col_to->get_nested_column()));
113
            }
114
1
        } else {
115
            // may write nulls to nullable_col_to
116
            if constexpr (IsDataTypeInt<FromDataType>) {
117
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
                        *col_from, *nullable_col_to));
119
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
                        *col_from, *nullable_col_to));
122
1
            } else {
123
1
                static_assert(IsDataTypeDecimal<FromDataType>);
124
1
                RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>(
125
1
                        *col_from, *nullable_col_to));
126
1
            }
127
1
        }
128
129
1
        block.get_by_position(result).column = std::move(nullable_col_to);
130
1
        return Status::OK();
131
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
132
};
133
134
template <CastModeType CastMode, typename FromDataType, typename ToDataType>
135
    requires(IsDatelikeTypes<FromDataType> && IsDatelikeTypes<ToDataType>)
136
class CastToImpl<CastMode, FromDataType, ToDataType> : public CastToBase {
137
public:
138
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
139
                        uint32_t result, size_t input_rows_count,
140
9
                        const NullMap::value_type* null_map = nullptr) const override {
141
9
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
142
9
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
143
144
9
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
145
9
                block.get_by_position(arguments[0]).column.get());
146
9
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
147
9
        ColumnUInt8::MutablePtr col_nullmap;
148
149
9
        if constexpr (Nullable) {
150
0
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
151
0
        }
152
153
34
        for (size_t i = 0; i < input_rows_count; ++i) {
154
25
            if (null_map && null_map[i]) {
155
8
                continue;
156
8
            }
157
17
            if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) {
158
                // from Date to Date
159
0
                auto dtv1 = col_from->get_data()[i];
160
0
                dtv1.cast_to_date();
161
0
                col_to->get_data()[i] =
162
0
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2());
163
0
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) {
164
0
                DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
165
0
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) {
166
                // from Datetime to Date
167
0
                col_to->get_data()[i] = col_from->get_data()[i];
168
0
                DataTypeDate::cast_to_date(col_to->get_data()[i]);
169
0
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
170
0
                DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
171
0
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) {
172
0
                auto dtmv1 = col_from->get_data()[i];
173
0
                col_to->get_data()[i] =
174
0
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2());
175
2
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
176
2
                DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]);
177
2
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
178
                // from Time to Date
179
0
                VecDateTimeValue dtv;
180
0
                dtv.cast_to_date();
181
0
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
182
0
                                  context->state()->timezone_obj());
183
184
0
                auto time_value = col_from->get_data()[i];
185
0
                int32_t hour = TimeValue::hour(time_value);
186
0
                int32_t minute = TimeValue::minute(time_value);
187
0
                int32_t second = TimeValue::second(time_value);
188
0
                bool neg = TimeValue::sign(time_value) < 0;
189
190
0
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
191
0
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
192
0
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
193
194
0
                col_to->get_data()[i] = dtv;
195
6
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
196
6
                DateV2Value<DateV2ValueType> dtv;
197
6
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
198
6
                                  context->state()->timezone_obj());
199
200
6
                auto time_value = col_from->get_data()[i];
201
6
                int32_t hour = TimeValue::hour(time_value);
202
6
                int32_t minute = TimeValue::minute(time_value);
203
6
                int32_t second = TimeValue::second(time_value);
204
6
                bool neg = TimeValue::sign(time_value) < 0;
205
206
6
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
207
6
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
208
6
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
209
210
6
                col_to->get_data()[i] = dtv;
211
6
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) {
212
                // from Date to Datetime
213
0
                col_to->get_data()[i] = col_from->get_data()[i];
214
0
                DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]);
215
0
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
216
0
                DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]);
217
0
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
218
0
                auto dtv1 = col_from->get_data()[i];
219
0
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
220
0
                        dtv1.to_datetime_v2());
221
2
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
222
2
                DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i],
223
2
                                                     col_to->get_data()[i]);
224
2
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
225
                // from Time to Datetime
226
0
                VecDateTimeValue dtv; // datetime by default
227
0
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
228
0
                                  context->state()->timezone_obj());
229
0
                dtv.reset_time_part();
230
231
0
                auto time_value = col_from->get_data()[i];
232
0
                int32_t hour = TimeValue::hour(time_value);
233
0
                int32_t minute = TimeValue::minute(time_value);
234
0
                int32_t second = TimeValue::second(time_value);
235
0
                bool neg = TimeValue::sign(time_value) < 0;
236
237
0
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
238
0
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
239
0
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
240
241
0
                col_to->get_data()[i] = dtv;
242
6
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
243
6
                const auto* type = assert_cast<const DataTypeTimeV2*>(
244
6
                        block.get_by_position(arguments[0]).type.get());
245
6
                auto scale = type->get_scale();
246
247
6
                DateV2Value<DateTimeV2ValueType> dtmv2;
248
6
                dtmv2.from_unixtime(context->state()->timestamp_ms() / 1000,
249
6
                                    context->state()->nano_seconds(),
250
6
                                    context->state()->timezone_obj(), scale);
251
6
                dtmv2.reset_time_part();
252
253
6
                auto time_value = col_from->get_data()[i];
254
6
                int32_t hour = TimeValue::hour(time_value);
255
6
                int32_t minute = TimeValue::minute(time_value);
256
6
                int32_t second = TimeValue::second(time_value);
257
6
                int32_t microsecond = TimeValue::microsecond(time_value);
258
6
                bool neg = TimeValue::sign(time_value) < 0;
259
260
6
                dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
261
6
                dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
262
6
                dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
263
6
                dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>(
264
6
                        TimeInterval(MICROSECOND, microsecond, neg));
265
266
6
                col_to->get_data()[i] = dtmv2;
267
6
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
268
                // from Datetime to Datetime
269
0
                auto dtmv1 = col_from->get_data()[i];
270
0
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
271
0
                        dtmv1.to_datetime_v2());
272
0
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
273
0
                DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i],
274
0
                                                      col_to->get_data()[i]);
275
0
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
276
0
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(
277
0
                        block.get_by_position(arguments[0]).type.get());
278
0
                auto scale = type->get_scale();
279
280
0
                const auto* to_type = assert_cast<const DataTypeDateTimeV2*>(
281
0
                        block.get_by_position(result).type.get());
282
0
                UInt32 to_scale = to_type->get_scale();
283
284
0
                bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i],
285
0
                                                    col_from->get_data()[i]);
286
0
                if (!success) {
287
0
                    if constexpr (CastMode == CastModeType::StrictMode) {
288
0
                        auto format_options = DataTypeSerDe::get_default_format_options();
289
0
                        auto time_zone = cctz::utc_time_zone();
290
0
                        format_options.timezone = (context && context->state())
291
0
                                                          ? &context->state()->timezone_obj()
292
0
                                                          : &time_zone;
293
0
                        return Status::InvalidArgument(
294
0
                                "DatetimeV2 overflow when casting {} from {} to {}",
295
0
                                type->to_string(*col_from, i, format_options), type->get_name(),
296
0
                                to_type->get_name());
297
0
                    } else {
298
0
                        col_nullmap->get_data()[i] = true;
299
                        //TODO: maybe we can remove all set operations on nested of null cell.
300
                        // the correctness should be keep by downstream user with replace_... or manually
301
                        // process null data if need.
302
0
                        col_to->get_data()[i] =
303
0
                                binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
304
0
                                        MIN_DATETIME_V2);
305
0
                    }
306
0
                }
307
308
0
            } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
309
0
                const auto* type = assert_cast<const DataTypeTimeV2*>(
310
0
                        block.get_by_position(arguments[0]).type.get());
311
0
                auto scale = type->get_scale();
312
313
0
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(
314
0
                        block.get_by_position(result).type.get());
315
0
                UInt32 to_scale = to_type->get_scale();
316
317
0
                if (to_scale >= scale) {
318
                    // nothing to do, just copy
319
0
                    col_to->get_data()[i] = col_from->get_data()[i];
320
0
                } else {
321
0
                    double time = col_from->get_data()[i];
322
0
                    auto sign = TimeValue::sign(time);
323
0
                    time = std::abs(time);
324
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
325
                    // 999956: 56 > 100/2, then round up to 1000000
326
0
                    uint32_t microseconds = TimeValue::microsecond(time);
327
0
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
328
0
                    uint32_t remainder = microseconds % divisor;
329
330
0
                    if (remainder >= divisor / 2) { // need to round up
331
                        // do rounding up
332
0
                        uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor;
333
                        // need carry on
334
0
                        if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
335
0
                            DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS);
336
0
                            time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) *
337
0
                                   TimeValue::ONE_SECOND_MICROSECONDS;
338
339
                            // the input data must be valid, so max to '838:59:59.0'. this value won't carry on
340
                            // to second.
341
0
                            DCHECK(TimeValue::valid(time)) << col_from->get_data()[i];
342
0
                        } else {
343
0
                            time = TimeValue::reset_microsecond(time, rounded_microseconds);
344
0
                        }
345
0
                    } else {
346
                        // truncate
347
0
                        time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor);
348
0
                    }
349
0
                    col_to->get_data()[i] = sign * time;
350
0
                }
351
1
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
352
                // from Datetime to Time
353
1
                auto dtmv2 = col_from->get_data()[i];
354
355
1
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(
356
1
                        block.get_by_position(arguments[0]).type.get());
357
1
                auto scale = type->get_scale();
358
1
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(
359
1
                        block.get_by_position(result).type.get());
360
1
                UInt32 to_scale = to_type->get_scale();
361
362
1
                uint32_t hour = dtmv2.hour();
363
1
                uint32_t minute = dtmv2.minute();
364
1
                uint32_t second = dtmv2.second();
365
1
                uint32_t microseconds = dtmv2.microsecond();
366
1
                if (to_scale < scale) { // need to round
367
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
368
                    // 999956: 56 > 100/2, then round up to 1000000
369
1
                    DCHECK(to_scale <= 6)
370
0
                            << "to_scale should be in range [0, 6], but got " << to_scale;
371
1
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
372
1
                    uint32_t remainder = microseconds % divisor;
373
1
                    microseconds = (microseconds / divisor) * divisor;
374
1
                    if (remainder >= divisor / 2) {
375
                        // do rounding up
376
1
                        microseconds += divisor;
377
1
                    }
378
1
                }
379
380
                // carry on if microseconds >= 1000000
381
1
                if (microseconds >= 1000000) {
382
0
                    microseconds -= 1000000;
383
0
                    second += 1;
384
0
                    if (second >= 60) {
385
0
                        second -= 60;
386
0
                        minute += 1;
387
0
                        if (minute >= 60) {
388
0
                            minute -= 60;
389
0
                            hour += 1;
390
0
                        }
391
0
                    }
392
0
                }
393
394
1
                auto time = TimeValue::limit_with_bound(
395
1
                        TimeValue::make_time(hour, minute, second, microseconds));
396
1
                col_to->get_data()[i] = time;
397
1
            } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) {
398
0
                auto dtmv1 = col_from->get_data()[i];
399
0
                auto time = TimeValue::limit_with_bound(
400
0
                        TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second()));
401
0
                col_to->get_data()[i] = time;
402
0
            }
403
17
        }
404
405
9
        if constexpr (Nullable) {
406
0
            block.get_by_position(result).column =
407
0
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
408
9
        } else {
409
9
            block.get_by_position(result).column = std::move(col_to);
410
9
        }
411
9
        return Status::OK();
412
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
140
2
                        const NullMap::value_type* null_map = nullptr) const override {
141
2
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
142
2
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
143
144
2
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
145
2
                block.get_by_position(arguments[0]).column.get());
146
2
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
147
2
        ColumnUInt8::MutablePtr col_nullmap;
148
149
        if constexpr (Nullable) {
150
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
151
        }
152
153
6
        for (size_t i = 0; i < input_rows_count; ++i) {
154
4
            if (null_map && null_map[i]) {
155
2
                continue;
156
2
            }
157
            if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) {
158
                // from Date to Date
159
                auto dtv1 = col_from->get_data()[i];
160
                dtv1.cast_to_date();
161
                col_to->get_data()[i] =
162
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2());
163
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) {
164
                DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
165
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) {
166
                // from Datetime to Date
167
                col_to->get_data()[i] = col_from->get_data()[i];
168
                DataTypeDate::cast_to_date(col_to->get_data()[i]);
169
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
170
                DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
171
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) {
172
                auto dtmv1 = col_from->get_data()[i];
173
                col_to->get_data()[i] =
174
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2());
175
2
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
176
2
                DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]);
177
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
178
                // from Time to Date
179
                VecDateTimeValue dtv;
180
                dtv.cast_to_date();
181
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
182
                                  context->state()->timezone_obj());
183
184
                auto time_value = col_from->get_data()[i];
185
                int32_t hour = TimeValue::hour(time_value);
186
                int32_t minute = TimeValue::minute(time_value);
187
                int32_t second = TimeValue::second(time_value);
188
                bool neg = TimeValue::sign(time_value) < 0;
189
190
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
191
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
192
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
193
194
                col_to->get_data()[i] = dtv;
195
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
196
                DateV2Value<DateV2ValueType> dtv;
197
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
198
                                  context->state()->timezone_obj());
199
200
                auto time_value = col_from->get_data()[i];
201
                int32_t hour = TimeValue::hour(time_value);
202
                int32_t minute = TimeValue::minute(time_value);
203
                int32_t second = TimeValue::second(time_value);
204
                bool neg = TimeValue::sign(time_value) < 0;
205
206
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
207
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
208
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
209
210
                col_to->get_data()[i] = dtv;
211
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) {
212
                // from Date to Datetime
213
                col_to->get_data()[i] = col_from->get_data()[i];
214
                DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]);
215
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
216
                DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]);
217
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
218
                auto dtv1 = col_from->get_data()[i];
219
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
220
                        dtv1.to_datetime_v2());
221
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
222
                DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i],
223
                                                     col_to->get_data()[i]);
224
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
225
                // from Time to Datetime
226
                VecDateTimeValue dtv; // datetime by default
227
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
228
                                  context->state()->timezone_obj());
229
                dtv.reset_time_part();
230
231
                auto time_value = col_from->get_data()[i];
232
                int32_t hour = TimeValue::hour(time_value);
233
                int32_t minute = TimeValue::minute(time_value);
234
                int32_t second = TimeValue::second(time_value);
235
                bool neg = TimeValue::sign(time_value) < 0;
236
237
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
238
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
239
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
240
241
                col_to->get_data()[i] = dtv;
242
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
243
                const auto* type = assert_cast<const DataTypeTimeV2*>(
244
                        block.get_by_position(arguments[0]).type.get());
245
                auto scale = type->get_scale();
246
247
                DateV2Value<DateTimeV2ValueType> dtmv2;
248
                dtmv2.from_unixtime(context->state()->timestamp_ms() / 1000,
249
                                    context->state()->nano_seconds(),
250
                                    context->state()->timezone_obj(), scale);
251
                dtmv2.reset_time_part();
252
253
                auto time_value = col_from->get_data()[i];
254
                int32_t hour = TimeValue::hour(time_value);
255
                int32_t minute = TimeValue::minute(time_value);
256
                int32_t second = TimeValue::second(time_value);
257
                int32_t microsecond = TimeValue::microsecond(time_value);
258
                bool neg = TimeValue::sign(time_value) < 0;
259
260
                dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
261
                dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
262
                dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
263
                dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>(
264
                        TimeInterval(MICROSECOND, microsecond, neg));
265
266
                col_to->get_data()[i] = dtmv2;
267
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
268
                // from Datetime to Datetime
269
                auto dtmv1 = col_from->get_data()[i];
270
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
271
                        dtmv1.to_datetime_v2());
272
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
273
                DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i],
274
                                                      col_to->get_data()[i]);
275
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
276
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(
277
                        block.get_by_position(arguments[0]).type.get());
278
                auto scale = type->get_scale();
279
280
                const auto* to_type = assert_cast<const DataTypeDateTimeV2*>(
281
                        block.get_by_position(result).type.get());
282
                UInt32 to_scale = to_type->get_scale();
283
284
                bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i],
285
                                                    col_from->get_data()[i]);
286
                if (!success) {
287
                    if constexpr (CastMode == CastModeType::StrictMode) {
288
                        auto format_options = DataTypeSerDe::get_default_format_options();
289
                        auto time_zone = cctz::utc_time_zone();
290
                        format_options.timezone = (context && context->state())
291
                                                          ? &context->state()->timezone_obj()
292
                                                          : &time_zone;
293
                        return Status::InvalidArgument(
294
                                "DatetimeV2 overflow when casting {} from {} to {}",
295
                                type->to_string(*col_from, i, format_options), type->get_name(),
296
                                to_type->get_name());
297
                    } else {
298
                        col_nullmap->get_data()[i] = true;
299
                        //TODO: maybe we can remove all set operations on nested of null cell.
300
                        // the correctness should be keep by downstream user with replace_... or manually
301
                        // process null data if need.
302
                        col_to->get_data()[i] =
303
                                binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
304
                                        MIN_DATETIME_V2);
305
                    }
306
                }
307
308
            } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
309
                const auto* type = assert_cast<const DataTypeTimeV2*>(
310
                        block.get_by_position(arguments[0]).type.get());
311
                auto scale = type->get_scale();
312
313
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(
314
                        block.get_by_position(result).type.get());
315
                UInt32 to_scale = to_type->get_scale();
316
317
                if (to_scale >= scale) {
318
                    // nothing to do, just copy
319
                    col_to->get_data()[i] = col_from->get_data()[i];
320
                } else {
321
                    double time = col_from->get_data()[i];
322
                    auto sign = TimeValue::sign(time);
323
                    time = std::abs(time);
324
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
325
                    // 999956: 56 > 100/2, then round up to 1000000
326
                    uint32_t microseconds = TimeValue::microsecond(time);
327
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
328
                    uint32_t remainder = microseconds % divisor;
329
330
                    if (remainder >= divisor / 2) { // need to round up
331
                        // do rounding up
332
                        uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor;
333
                        // need carry on
334
                        if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
335
                            DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS);
336
                            time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) *
337
                                   TimeValue::ONE_SECOND_MICROSECONDS;
338
339
                            // the input data must be valid, so max to '838:59:59.0'. this value won't carry on
340
                            // to second.
341
                            DCHECK(TimeValue::valid(time)) << col_from->get_data()[i];
342
                        } else {
343
                            time = TimeValue::reset_microsecond(time, rounded_microseconds);
344
                        }
345
                    } else {
346
                        // truncate
347
                        time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor);
348
                    }
349
                    col_to->get_data()[i] = sign * time;
350
                }
351
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
352
                // from Datetime to Time
353
                auto dtmv2 = col_from->get_data()[i];
354
355
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(
356
                        block.get_by_position(arguments[0]).type.get());
357
                auto scale = type->get_scale();
358
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(
359
                        block.get_by_position(result).type.get());
360
                UInt32 to_scale = to_type->get_scale();
361
362
                uint32_t hour = dtmv2.hour();
363
                uint32_t minute = dtmv2.minute();
364
                uint32_t second = dtmv2.second();
365
                uint32_t microseconds = dtmv2.microsecond();
366
                if (to_scale < scale) { // need to round
367
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
368
                    // 999956: 56 > 100/2, then round up to 1000000
369
                    DCHECK(to_scale <= 6)
370
                            << "to_scale should be in range [0, 6], but got " << to_scale;
371
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
372
                    uint32_t remainder = microseconds % divisor;
373
                    microseconds = (microseconds / divisor) * divisor;
374
                    if (remainder >= divisor / 2) {
375
                        // do rounding up
376
                        microseconds += divisor;
377
                    }
378
                }
379
380
                // carry on if microseconds >= 1000000
381
                if (microseconds >= 1000000) {
382
                    microseconds -= 1000000;
383
                    second += 1;
384
                    if (second >= 60) {
385
                        second -= 60;
386
                        minute += 1;
387
                        if (minute >= 60) {
388
                            minute -= 60;
389
                            hour += 1;
390
                        }
391
                    }
392
                }
393
394
                auto time = TimeValue::limit_with_bound(
395
                        TimeValue::make_time(hour, minute, second, microseconds));
396
                col_to->get_data()[i] = time;
397
            } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) {
398
                auto dtmv1 = col_from->get_data()[i];
399
                auto time = TimeValue::limit_with_bound(
400
                        TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second()));
401
                col_to->get_data()[i] = time;
402
            }
403
2
        }
404
405
        if constexpr (Nullable) {
406
            block.get_by_position(result).column =
407
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
408
2
        } else {
409
2
            block.get_by_position(result).column = std::move(col_to);
410
2
        }
411
2
        return Status::OK();
412
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
140
2
                        const NullMap::value_type* null_map = nullptr) const override {
141
2
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
142
2
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
143
144
2
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
145
2
                block.get_by_position(arguments[0]).column.get());
146
2
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
147
2
        ColumnUInt8::MutablePtr col_nullmap;
148
149
        if constexpr (Nullable) {
150
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
151
        }
152
153
10
        for (size_t i = 0; i < input_rows_count; ++i) {
154
8
            if (null_map && null_map[i]) {
155
2
                continue;
156
2
            }
157
            if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) {
158
                // from Date to Date
159
                auto dtv1 = col_from->get_data()[i];
160
                dtv1.cast_to_date();
161
                col_to->get_data()[i] =
162
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2());
163
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) {
164
                DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
165
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) {
166
                // from Datetime to Date
167
                col_to->get_data()[i] = col_from->get_data()[i];
168
                DataTypeDate::cast_to_date(col_to->get_data()[i]);
169
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
170
                DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
171
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) {
172
                auto dtmv1 = col_from->get_data()[i];
173
                col_to->get_data()[i] =
174
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2());
175
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
176
                DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]);
177
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
178
                // from Time to Date
179
                VecDateTimeValue dtv;
180
                dtv.cast_to_date();
181
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
182
                                  context->state()->timezone_obj());
183
184
                auto time_value = col_from->get_data()[i];
185
                int32_t hour = TimeValue::hour(time_value);
186
                int32_t minute = TimeValue::minute(time_value);
187
                int32_t second = TimeValue::second(time_value);
188
                bool neg = TimeValue::sign(time_value) < 0;
189
190
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
191
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
192
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
193
194
                col_to->get_data()[i] = dtv;
195
6
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
196
6
                DateV2Value<DateV2ValueType> dtv;
197
6
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
198
6
                                  context->state()->timezone_obj());
199
200
6
                auto time_value = col_from->get_data()[i];
201
6
                int32_t hour = TimeValue::hour(time_value);
202
6
                int32_t minute = TimeValue::minute(time_value);
203
6
                int32_t second = TimeValue::second(time_value);
204
6
                bool neg = TimeValue::sign(time_value) < 0;
205
206
6
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
207
6
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
208
6
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
209
210
6
                col_to->get_data()[i] = dtv;
211
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) {
212
                // from Date to Datetime
213
                col_to->get_data()[i] = col_from->get_data()[i];
214
                DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]);
215
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
216
                DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]);
217
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
218
                auto dtv1 = col_from->get_data()[i];
219
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
220
                        dtv1.to_datetime_v2());
221
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
222
                DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i],
223
                                                     col_to->get_data()[i]);
224
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
225
                // from Time to Datetime
226
                VecDateTimeValue dtv; // datetime by default
227
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
228
                                  context->state()->timezone_obj());
229
                dtv.reset_time_part();
230
231
                auto time_value = col_from->get_data()[i];
232
                int32_t hour = TimeValue::hour(time_value);
233
                int32_t minute = TimeValue::minute(time_value);
234
                int32_t second = TimeValue::second(time_value);
235
                bool neg = TimeValue::sign(time_value) < 0;
236
237
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
238
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
239
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
240
241
                col_to->get_data()[i] = dtv;
242
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
243
                const auto* type = assert_cast<const DataTypeTimeV2*>(
244
                        block.get_by_position(arguments[0]).type.get());
245
                auto scale = type->get_scale();
246
247
                DateV2Value<DateTimeV2ValueType> dtmv2;
248
                dtmv2.from_unixtime(context->state()->timestamp_ms() / 1000,
249
                                    context->state()->nano_seconds(),
250
                                    context->state()->timezone_obj(), scale);
251
                dtmv2.reset_time_part();
252
253
                auto time_value = col_from->get_data()[i];
254
                int32_t hour = TimeValue::hour(time_value);
255
                int32_t minute = TimeValue::minute(time_value);
256
                int32_t second = TimeValue::second(time_value);
257
                int32_t microsecond = TimeValue::microsecond(time_value);
258
                bool neg = TimeValue::sign(time_value) < 0;
259
260
                dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
261
                dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
262
                dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
263
                dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>(
264
                        TimeInterval(MICROSECOND, microsecond, neg));
265
266
                col_to->get_data()[i] = dtmv2;
267
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
268
                // from Datetime to Datetime
269
                auto dtmv1 = col_from->get_data()[i];
270
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
271
                        dtmv1.to_datetime_v2());
272
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
273
                DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i],
274
                                                      col_to->get_data()[i]);
275
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
276
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(
277
                        block.get_by_position(arguments[0]).type.get());
278
                auto scale = type->get_scale();
279
280
                const auto* to_type = assert_cast<const DataTypeDateTimeV2*>(
281
                        block.get_by_position(result).type.get());
282
                UInt32 to_scale = to_type->get_scale();
283
284
                bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i],
285
                                                    col_from->get_data()[i]);
286
                if (!success) {
287
                    if constexpr (CastMode == CastModeType::StrictMode) {
288
                        auto format_options = DataTypeSerDe::get_default_format_options();
289
                        auto time_zone = cctz::utc_time_zone();
290
                        format_options.timezone = (context && context->state())
291
                                                          ? &context->state()->timezone_obj()
292
                                                          : &time_zone;
293
                        return Status::InvalidArgument(
294
                                "DatetimeV2 overflow when casting {} from {} to {}",
295
                                type->to_string(*col_from, i, format_options), type->get_name(),
296
                                to_type->get_name());
297
                    } else {
298
                        col_nullmap->get_data()[i] = true;
299
                        //TODO: maybe we can remove all set operations on nested of null cell.
300
                        // the correctness should be keep by downstream user with replace_... or manually
301
                        // process null data if need.
302
                        col_to->get_data()[i] =
303
                                binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
304
                                        MIN_DATETIME_V2);
305
                    }
306
                }
307
308
            } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
309
                const auto* type = assert_cast<const DataTypeTimeV2*>(
310
                        block.get_by_position(arguments[0]).type.get());
311
                auto scale = type->get_scale();
312
313
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(
314
                        block.get_by_position(result).type.get());
315
                UInt32 to_scale = to_type->get_scale();
316
317
                if (to_scale >= scale) {
318
                    // nothing to do, just copy
319
                    col_to->get_data()[i] = col_from->get_data()[i];
320
                } else {
321
                    double time = col_from->get_data()[i];
322
                    auto sign = TimeValue::sign(time);
323
                    time = std::abs(time);
324
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
325
                    // 999956: 56 > 100/2, then round up to 1000000
326
                    uint32_t microseconds = TimeValue::microsecond(time);
327
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
328
                    uint32_t remainder = microseconds % divisor;
329
330
                    if (remainder >= divisor / 2) { // need to round up
331
                        // do rounding up
332
                        uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor;
333
                        // need carry on
334
                        if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
335
                            DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS);
336
                            time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) *
337
                                   TimeValue::ONE_SECOND_MICROSECONDS;
338
339
                            // the input data must be valid, so max to '838:59:59.0'. this value won't carry on
340
                            // to second.
341
                            DCHECK(TimeValue::valid(time)) << col_from->get_data()[i];
342
                        } else {
343
                            time = TimeValue::reset_microsecond(time, rounded_microseconds);
344
                        }
345
                    } else {
346
                        // truncate
347
                        time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor);
348
                    }
349
                    col_to->get_data()[i] = sign * time;
350
                }
351
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
352
                // from Datetime to Time
353
                auto dtmv2 = col_from->get_data()[i];
354
355
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(
356
                        block.get_by_position(arguments[0]).type.get());
357
                auto scale = type->get_scale();
358
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(
359
                        block.get_by_position(result).type.get());
360
                UInt32 to_scale = to_type->get_scale();
361
362
                uint32_t hour = dtmv2.hour();
363
                uint32_t minute = dtmv2.minute();
364
                uint32_t second = dtmv2.second();
365
                uint32_t microseconds = dtmv2.microsecond();
366
                if (to_scale < scale) { // need to round
367
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
368
                    // 999956: 56 > 100/2, then round up to 1000000
369
                    DCHECK(to_scale <= 6)
370
                            << "to_scale should be in range [0, 6], but got " << to_scale;
371
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
372
                    uint32_t remainder = microseconds % divisor;
373
                    microseconds = (microseconds / divisor) * divisor;
374
                    if (remainder >= divisor / 2) {
375
                        // do rounding up
376
                        microseconds += divisor;
377
                    }
378
                }
379
380
                // carry on if microseconds >= 1000000
381
                if (microseconds >= 1000000) {
382
                    microseconds -= 1000000;
383
                    second += 1;
384
                    if (second >= 60) {
385
                        second -= 60;
386
                        minute += 1;
387
                        if (minute >= 60) {
388
                            minute -= 60;
389
                            hour += 1;
390
                        }
391
                    }
392
                }
393
394
                auto time = TimeValue::limit_with_bound(
395
                        TimeValue::make_time(hour, minute, second, microseconds));
396
                col_to->get_data()[i] = time;
397
            } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) {
398
                auto dtmv1 = col_from->get_data()[i];
399
                auto time = TimeValue::limit_with_bound(
400
                        TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second()));
401
                col_to->get_data()[i] = time;
402
            }
403
6
        }
404
405
        if constexpr (Nullable) {
406
            block.get_by_position(result).column =
407
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
408
2
        } else {
409
2
            block.get_by_position(result).column = std::move(col_to);
410
2
        }
411
2
        return Status::OK();
412
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
140
2
                        const NullMap::value_type* null_map = nullptr) const override {
141
2
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
142
2
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
143
144
2
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
145
2
                block.get_by_position(arguments[0]).column.get());
146
2
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
147
2
        ColumnUInt8::MutablePtr col_nullmap;
148
149
        if constexpr (Nullable) {
150
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
151
        }
152
153
6
        for (size_t i = 0; i < input_rows_count; ++i) {
154
4
            if (null_map && null_map[i]) {
155
2
                continue;
156
2
            }
157
            if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) {
158
                // from Date to Date
159
                auto dtv1 = col_from->get_data()[i];
160
                dtv1.cast_to_date();
161
                col_to->get_data()[i] =
162
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2());
163
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) {
164
                DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
165
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) {
166
                // from Datetime to Date
167
                col_to->get_data()[i] = col_from->get_data()[i];
168
                DataTypeDate::cast_to_date(col_to->get_data()[i]);
169
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
170
                DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
171
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) {
172
                auto dtmv1 = col_from->get_data()[i];
173
                col_to->get_data()[i] =
174
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2());
175
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
176
                DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]);
177
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
178
                // from Time to Date
179
                VecDateTimeValue dtv;
180
                dtv.cast_to_date();
181
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
182
                                  context->state()->timezone_obj());
183
184
                auto time_value = col_from->get_data()[i];
185
                int32_t hour = TimeValue::hour(time_value);
186
                int32_t minute = TimeValue::minute(time_value);
187
                int32_t second = TimeValue::second(time_value);
188
                bool neg = TimeValue::sign(time_value) < 0;
189
190
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
191
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
192
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
193
194
                col_to->get_data()[i] = dtv;
195
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
196
                DateV2Value<DateV2ValueType> dtv;
197
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
198
                                  context->state()->timezone_obj());
199
200
                auto time_value = col_from->get_data()[i];
201
                int32_t hour = TimeValue::hour(time_value);
202
                int32_t minute = TimeValue::minute(time_value);
203
                int32_t second = TimeValue::second(time_value);
204
                bool neg = TimeValue::sign(time_value) < 0;
205
206
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
207
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
208
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
209
210
                col_to->get_data()[i] = dtv;
211
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) {
212
                // from Date to Datetime
213
                col_to->get_data()[i] = col_from->get_data()[i];
214
                DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]);
215
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
216
                DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]);
217
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
218
                auto dtv1 = col_from->get_data()[i];
219
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
220
                        dtv1.to_datetime_v2());
221
2
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
222
2
                DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i],
223
2
                                                     col_to->get_data()[i]);
224
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
225
                // from Time to Datetime
226
                VecDateTimeValue dtv; // datetime by default
227
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
228
                                  context->state()->timezone_obj());
229
                dtv.reset_time_part();
230
231
                auto time_value = col_from->get_data()[i];
232
                int32_t hour = TimeValue::hour(time_value);
233
                int32_t minute = TimeValue::minute(time_value);
234
                int32_t second = TimeValue::second(time_value);
235
                bool neg = TimeValue::sign(time_value) < 0;
236
237
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
238
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
239
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
240
241
                col_to->get_data()[i] = dtv;
242
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
243
                const auto* type = assert_cast<const DataTypeTimeV2*>(
244
                        block.get_by_position(arguments[0]).type.get());
245
                auto scale = type->get_scale();
246
247
                DateV2Value<DateTimeV2ValueType> dtmv2;
248
                dtmv2.from_unixtime(context->state()->timestamp_ms() / 1000,
249
                                    context->state()->nano_seconds(),
250
                                    context->state()->timezone_obj(), scale);
251
                dtmv2.reset_time_part();
252
253
                auto time_value = col_from->get_data()[i];
254
                int32_t hour = TimeValue::hour(time_value);
255
                int32_t minute = TimeValue::minute(time_value);
256
                int32_t second = TimeValue::second(time_value);
257
                int32_t microsecond = TimeValue::microsecond(time_value);
258
                bool neg = TimeValue::sign(time_value) < 0;
259
260
                dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
261
                dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
262
                dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
263
                dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>(
264
                        TimeInterval(MICROSECOND, microsecond, neg));
265
266
                col_to->get_data()[i] = dtmv2;
267
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
268
                // from Datetime to Datetime
269
                auto dtmv1 = col_from->get_data()[i];
270
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
271
                        dtmv1.to_datetime_v2());
272
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
273
                DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i],
274
                                                      col_to->get_data()[i]);
275
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
276
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(
277
                        block.get_by_position(arguments[0]).type.get());
278
                auto scale = type->get_scale();
279
280
                const auto* to_type = assert_cast<const DataTypeDateTimeV2*>(
281
                        block.get_by_position(result).type.get());
282
                UInt32 to_scale = to_type->get_scale();
283
284
                bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i],
285
                                                    col_from->get_data()[i]);
286
                if (!success) {
287
                    if constexpr (CastMode == CastModeType::StrictMode) {
288
                        auto format_options = DataTypeSerDe::get_default_format_options();
289
                        auto time_zone = cctz::utc_time_zone();
290
                        format_options.timezone = (context && context->state())
291
                                                          ? &context->state()->timezone_obj()
292
                                                          : &time_zone;
293
                        return Status::InvalidArgument(
294
                                "DatetimeV2 overflow when casting {} from {} to {}",
295
                                type->to_string(*col_from, i, format_options), type->get_name(),
296
                                to_type->get_name());
297
                    } else {
298
                        col_nullmap->get_data()[i] = true;
299
                        //TODO: maybe we can remove all set operations on nested of null cell.
300
                        // the correctness should be keep by downstream user with replace_... or manually
301
                        // process null data if need.
302
                        col_to->get_data()[i] =
303
                                binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
304
                                        MIN_DATETIME_V2);
305
                    }
306
                }
307
308
            } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
309
                const auto* type = assert_cast<const DataTypeTimeV2*>(
310
                        block.get_by_position(arguments[0]).type.get());
311
                auto scale = type->get_scale();
312
313
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(
314
                        block.get_by_position(result).type.get());
315
                UInt32 to_scale = to_type->get_scale();
316
317
                if (to_scale >= scale) {
318
                    // nothing to do, just copy
319
                    col_to->get_data()[i] = col_from->get_data()[i];
320
                } else {
321
                    double time = col_from->get_data()[i];
322
                    auto sign = TimeValue::sign(time);
323
                    time = std::abs(time);
324
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
325
                    // 999956: 56 > 100/2, then round up to 1000000
326
                    uint32_t microseconds = TimeValue::microsecond(time);
327
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
328
                    uint32_t remainder = microseconds % divisor;
329
330
                    if (remainder >= divisor / 2) { // need to round up
331
                        // do rounding up
332
                        uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor;
333
                        // need carry on
334
                        if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
335
                            DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS);
336
                            time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) *
337
                                   TimeValue::ONE_SECOND_MICROSECONDS;
338
339
                            // the input data must be valid, so max to '838:59:59.0'. this value won't carry on
340
                            // to second.
341
                            DCHECK(TimeValue::valid(time)) << col_from->get_data()[i];
342
                        } else {
343
                            time = TimeValue::reset_microsecond(time, rounded_microseconds);
344
                        }
345
                    } else {
346
                        // truncate
347
                        time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor);
348
                    }
349
                    col_to->get_data()[i] = sign * time;
350
                }
351
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
352
                // from Datetime to Time
353
                auto dtmv2 = col_from->get_data()[i];
354
355
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(
356
                        block.get_by_position(arguments[0]).type.get());
357
                auto scale = type->get_scale();
358
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(
359
                        block.get_by_position(result).type.get());
360
                UInt32 to_scale = to_type->get_scale();
361
362
                uint32_t hour = dtmv2.hour();
363
                uint32_t minute = dtmv2.minute();
364
                uint32_t second = dtmv2.second();
365
                uint32_t microseconds = dtmv2.microsecond();
366
                if (to_scale < scale) { // need to round
367
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
368
                    // 999956: 56 > 100/2, then round up to 1000000
369
                    DCHECK(to_scale <= 6)
370
                            << "to_scale should be in range [0, 6], but got " << to_scale;
371
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
372
                    uint32_t remainder = microseconds % divisor;
373
                    microseconds = (microseconds / divisor) * divisor;
374
                    if (remainder >= divisor / 2) {
375
                        // do rounding up
376
                        microseconds += divisor;
377
                    }
378
                }
379
380
                // carry on if microseconds >= 1000000
381
                if (microseconds >= 1000000) {
382
                    microseconds -= 1000000;
383
                    second += 1;
384
                    if (second >= 60) {
385
                        second -= 60;
386
                        minute += 1;
387
                        if (minute >= 60) {
388
                            minute -= 60;
389
                            hour += 1;
390
                        }
391
                    }
392
                }
393
394
                auto time = TimeValue::limit_with_bound(
395
                        TimeValue::make_time(hour, minute, second, microseconds));
396
                col_to->get_data()[i] = time;
397
            } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) {
398
                auto dtmv1 = col_from->get_data()[i];
399
                auto time = TimeValue::limit_with_bound(
400
                        TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second()));
401
                col_to->get_data()[i] = time;
402
            }
403
2
        }
404
405
        if constexpr (Nullable) {
406
            block.get_by_position(result).column =
407
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
408
2
        } else {
409
2
            block.get_by_position(result).column = std::move(col_to);
410
2
        }
411
2
        return Status::OK();
412
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
140
2
                        const NullMap::value_type* null_map = nullptr) const override {
141
2
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
142
2
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
143
144
2
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
145
2
                block.get_by_position(arguments[0]).column.get());
146
2
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
147
2
        ColumnUInt8::MutablePtr col_nullmap;
148
149
        if constexpr (Nullable) {
150
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
151
        }
152
153
10
        for (size_t i = 0; i < input_rows_count; ++i) {
154
8
            if (null_map && null_map[i]) {
155
2
                continue;
156
2
            }
157
            if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) {
158
                // from Date to Date
159
                auto dtv1 = col_from->get_data()[i];
160
                dtv1.cast_to_date();
161
                col_to->get_data()[i] =
162
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2());
163
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) {
164
                DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
165
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) {
166
                // from Datetime to Date
167
                col_to->get_data()[i] = col_from->get_data()[i];
168
                DataTypeDate::cast_to_date(col_to->get_data()[i]);
169
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
170
                DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
171
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) {
172
                auto dtmv1 = col_from->get_data()[i];
173
                col_to->get_data()[i] =
174
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2());
175
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
176
                DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]);
177
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
178
                // from Time to Date
179
                VecDateTimeValue dtv;
180
                dtv.cast_to_date();
181
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
182
                                  context->state()->timezone_obj());
183
184
                auto time_value = col_from->get_data()[i];
185
                int32_t hour = TimeValue::hour(time_value);
186
                int32_t minute = TimeValue::minute(time_value);
187
                int32_t second = TimeValue::second(time_value);
188
                bool neg = TimeValue::sign(time_value) < 0;
189
190
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
191
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
192
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
193
194
                col_to->get_data()[i] = dtv;
195
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
196
                DateV2Value<DateV2ValueType> dtv;
197
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
198
                                  context->state()->timezone_obj());
199
200
                auto time_value = col_from->get_data()[i];
201
                int32_t hour = TimeValue::hour(time_value);
202
                int32_t minute = TimeValue::minute(time_value);
203
                int32_t second = TimeValue::second(time_value);
204
                bool neg = TimeValue::sign(time_value) < 0;
205
206
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
207
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
208
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
209
210
                col_to->get_data()[i] = dtv;
211
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) {
212
                // from Date to Datetime
213
                col_to->get_data()[i] = col_from->get_data()[i];
214
                DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]);
215
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
216
                DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]);
217
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
218
                auto dtv1 = col_from->get_data()[i];
219
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
220
                        dtv1.to_datetime_v2());
221
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
222
                DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i],
223
                                                     col_to->get_data()[i]);
224
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
225
                // from Time to Datetime
226
                VecDateTimeValue dtv; // datetime by default
227
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
228
                                  context->state()->timezone_obj());
229
                dtv.reset_time_part();
230
231
                auto time_value = col_from->get_data()[i];
232
                int32_t hour = TimeValue::hour(time_value);
233
                int32_t minute = TimeValue::minute(time_value);
234
                int32_t second = TimeValue::second(time_value);
235
                bool neg = TimeValue::sign(time_value) < 0;
236
237
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
238
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
239
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
240
241
                col_to->get_data()[i] = dtv;
242
6
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
243
6
                const auto* type = assert_cast<const DataTypeTimeV2*>(
244
6
                        block.get_by_position(arguments[0]).type.get());
245
6
                auto scale = type->get_scale();
246
247
6
                DateV2Value<DateTimeV2ValueType> dtmv2;
248
6
                dtmv2.from_unixtime(context->state()->timestamp_ms() / 1000,
249
6
                                    context->state()->nano_seconds(),
250
6
                                    context->state()->timezone_obj(), scale);
251
6
                dtmv2.reset_time_part();
252
253
6
                auto time_value = col_from->get_data()[i];
254
6
                int32_t hour = TimeValue::hour(time_value);
255
6
                int32_t minute = TimeValue::minute(time_value);
256
6
                int32_t second = TimeValue::second(time_value);
257
6
                int32_t microsecond = TimeValue::microsecond(time_value);
258
6
                bool neg = TimeValue::sign(time_value) < 0;
259
260
6
                dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
261
6
                dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
262
6
                dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
263
6
                dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>(
264
6
                        TimeInterval(MICROSECOND, microsecond, neg));
265
266
6
                col_to->get_data()[i] = dtmv2;
267
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
268
                // from Datetime to Datetime
269
                auto dtmv1 = col_from->get_data()[i];
270
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
271
                        dtmv1.to_datetime_v2());
272
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
273
                DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i],
274
                                                      col_to->get_data()[i]);
275
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
276
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(
277
                        block.get_by_position(arguments[0]).type.get());
278
                auto scale = type->get_scale();
279
280
                const auto* to_type = assert_cast<const DataTypeDateTimeV2*>(
281
                        block.get_by_position(result).type.get());
282
                UInt32 to_scale = to_type->get_scale();
283
284
                bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i],
285
                                                    col_from->get_data()[i]);
286
                if (!success) {
287
                    if constexpr (CastMode == CastModeType::StrictMode) {
288
                        auto format_options = DataTypeSerDe::get_default_format_options();
289
                        auto time_zone = cctz::utc_time_zone();
290
                        format_options.timezone = (context && context->state())
291
                                                          ? &context->state()->timezone_obj()
292
                                                          : &time_zone;
293
                        return Status::InvalidArgument(
294
                                "DatetimeV2 overflow when casting {} from {} to {}",
295
                                type->to_string(*col_from, i, format_options), type->get_name(),
296
                                to_type->get_name());
297
                    } else {
298
                        col_nullmap->get_data()[i] = true;
299
                        //TODO: maybe we can remove all set operations on nested of null cell.
300
                        // the correctness should be keep by downstream user with replace_... or manually
301
                        // process null data if need.
302
                        col_to->get_data()[i] =
303
                                binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
304
                                        MIN_DATETIME_V2);
305
                    }
306
                }
307
308
            } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
309
                const auto* type = assert_cast<const DataTypeTimeV2*>(
310
                        block.get_by_position(arguments[0]).type.get());
311
                auto scale = type->get_scale();
312
313
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(
314
                        block.get_by_position(result).type.get());
315
                UInt32 to_scale = to_type->get_scale();
316
317
                if (to_scale >= scale) {
318
                    // nothing to do, just copy
319
                    col_to->get_data()[i] = col_from->get_data()[i];
320
                } else {
321
                    double time = col_from->get_data()[i];
322
                    auto sign = TimeValue::sign(time);
323
                    time = std::abs(time);
324
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
325
                    // 999956: 56 > 100/2, then round up to 1000000
326
                    uint32_t microseconds = TimeValue::microsecond(time);
327
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
328
                    uint32_t remainder = microseconds % divisor;
329
330
                    if (remainder >= divisor / 2) { // need to round up
331
                        // do rounding up
332
                        uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor;
333
                        // need carry on
334
                        if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
335
                            DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS);
336
                            time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) *
337
                                   TimeValue::ONE_SECOND_MICROSECONDS;
338
339
                            // the input data must be valid, so max to '838:59:59.0'. this value won't carry on
340
                            // to second.
341
                            DCHECK(TimeValue::valid(time)) << col_from->get_data()[i];
342
                        } else {
343
                            time = TimeValue::reset_microsecond(time, rounded_microseconds);
344
                        }
345
                    } else {
346
                        // truncate
347
                        time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor);
348
                    }
349
                    col_to->get_data()[i] = sign * time;
350
                }
351
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
352
                // from Datetime to Time
353
                auto dtmv2 = col_from->get_data()[i];
354
355
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(
356
                        block.get_by_position(arguments[0]).type.get());
357
                auto scale = type->get_scale();
358
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(
359
                        block.get_by_position(result).type.get());
360
                UInt32 to_scale = to_type->get_scale();
361
362
                uint32_t hour = dtmv2.hour();
363
                uint32_t minute = dtmv2.minute();
364
                uint32_t second = dtmv2.second();
365
                uint32_t microseconds = dtmv2.microsecond();
366
                if (to_scale < scale) { // need to round
367
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
368
                    // 999956: 56 > 100/2, then round up to 1000000
369
                    DCHECK(to_scale <= 6)
370
                            << "to_scale should be in range [0, 6], but got " << to_scale;
371
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
372
                    uint32_t remainder = microseconds % divisor;
373
                    microseconds = (microseconds / divisor) * divisor;
374
                    if (remainder >= divisor / 2) {
375
                        // do rounding up
376
                        microseconds += divisor;
377
                    }
378
                }
379
380
                // carry on if microseconds >= 1000000
381
                if (microseconds >= 1000000) {
382
                    microseconds -= 1000000;
383
                    second += 1;
384
                    if (second >= 60) {
385
                        second -= 60;
386
                        minute += 1;
387
                        if (minute >= 60) {
388
                            minute -= 60;
389
                            hour += 1;
390
                        }
391
                    }
392
                }
393
394
                auto time = TimeValue::limit_with_bound(
395
                        TimeValue::make_time(hour, minute, second, microseconds));
396
                col_to->get_data()[i] = time;
397
            } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) {
398
                auto dtmv1 = col_from->get_data()[i];
399
                auto time = TimeValue::limit_with_bound(
400
                        TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second()));
401
                col_to->get_data()[i] = time;
402
            }
403
6
        }
404
405
        if constexpr (Nullable) {
406
            block.get_by_position(result).column =
407
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
408
2
        } else {
409
2
            block.get_by_position(result).column = std::move(col_to);
410
2
        }
411
2
        return Status::OK();
412
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
140
1
                        const NullMap::value_type* null_map = nullptr) const override {
141
1
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
142
1
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
143
144
1
        const auto* col_from = check_and_get_column<typename FromDataType::ColumnType>(
145
1
                block.get_by_position(arguments[0]).column.get());
146
1
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
147
1
        ColumnUInt8::MutablePtr col_nullmap;
148
149
        if constexpr (Nullable) {
150
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
151
        }
152
153
2
        for (size_t i = 0; i < input_rows_count; ++i) {
154
1
            if (null_map && null_map[i]) {
155
0
                continue;
156
0
            }
157
            if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) {
158
                // from Date to Date
159
                auto dtv1 = col_from->get_data()[i];
160
                dtv1.cast_to_date();
161
                col_to->get_data()[i] =
162
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2());
163
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) {
164
                DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
165
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) {
166
                // from Datetime to Date
167
                col_to->get_data()[i] = col_from->get_data()[i];
168
                DataTypeDate::cast_to_date(col_to->get_data()[i]);
169
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
170
                DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
171
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) {
172
                auto dtmv1 = col_from->get_data()[i];
173
                col_to->get_data()[i] =
174
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2());
175
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
176
                DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]);
177
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
178
                // from Time to Date
179
                VecDateTimeValue dtv;
180
                dtv.cast_to_date();
181
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
182
                                  context->state()->timezone_obj());
183
184
                auto time_value = col_from->get_data()[i];
185
                int32_t hour = TimeValue::hour(time_value);
186
                int32_t minute = TimeValue::minute(time_value);
187
                int32_t second = TimeValue::second(time_value);
188
                bool neg = TimeValue::sign(time_value) < 0;
189
190
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
191
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
192
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
193
194
                col_to->get_data()[i] = dtv;
195
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
196
                DateV2Value<DateV2ValueType> dtv;
197
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
198
                                  context->state()->timezone_obj());
199
200
                auto time_value = col_from->get_data()[i];
201
                int32_t hour = TimeValue::hour(time_value);
202
                int32_t minute = TimeValue::minute(time_value);
203
                int32_t second = TimeValue::second(time_value);
204
                bool neg = TimeValue::sign(time_value) < 0;
205
206
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
207
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
208
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
209
210
                col_to->get_data()[i] = dtv;
211
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) {
212
                // from Date to Datetime
213
                col_to->get_data()[i] = col_from->get_data()[i];
214
                DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]);
215
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
216
                DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]);
217
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
218
                auto dtv1 = col_from->get_data()[i];
219
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
220
                        dtv1.to_datetime_v2());
221
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
222
                DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i],
223
                                                     col_to->get_data()[i]);
224
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
225
                // from Time to Datetime
226
                VecDateTimeValue dtv; // datetime by default
227
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
228
                                  context->state()->timezone_obj());
229
                dtv.reset_time_part();
230
231
                auto time_value = col_from->get_data()[i];
232
                int32_t hour = TimeValue::hour(time_value);
233
                int32_t minute = TimeValue::minute(time_value);
234
                int32_t second = TimeValue::second(time_value);
235
                bool neg = TimeValue::sign(time_value) < 0;
236
237
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
238
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
239
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
240
241
                col_to->get_data()[i] = dtv;
242
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
243
                const auto* type = assert_cast<const DataTypeTimeV2*>(
244
                        block.get_by_position(arguments[0]).type.get());
245
                auto scale = type->get_scale();
246
247
                DateV2Value<DateTimeV2ValueType> dtmv2;
248
                dtmv2.from_unixtime(context->state()->timestamp_ms() / 1000,
249
                                    context->state()->nano_seconds(),
250
                                    context->state()->timezone_obj(), scale);
251
                dtmv2.reset_time_part();
252
253
                auto time_value = col_from->get_data()[i];
254
                int32_t hour = TimeValue::hour(time_value);
255
                int32_t minute = TimeValue::minute(time_value);
256
                int32_t second = TimeValue::second(time_value);
257
                int32_t microsecond = TimeValue::microsecond(time_value);
258
                bool neg = TimeValue::sign(time_value) < 0;
259
260
                dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
261
                dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
262
                dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
263
                dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>(
264
                        TimeInterval(MICROSECOND, microsecond, neg));
265
266
                col_to->get_data()[i] = dtmv2;
267
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
268
                // from Datetime to Datetime
269
                auto dtmv1 = col_from->get_data()[i];
270
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
271
                        dtmv1.to_datetime_v2());
272
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
273
                DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i],
274
                                                      col_to->get_data()[i]);
275
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
276
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(
277
                        block.get_by_position(arguments[0]).type.get());
278
                auto scale = type->get_scale();
279
280
                const auto* to_type = assert_cast<const DataTypeDateTimeV2*>(
281
                        block.get_by_position(result).type.get());
282
                UInt32 to_scale = to_type->get_scale();
283
284
                bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i],
285
                                                    col_from->get_data()[i]);
286
                if (!success) {
287
                    if constexpr (CastMode == CastModeType::StrictMode) {
288
                        auto format_options = DataTypeSerDe::get_default_format_options();
289
                        auto time_zone = cctz::utc_time_zone();
290
                        format_options.timezone = (context && context->state())
291
                                                          ? &context->state()->timezone_obj()
292
                                                          : &time_zone;
293
                        return Status::InvalidArgument(
294
                                "DatetimeV2 overflow when casting {} from {} to {}",
295
                                type->to_string(*col_from, i, format_options), type->get_name(),
296
                                to_type->get_name());
297
                    } else {
298
                        col_nullmap->get_data()[i] = true;
299
                        //TODO: maybe we can remove all set operations on nested of null cell.
300
                        // the correctness should be keep by downstream user with replace_... or manually
301
                        // process null data if need.
302
                        col_to->get_data()[i] =
303
                                binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
304
                                        MIN_DATETIME_V2);
305
                    }
306
                }
307
308
            } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
309
                const auto* type = assert_cast<const DataTypeTimeV2*>(
310
                        block.get_by_position(arguments[0]).type.get());
311
                auto scale = type->get_scale();
312
313
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(
314
                        block.get_by_position(result).type.get());
315
                UInt32 to_scale = to_type->get_scale();
316
317
                if (to_scale >= scale) {
318
                    // nothing to do, just copy
319
                    col_to->get_data()[i] = col_from->get_data()[i];
320
                } else {
321
                    double time = col_from->get_data()[i];
322
                    auto sign = TimeValue::sign(time);
323
                    time = std::abs(time);
324
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
325
                    // 999956: 56 > 100/2, then round up to 1000000
326
                    uint32_t microseconds = TimeValue::microsecond(time);
327
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
328
                    uint32_t remainder = microseconds % divisor;
329
330
                    if (remainder >= divisor / 2) { // need to round up
331
                        // do rounding up
332
                        uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor;
333
                        // need carry on
334
                        if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
335
                            DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS);
336
                            time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) *
337
                                   TimeValue::ONE_SECOND_MICROSECONDS;
338
339
                            // the input data must be valid, so max to '838:59:59.0'. this value won't carry on
340
                            // to second.
341
                            DCHECK(TimeValue::valid(time)) << col_from->get_data()[i];
342
                        } else {
343
                            time = TimeValue::reset_microsecond(time, rounded_microseconds);
344
                        }
345
                    } else {
346
                        // truncate
347
                        time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor);
348
                    }
349
                    col_to->get_data()[i] = sign * time;
350
                }
351
1
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
352
                // from Datetime to Time
353
1
                auto dtmv2 = col_from->get_data()[i];
354
355
1
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(
356
1
                        block.get_by_position(arguments[0]).type.get());
357
1
                auto scale = type->get_scale();
358
1
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(
359
1
                        block.get_by_position(result).type.get());
360
1
                UInt32 to_scale = to_type->get_scale();
361
362
1
                uint32_t hour = dtmv2.hour();
363
1
                uint32_t minute = dtmv2.minute();
364
1
                uint32_t second = dtmv2.second();
365
1
                uint32_t microseconds = dtmv2.microsecond();
366
1
                if (to_scale < scale) { // need to round
367
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
368
                    // 999956: 56 > 100/2, then round up to 1000000
369
1
                    DCHECK(to_scale <= 6)
370
0
                            << "to_scale should be in range [0, 6], but got " << to_scale;
371
1
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
372
1
                    uint32_t remainder = microseconds % divisor;
373
1
                    microseconds = (microseconds / divisor) * divisor;
374
1
                    if (remainder >= divisor / 2) {
375
                        // do rounding up
376
1
                        microseconds += divisor;
377
1
                    }
378
1
                }
379
380
                // carry on if microseconds >= 1000000
381
1
                if (microseconds >= 1000000) {
382
0
                    microseconds -= 1000000;
383
0
                    second += 1;
384
0
                    if (second >= 60) {
385
0
                        second -= 60;
386
0
                        minute += 1;
387
0
                        if (minute >= 60) {
388
0
                            minute -= 60;
389
0
                            hour += 1;
390
0
                        }
391
0
                    }
392
0
                }
393
394
1
                auto time = TimeValue::limit_with_bound(
395
1
                        TimeValue::make_time(hour, minute, second, microseconds));
396
1
                col_to->get_data()[i] = time;
397
            } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) {
398
                auto dtmv1 = col_from->get_data()[i];
399
                auto time = TimeValue::limit_with_bound(
400
                        TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second()));
401
                col_to->get_data()[i] = time;
402
            }
403
1
        }
404
405
        if constexpr (Nullable) {
406
            block.get_by_position(result).column =
407
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
408
1
        } else {
409
1
            block.get_by_position(result).column = std::move(col_to);
410
1
        }
411
1
        return Status::OK();
412
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
413
};
414
415
template <>
416
class CastToImpl<CastModeType::StrictMode, DataTypeTimeStampTz, DataTypeDateTimeV2>
417
        : public CastToBase {
418
public:
419
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
420
                        uint32_t result, size_t input_rows_count,
421
2
                        const NullMap::value_type* null_map = nullptr) const override {
422
2
        const auto& col_from =
423
2
                assert_cast<const ColumnTimeStampTz&>(*block.get_by_position(arguments[0]).column)
424
2
                        .get_data();
425
426
2
        auto col_to = ColumnDateTimeV2::create(input_rows_count);
427
2
        auto& col_to_data = col_to->get_data();
428
2
        const auto& local_time_zone = context->state()->timezone_obj();
429
430
2
        const auto tz_scale = block.get_by_position(arguments[0]).type->get_scale();
431
2
        const auto dt_scale = block.get_by_position(result).type->get_scale();
432
433
9
        for (int i = 0; i < input_rows_count; ++i) {
434
8
            if (null_map && null_map[i]) {
435
0
                continue;
436
0
            }
437
8
            TimestampTzValue from_tz {col_from[i]};
438
8
            DateV2Value<DateTimeV2ValueType> dt;
439
8
            if (!from_tz.to_datetime(dt, local_time_zone, dt_scale, tz_scale)) {
440
1
                return Status::InternalError(
441
1
                        "can not cast from  timestamptz : {} to datetime in timezone : {}",
442
1
                        from_tz.to_string(local_time_zone), context->state()->timezone());
443
1
            }
444
7
            col_to_data[i] = dt.to_date_int_val();
445
7
        }
446
447
1
        block.get_by_position(result).column = std::move(col_to);
448
1
        return Status::OK();
449
2
    }
450
};
451
452
template <>
453
class CastToImpl<CastModeType::NonStrictMode, DataTypeTimeStampTz, DataTypeDateTimeV2>
454
        : public CastToBase {
455
public:
456
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
457
                        uint32_t result, size_t input_rows_count,
458
2
                        const NullMap::value_type*) const override {
459
2
        const auto& col_from =
460
2
                assert_cast<const ColumnTimeStampTz&>(*block.get_by_position(arguments[0]).column)
461
2
                        .get_data();
462
463
2
        auto col_to = ColumnDateTimeV2::create(input_rows_count);
464
2
        auto& col_to_data = col_to->get_data();
465
2
        auto col_null = ColumnBool::create(input_rows_count, 0);
466
2
        auto& col_null_map = col_null->get_data();
467
2
        const auto& local_time_zone = context->state()->timezone_obj();
468
469
2
        const auto tz_scale = block.get_by_position(arguments[0]).type->get_scale();
470
2
        const auto dt_scale = block.get_by_position(result).type->get_scale();
471
472
10
        for (int i = 0; i < input_rows_count; ++i) {
473
8
            TimestampTzValue from_tz {col_from[i]};
474
8
            DateV2Value<DateTimeV2ValueType> dt;
475
8
            if (from_tz.to_datetime(dt, local_time_zone, dt_scale, tz_scale)) {
476
7
                col_to_data[i] = dt;
477
7
            } else {
478
1
                col_null_map[i] = 1;
479
1
                col_to_data[i] = MIN_DATETIME_V2;
480
1
            }
481
8
        }
482
2
        block.get_by_position(result).column =
483
2
                ColumnNullable::create(std::move(col_to), std::move(col_null));
484
2
        return Status::OK();
485
2
    }
486
};
487
} // namespace doris