Coverage Report

Created: 2026-05-23 04:27

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