Coverage Report

Created: 2026-09-10 07:03

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