Coverage Report

Created: 2026-09-28 17:01

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
232
                        const NullMap::value_type* null_map = nullptr) const override {
54
232
        const auto* col_from = assert_cast<const DataTypeString::ColumnType*>(
55
232
                block.get_by_position(arguments[0]).column.get());
56
57
232
        auto to_type = block.get_by_position(result).type;
58
232
        auto nested_to_type = remove_nullable(to_type);
59
232
        auto serde = nested_to_type->get_serde();
60
61
232
        DataTypeSerDe::FormatOptions options;
62
232
        options.timezone = &context->state()->timezone_obj();
63
64
232
        if constexpr (CastMode == CastModeType::StrictMode) {
65
216
            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
216
            RETURN_IF_ERROR(
68
216
                    serde->from_string_strict_mode_batch(*col_from, *column_to, options, null_map));
69
8
            block.get_by_position(result).column = std::move(column_to);
70
16
        } else {
71
16
            auto nullable_col_to = create_empty_nullable_column(nested_to_type);
72
            // may write nulls to nullable_col_to
73
16
            RETURN_IF_ERROR(serde->from_string_batch(*col_from, *nullable_col_to, options));
74
16
            block.get_by_position(result).column = std::move(nullable_col_to);
75
16
        }
76
77
0
        return Status::OK();
78
232
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeStringENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
53
2
                        const NullMap::value_type* null_map = nullptr) const override {
54
2
        const auto* col_from = assert_cast<const DataTypeString::ColumnType*>(
55
2
                block.get_by_position(arguments[0]).column.get());
56
57
2
        auto to_type = block.get_by_position(result).type;
58
2
        auto nested_to_type = remove_nullable(to_type);
59
2
        auto serde = nested_to_type->get_serde();
60
61
2
        DataTypeSerDe::FormatOptions options;
62
2
        options.timezone = &context->state()->timezone_obj();
63
64
2
        if constexpr (CastMode == CastModeType::StrictMode) {
65
2
            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
2
            RETURN_IF_ERROR(
68
2
                    serde->from_string_strict_mode_batch(*col_from, *column_to, options, null_map));
69
2
            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
2
    }
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
96
                        const NullMap::value_type* null_map = nullptr) const override {
54
96
        const auto* col_from = assert_cast<const DataTypeString::ColumnType*>(
55
96
                block.get_by_position(arguments[0]).column.get());
56
57
96
        auto to_type = block.get_by_position(result).type;
58
96
        auto nested_to_type = remove_nullable(to_type);
59
96
        auto serde = nested_to_type->get_serde();
60
61
96
        DataTypeSerDe::FormatOptions options;
62
96
        options.timezone = &context->state()->timezone_obj();
63
64
96
        if constexpr (CastMode == CastModeType::StrictMode) {
65
96
            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
96
            RETURN_IF_ERROR(
68
96
                    serde->from_string_strict_mode_batch(*col_from, *column_to, options, null_map));
69
2
            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
96
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeStringENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
53
8
                        const NullMap::value_type* null_map = nullptr) const override {
54
8
        const auto* col_from = assert_cast<const DataTypeString::ColumnType*>(
55
8
                block.get_by_position(arguments[0]).column.get());
56
57
8
        auto to_type = block.get_by_position(result).type;
58
8
        auto nested_to_type = remove_nullable(to_type);
59
8
        auto serde = nested_to_type->get_serde();
60
61
8
        DataTypeSerDe::FormatOptions options;
62
8
        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
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
8
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeStringENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
53
96
                        const NullMap::value_type* null_map = nullptr) const override {
54
96
        const auto* col_from = assert_cast<const DataTypeString::ColumnType*>(
55
96
                block.get_by_position(arguments[0]).column.get());
56
57
96
        auto to_type = block.get_by_position(result).type;
58
96
        auto nested_to_type = remove_nullable(to_type);
59
96
        auto serde = nested_to_type->get_serde();
60
61
96
        DataTypeSerDe::FormatOptions options;
62
96
        options.timezone = &context->state()->timezone_obj();
63
64
96
        if constexpr (CastMode == CastModeType::StrictMode) {
65
96
            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
96
            RETURN_IF_ERROR(
68
96
                    serde->from_string_strict_mode_batch(*col_from, *column_to, options, null_map));
69
2
            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
96
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeStringENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
53
6
                        const NullMap::value_type* null_map = nullptr) const override {
54
6
        const auto* col_from = assert_cast<const DataTypeString::ColumnType*>(
55
6
                block.get_by_position(arguments[0]).column.get());
56
57
6
        auto to_type = block.get_by_position(result).type;
58
6
        auto nested_to_type = remove_nullable(to_type);
59
6
        auto serde = nested_to_type->get_serde();
60
61
6
        DataTypeSerDe::FormatOptions options;
62
6
        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
6
        } else {
71
6
            auto nullable_col_to = create_empty_nullable_column(nested_to_type);
72
            // may write nulls to nullable_col_to
73
6
            RETURN_IF_ERROR(serde->from_string_batch(*col_from, *nullable_col_to, options));
74
6
            block.get_by_position(result).column = std::move(nullable_col_to);
75
6
        }
76
77
0
        return Status::OK();
78
6
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeStringENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
53
22
                        const NullMap::value_type* null_map = nullptr) const override {
54
22
        const auto* col_from = assert_cast<const DataTypeString::ColumnType*>(
55
22
                block.get_by_position(arguments[0]).column.get());
56
57
22
        auto to_type = block.get_by_position(result).type;
58
22
        auto nested_to_type = remove_nullable(to_type);
59
22
        auto serde = nested_to_type->get_serde();
60
61
22
        DataTypeSerDe::FormatOptions options;
62
22
        options.timezone = &context->state()->timezone_obj();
63
64
22
        if constexpr (CastMode == CastModeType::StrictMode) {
65
22
            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
22
            RETURN_IF_ERROR(
68
22
                    serde->from_string_strict_mode_batch(*col_from, *column_to, options, null_map));
69
2
            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
22
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeStringENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
53
2
                        const NullMap::value_type* null_map = nullptr) const override {
54
2
        const auto* col_from = assert_cast<const DataTypeString::ColumnType*>(
55
2
                block.get_by_position(arguments[0]).column.get());
56
57
2
        auto to_type = block.get_by_position(result).type;
58
2
        auto nested_to_type = remove_nullable(to_type);
59
2
        auto serde = nested_to_type->get_serde();
60
61
2
        DataTypeSerDe::FormatOptions options;
62
2
        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
2
        } else {
71
2
            auto nullable_col_to = create_empty_nullable_column(nested_to_type);
72
            // may write nulls to nullable_col_to
73
2
            RETURN_IF_ERROR(serde->from_string_batch(*col_from, *nullable_col_to, options));
74
2
            block.get_by_position(result).column = std::move(nullable_col_to);
75
2
        }
76
77
0
        return Status::OK();
78
2
    }
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
74
                        const NullMap::value_type* null_map = nullptr) const override {
88
74
        const auto* col_from = assert_cast<const typename FromDataType::ColumnType*>(
89
74
                block.get_by_position(arguments[0]).column.get());
90
74
        auto to_type = block.get_by_position(result).type;
91
74
        auto nested_to_type = remove_nullable(to_type);
92
74
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
93
74
                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
74
        if constexpr (CastMode == CastModeType::StrictMode) {
98
42
            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
42
            if constexpr (IsDataTypeInt<FromDataType>) {
101
20
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
102
20
                        *col_from, *column_to));
103
20
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
104
20
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
105
20
                        *col_from, *column_to));
106
20
            } else {
107
2
                static_assert(IsDataTypeDecimal<FromDataType>);
108
2
                RETURN_IF_ERROR(
109
2
                        concrete_serde->template from_decimal_strict_mode_batch<FromDataType>(
110
2
                                *col_from, *column_to));
111
2
            }
112
0
            block.get_by_position(result).column = std::move(column_to);
113
42
        } else {
114
32
            auto nullable_col_to = create_empty_nullable_column(nested_to_type);
115
            // may write nulls to nullable_col_to
116
32
            if constexpr (IsDataTypeInt<FromDataType>) {
117
10
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
10
                        *col_from, *nullable_col_to));
119
10
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
10
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
10
                        *col_from, *nullable_col_to));
122
12
            } else {
123
12
                static_assert(IsDataTypeDecimal<FromDataType>);
124
12
                RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>(
125
12
                        *col_from, *nullable_col_to));
126
12
            }
127
32
            block.get_by_position(result).column = std::move(nullable_col_to);
128
32
        }
129
130
0
        return Status::OK();
131
74
    }
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
10
                        const NullMap::value_type* null_map = nullptr) const override {
88
10
        const auto* col_from = assert_cast<const typename FromDataType::ColumnType*>(
89
10
                block.get_by_position(arguments[0]).column.get());
90
10
        auto to_type = block.get_by_position(result).type;
91
10
        auto nested_to_type = remove_nullable(to_type);
92
10
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
93
10
                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
10
        if constexpr (CastMode == CastModeType::StrictMode) {
98
10
            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
10
            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
            } 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
10
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
87
4
                        const NullMap::value_type* null_map = nullptr) const override {
88
4
        const auto* col_from = assert_cast<const typename FromDataType::ColumnType*>(
89
4
                block.get_by_position(arguments[0]).column.get());
90
4
        auto to_type = block.get_by_position(result).type;
91
4
        auto nested_to_type = remove_nullable(to_type);
92
4
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
93
4
                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
4
        } else {
114
4
            auto nullable_col_to = create_empty_nullable_column(nested_to_type);
115
            // may write nulls to nullable_col_to
116
4
            if constexpr (IsDataTypeInt<FromDataType>) {
117
4
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
4
                        *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
4
            block.get_by_position(result).column = std::move(nullable_col_to);
128
4
        }
129
130
0
        return Status::OK();
131
4
    }
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
10
                        const NullMap::value_type* null_map = nullptr) const override {
88
10
        const auto* col_from = assert_cast<const typename FromDataType::ColumnType*>(
89
10
                block.get_by_position(arguments[0]).column.get());
90
10
        auto to_type = block.get_by_position(result).type;
91
10
        auto nested_to_type = remove_nullable(to_type);
92
10
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
93
10
                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
10
        if constexpr (CastMode == CastModeType::StrictMode) {
98
10
            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
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
            } 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
10
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
87
4
                        const NullMap::value_type* null_map = nullptr) const override {
88
4
        const auto* col_from = assert_cast<const typename FromDataType::ColumnType*>(
89
4
                block.get_by_position(arguments[0]).column.get());
90
4
        auto to_type = block.get_by_position(result).type;
91
4
        auto nested_to_type = remove_nullable(to_type);
92
4
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
93
4
                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
4
        } else {
114
4
            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
4
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
4
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
4
                        *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
4
            block.get_by_position(result).column = std::move(nullable_col_to);
128
4
        }
129
130
0
        return Status::OK();
131
4
    }
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
4
                        const NullMap::value_type* null_map = nullptr) const override {
88
4
        const auto* col_from = assert_cast<const typename FromDataType::ColumnType*>(
89
4
                block.get_by_position(arguments[0]).column.get());
90
4
        auto to_type = block.get_by_position(result).type;
91
4
        auto nested_to_type = remove_nullable(to_type);
92
4
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
93
4
                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
4
        } else {
114
4
            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
4
            } else {
123
4
                static_assert(IsDataTypeDecimal<FromDataType>);
124
4
                RETURN_IF_ERROR(concrete_serde->template from_decimal_batch<FromDataType>(
125
4
                        *col_from, *nullable_col_to));
126
4
            }
127
4
            block.get_by_position(result).column = std::move(nullable_col_to);
128
4
        }
129
130
0
        return Status::OK();
131
4
    }
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
10
                        const NullMap::value_type* null_map = nullptr) const override {
88
10
        const auto* col_from = assert_cast<const typename FromDataType::ColumnType*>(
89
10
                block.get_by_position(arguments[0]).column.get());
90
10
        auto to_type = block.get_by_position(result).type;
91
10
        auto nested_to_type = remove_nullable(to_type);
92
10
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
93
10
                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
10
        if constexpr (CastMode == CastModeType::StrictMode) {
98
10
            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
10
            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
            } 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
10
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
87
4
                        const NullMap::value_type* null_map = nullptr) const override {
88
4
        const auto* col_from = assert_cast<const typename FromDataType::ColumnType*>(
89
4
                block.get_by_position(arguments[0]).column.get());
90
4
        auto to_type = block.get_by_position(result).type;
91
4
        auto nested_to_type = remove_nullable(to_type);
92
4
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
93
4
                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
4
        } else {
114
4
            auto nullable_col_to = create_empty_nullable_column(nested_to_type);
115
            // may write nulls to nullable_col_to
116
4
            if constexpr (IsDataTypeInt<FromDataType>) {
117
4
                RETURN_IF_ERROR(concrete_serde->template from_int_batch<FromDataType>(
118
4
                        *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
4
            block.get_by_position(result).column = std::move(nullable_col_to);
128
4
        }
129
130
0
        return Status::OK();
131
4
    }
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
10
                        const NullMap::value_type* null_map = nullptr) const override {
88
10
        const auto* col_from = assert_cast<const typename FromDataType::ColumnType*>(
89
10
                block.get_by_position(arguments[0]).column.get());
90
10
        auto to_type = block.get_by_position(result).type;
91
10
        auto nested_to_type = remove_nullable(to_type);
92
10
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
93
10
                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
10
        if constexpr (CastMode == CastModeType::StrictMode) {
98
10
            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
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
            } 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
10
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
87
4
                        const NullMap::value_type* null_map = nullptr) const override {
88
4
        const auto* col_from = assert_cast<const typename FromDataType::ColumnType*>(
89
4
                block.get_by_position(arguments[0]).column.get());
90
4
        auto to_type = block.get_by_position(result).type;
91
4
        auto nested_to_type = remove_nullable(to_type);
92
4
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
93
4
                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
4
        } else {
114
4
            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
4
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
120
4
                RETURN_IF_ERROR(concrete_serde->template from_float_batch<FromDataType>(
121
4
                        *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
4
            block.get_by_position(result).column = std::move(nullable_col_to);
128
4
        }
129
130
0
        return Status::OK();
131
4
    }
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
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
2
        if constexpr (CastMode == CastModeType::StrictMode) {
98
2
            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
2
            } else {
107
2
                static_assert(IsDataTypeDecimal<FromDataType>);
108
2
                RETURN_IF_ERROR(
109
2
                        concrete_serde->template from_decimal_strict_mode_batch<FromDataType>(
110
2
                                *col_from, *column_to));
111
2
            }
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
2
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
87
6
                        const NullMap::value_type* null_map = nullptr) const override {
88
6
        const auto* col_from = assert_cast<const typename FromDataType::ColumnType*>(
89
6
                block.get_by_position(arguments[0]).column.get());
90
6
        auto to_type = block.get_by_position(result).type;
91
6
        auto nested_to_type = remove_nullable(to_type);
92
6
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
93
6
                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
6
        } else {
114
6
            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
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
6
            block.get_by_position(result).column = std::move(nullable_col_to);
128
6
        }
129
130
0
        return Status::OK();
131
6
    }
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
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_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
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_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
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_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
12
                        const NullMap::value_type* null_map = nullptr) const override {
141
12
        const auto& col_from =
142
12
                assert_cast<const ColumnTimeStampNs&>(*block.get_by_position(arguments[0]).column);
143
12
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
144
145
52
        for (size_t i = 0; i < input_rows_count; ++i) {
146
40
            if (null_map && null_map[i]) {
147
0
                continue;
148
0
            }
149
150
40
            const auto& source = col_from.get_data()[i];
151
40
            if constexpr (IsDateType<ToDataType>) {
152
6
                const auto civil = source.to_datetime();
153
6
                DataTypeDateTimeV2::cast_to_date(civil, col_to->get_data()[i]);
154
6
            } else if constexpr (IsDateV2Type<ToDataType>) {
155
6
                col_to->get_data()[i] = source.to_date();
156
6
            } else if constexpr (IsDateTimeType<ToDataType>) {
157
6
                const auto civil = source.to_datetime();
158
6
                DataTypeDateTimeV2::cast_to_date_time(civil, col_to->get_data()[i]);
159
16
            } else if constexpr (IsDateTimeV2Type<ToDataType>) {
160
16
                const auto to_scale = block.get_by_position(result).type->get_scale();
161
16
                const bool success =
162
16
                        transform_date_scale(to_scale, TimeStampNsValue::FRACTIONAL_DIGITS,
163
16
                                             col_to->get_data()[i], source);
164
16
                DORIS_CHECK(success);
165
16
            } else {
166
6
                static_assert(IsTimeV2Type<ToDataType>);
167
6
                const auto to_scale = block.get_by_position(result).type->get_scale();
168
6
                const int64_t seconds = source.time_part_to_seconds();
169
6
                uint32_t hour = static_cast<uint32_t>(seconds / 3600);
170
6
                uint32_t minute = static_cast<uint32_t>(seconds / 60 % 60);
171
6
                uint32_t second = static_cast<uint32_t>(seconds % 60);
172
6
                uint32_t nanoseconds = source.nanosecond();
173
6
                const auto divisor = static_cast<uint32_t>(common::exp10_i64(9 - to_scale));
174
6
                const uint32_t remainder = nanoseconds % divisor;
175
6
                nanoseconds = nanoseconds / divisor * divisor;
176
6
                if (remainder >= divisor / 2) {
177
4
                    nanoseconds += divisor;
178
4
                }
179
6
                uint32_t microseconds = nanoseconds / TimeStampNsValue::NANOS_PER_MICROSECOND;
180
6
                if (microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
181
2
                    microseconds = 0;
182
2
                    if (++second == 60) {
183
2
                        second = 0;
184
2
                        if (++minute == 60) {
185
2
                            minute = 0;
186
2
                            ++hour;
187
2
                        }
188
2
                    }
189
2
                }
190
6
                col_to->get_data()[i] =
191
6
                        ((hour * 60 + minute) * 60 + second) * TimeValue::ONE_SECOND_MICROSECONDS +
192
6
                        microseconds;
193
6
            }
194
40
        }
195
196
12
        block.get_by_position(result).column = std::move(col_to);
197
12
        return Status::OK();
198
12
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_19DataTypeTimeStampNsENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_19DataTypeTimeStampNsENS_12DataTypeDateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
140
2
                        const NullMap::value_type* null_map = nullptr) const override {
141
2
        const auto& col_from =
142
2
                assert_cast<const ColumnTimeStampNs&>(*block.get_by_position(arguments[0]).column);
143
2
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
144
145
8
        for (size_t i = 0; i < input_rows_count; ++i) {
146
6
            if (null_map && null_map[i]) {
147
0
                continue;
148
0
            }
149
150
6
            const auto& source = col_from.get_data()[i];
151
6
            if constexpr (IsDateType<ToDataType>) {
152
6
                const auto civil = source.to_datetime();
153
6
                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
6
        }
195
196
2
        block.get_by_position(result).column = std::move(col_to);
197
2
        return Status::OK();
198
2
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_19DataTypeTimeStampNsENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_19DataTypeTimeStampNsENS_16DataTypeDateTimeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
140
2
                        const NullMap::value_type* null_map = nullptr) const override {
141
2
        const auto& col_from =
142
2
                assert_cast<const ColumnTimeStampNs&>(*block.get_by_position(arguments[0]).column);
143
2
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
144
145
8
        for (size_t i = 0; i < input_rows_count; ++i) {
146
6
            if (null_map && null_map[i]) {
147
0
                continue;
148
0
            }
149
150
6
            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
6
            } else if constexpr (IsDateTimeType<ToDataType>) {
157
6
                const auto civil = source.to_datetime();
158
6
                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
6
        }
195
196
2
        block.get_by_position(result).column = std::move(col_to);
197
2
        return Status::OK();
198
2
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_19DataTypeTimeStampNsENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_19DataTypeTimeStampNsENS_14DataTypeDateV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
140
2
                        const NullMap::value_type* null_map = nullptr) const override {
141
2
        const auto& col_from =
142
2
                assert_cast<const ColumnTimeStampNs&>(*block.get_by_position(arguments[0]).column);
143
2
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
144
145
8
        for (size_t i = 0; i < input_rows_count; ++i) {
146
6
            if (null_map && null_map[i]) {
147
0
                continue;
148
0
            }
149
150
6
            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
6
            } else if constexpr (IsDateV2Type<ToDataType>) {
155
6
                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
6
        }
195
196
2
        block.get_by_position(result).column = std::move(col_to);
197
2
        return Status::OK();
198
2
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_19DataTypeTimeStampNsENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
140
2
                        const NullMap::value_type* null_map = nullptr) const override {
141
2
        const auto& col_from =
142
2
                assert_cast<const ColumnTimeStampNs&>(*block.get_by_position(arguments[0]).column);
143
2
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
144
145
10
        for (size_t i = 0; i < input_rows_count; ++i) {
146
8
            if (null_map && null_map[i]) {
147
0
                continue;
148
0
            }
149
150
8
            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
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
            } 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
8
        }
195
196
2
        block.get_by_position(result).column = std::move(col_to);
197
2
        return Status::OK();
198
2
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_19DataTypeTimeStampNsENS_18DataTypeDateTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
140
2
                        const NullMap::value_type* null_map = nullptr) const override {
141
2
        const auto& col_from =
142
2
                assert_cast<const ColumnTimeStampNs&>(*block.get_by_position(arguments[0]).column);
143
2
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
144
145
10
        for (size_t i = 0; i < input_rows_count; ++i) {
146
8
            if (null_map && null_map[i]) {
147
0
                continue;
148
0
            }
149
150
8
            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
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
            } 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
8
        }
195
196
2
        block.get_by_position(result).column = std::move(col_to);
197
2
        return Status::OK();
198
2
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_19DataTypeTimeStampNsENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_19DataTypeTimeStampNsENS_14DataTypeTimeV2EE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmPKh
Line
Count
Source
140
2
                        const NullMap::value_type* null_map = nullptr) const override {
141
2
        const auto& col_from =
142
2
                assert_cast<const ColumnTimeStampNs&>(*block.get_by_position(arguments[0]).column);
143
2
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
144
145
8
        for (size_t i = 0; i < input_rows_count; ++i) {
146
6
            if (null_map && null_map[i]) {
147
0
                continue;
148
0
            }
149
150
6
            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
6
            } else {
166
6
                static_assert(IsTimeV2Type<ToDataType>);
167
6
                const auto to_scale = block.get_by_position(result).type->get_scale();
168
6
                const int64_t seconds = source.time_part_to_seconds();
169
6
                uint32_t hour = static_cast<uint32_t>(seconds / 3600);
170
6
                uint32_t minute = static_cast<uint32_t>(seconds / 60 % 60);
171
6
                uint32_t second = static_cast<uint32_t>(seconds % 60);
172
6
                uint32_t nanoseconds = source.nanosecond();
173
6
                const auto divisor = static_cast<uint32_t>(common::exp10_i64(9 - to_scale));
174
6
                const uint32_t remainder = nanoseconds % divisor;
175
6
                nanoseconds = nanoseconds / divisor * divisor;
176
6
                if (remainder >= divisor / 2) {
177
4
                    nanoseconds += divisor;
178
4
                }
179
6
                uint32_t microseconds = nanoseconds / TimeStampNsValue::NANOS_PER_MICROSECOND;
180
6
                if (microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
181
2
                    microseconds = 0;
182
2
                    if (++second == 60) {
183
2
                        second = 0;
184
2
                        if (++minute == 60) {
185
2
                            minute = 0;
186
2
                            ++hour;
187
2
                        }
188
2
                    }
189
2
                }
190
6
                col_to->get_data()[i] =
191
6
                        ((hour * 60 + minute) * 60 + second) * TimeValue::ONE_SECOND_MICROSECONDS +
192
6
                        microseconds;
193
6
            }
194
6
        }
195
196
2
        block.get_by_position(result).column = std::move(col_to);
197
2
        return Status::OK();
198
2
    }
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
18
                        const NullMap::value_type* null_map = nullptr) const override {
208
18
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
209
18
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
210
211
18
        const auto* col_from = assert_cast<const typename FromDataType::ColumnType*>(
212
18
                block.get_by_position(arguments[0]).column.get());
213
18
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
214
18
        ColumnUInt8::MutablePtr col_nullmap;
215
216
18
        if constexpr (Nullable) {
217
0
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
218
0
        }
219
220
68
        for (size_t i = 0; i < input_rows_count; ++i) {
221
50
            if (null_map && null_map[i]) {
222
16
                continue;
223
16
            }
224
34
            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
4
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
243
4
                DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]);
244
4
            } 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
12
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
263
12
                DateV2Value<DateV2ValueType> dtv;
264
12
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
265
12
                                  context->state()->timezone_obj());
266
267
12
                auto time_value = col_from->get_data()[i];
268
12
                int32_t hour = TimeValue::hour(time_value);
269
12
                int32_t minute = TimeValue::minute(time_value);
270
12
                int32_t second = TimeValue::second(time_value);
271
12
                bool neg = TimeValue::sign(time_value) < 0;
272
273
12
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
274
12
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
275
12
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
276
277
12
                col_to->get_data()[i] = dtv;
278
12
            } 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
4
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
289
4
                DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i],
290
4
                                                     col_to->get_data()[i]);
291
4
            } 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
12
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
310
12
                const auto* type = assert_cast<const DataTypeTimeV2*>(
311
12
                        block.get_by_position(arguments[0]).type.get());
312
12
                auto scale = type->get_scale();
313
314
12
                DateV2Value<DateTimeV2ValueType> dtmv2;
315
12
                dtmv2.from_unixtime(context->state()->timestamp_ms() / 1000,
316
12
                                    context->state()->nano_seconds(),
317
12
                                    context->state()->timezone_obj(), scale);
318
12
                dtmv2.reset_time_part();
319
320
12
                auto time_value = col_from->get_data()[i];
321
12
                int32_t hour = TimeValue::hour(time_value);
322
12
                int32_t minute = TimeValue::minute(time_value);
323
12
                int32_t second = TimeValue::second(time_value);
324
12
                int32_t microsecond = TimeValue::microsecond(time_value);
325
12
                bool neg = TimeValue::sign(time_value) < 0;
326
327
12
                dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
328
12
                dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
329
12
                dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
330
12
                dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>(
331
12
                        TimeInterval(MICROSECOND, microsecond, neg));
332
333
12
                col_to->get_data()[i] = dtmv2;
334
12
            } 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
2
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
419
                // from Datetime to Time
420
2
                auto dtmv2 = col_from->get_data()[i];
421
422
2
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(
423
2
                        block.get_by_position(arguments[0]).type.get());
424
2
                auto scale = type->get_scale();
425
2
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(
426
2
                        block.get_by_position(result).type.get());
427
2
                UInt32 to_scale = to_type->get_scale();
428
429
2
                uint32_t hour = dtmv2.hour();
430
2
                uint32_t minute = dtmv2.minute();
431
2
                uint32_t second = dtmv2.second();
432
2
                uint32_t microseconds = dtmv2.microsecond();
433
2
                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
2
                    DCHECK(to_scale <= 6)
437
0
                            << "to_scale should be in range [0, 6], but got " << to_scale;
438
2
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
439
2
                    uint32_t remainder = microseconds % divisor;
440
2
                    microseconds = (microseconds / divisor) * divisor;
441
2
                    if (remainder >= divisor / 2) {
442
                        // do rounding up
443
2
                        microseconds += divisor;
444
2
                    }
445
2
                }
446
447
                // carry on if microseconds >= 1000000
448
2
                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
2
                auto time = TimeValue::limit_with_bound(
462
2
                        TimeValue::make_time(hour, minute, second, microseconds));
463
2
                col_to->get_data()[i] = time;
464
2
            } 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
34
        }
471
472
18
        if constexpr (Nullable) {
473
0
            block.get_by_position(result).column =
474
0
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
475
18
        } else {
476
18
            block.get_by_position(result).column = std::move(col_to);
477
18
        }
478
18
        return Status::OK();
479
18
    }
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
4
                        const NullMap::value_type* null_map = nullptr) const override {
208
4
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
209
4
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
210
211
4
        const auto* col_from = assert_cast<const typename FromDataType::ColumnType*>(
212
4
                block.get_by_position(arguments[0]).column.get());
213
4
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
214
4
        ColumnUInt8::MutablePtr col_nullmap;
215
216
        if constexpr (Nullable) {
217
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
218
        }
219
220
12
        for (size_t i = 0; i < input_rows_count; ++i) {
221
8
            if (null_map && null_map[i]) {
222
4
                continue;
223
4
            }
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
4
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
243
4
                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
4
        }
471
472
        if constexpr (Nullable) {
473
            block.get_by_position(result).column =
474
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
475
4
        } else {
476
4
            block.get_by_position(result).column = std::move(col_to);
477
4
        }
478
4
        return Status::OK();
479
4
    }
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
4
                        const NullMap::value_type* null_map = nullptr) const override {
208
4
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
209
4
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
210
211
4
        const auto* col_from = assert_cast<const typename FromDataType::ColumnType*>(
212
4
                block.get_by_position(arguments[0]).column.get());
213
4
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
214
4
        ColumnUInt8::MutablePtr col_nullmap;
215
216
        if constexpr (Nullable) {
217
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
218
        }
219
220
20
        for (size_t i = 0; i < input_rows_count; ++i) {
221
16
            if (null_map && null_map[i]) {
222
4
                continue;
223
4
            }
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
12
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
263
12
                DateV2Value<DateV2ValueType> dtv;
264
12
                dtv.from_unixtime(context->state()->timestamp_ms() / 1000,
265
12
                                  context->state()->timezone_obj());
266
267
12
                auto time_value = col_from->get_data()[i];
268
12
                int32_t hour = TimeValue::hour(time_value);
269
12
                int32_t minute = TimeValue::minute(time_value);
270
12
                int32_t second = TimeValue::second(time_value);
271
12
                bool neg = TimeValue::sign(time_value) < 0;
272
273
12
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
274
12
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
275
12
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
276
277
12
                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
12
        }
471
472
        if constexpr (Nullable) {
473
            block.get_by_position(result).column =
474
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
475
4
        } else {
476
4
            block.get_by_position(result).column = std::move(col_to);
477
4
        }
478
4
        return Status::OK();
479
4
    }
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
4
                        const NullMap::value_type* null_map = nullptr) const override {
208
4
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
209
4
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
210
211
4
        const auto* col_from = assert_cast<const typename FromDataType::ColumnType*>(
212
4
                block.get_by_position(arguments[0]).column.get());
213
4
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
214
4
        ColumnUInt8::MutablePtr col_nullmap;
215
216
        if constexpr (Nullable) {
217
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
218
        }
219
220
12
        for (size_t i = 0; i < input_rows_count; ++i) {
221
8
            if (null_map && null_map[i]) {
222
4
                continue;
223
4
            }
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
4
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
289
4
                DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i],
290
4
                                                     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
4
        }
471
472
        if constexpr (Nullable) {
473
            block.get_by_position(result).column =
474
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
475
4
        } else {
476
4
            block.get_by_position(result).column = std::move(col_to);
477
4
        }
478
4
        return Status::OK();
479
4
    }
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
4
                        const NullMap::value_type* null_map = nullptr) const override {
208
4
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
209
4
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
210
211
4
        const auto* col_from = assert_cast<const typename FromDataType::ColumnType*>(
212
4
                block.get_by_position(arguments[0]).column.get());
213
4
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
214
4
        ColumnUInt8::MutablePtr col_nullmap;
215
216
        if constexpr (Nullable) {
217
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
218
        }
219
220
20
        for (size_t i = 0; i < input_rows_count; ++i) {
221
16
            if (null_map && null_map[i]) {
222
4
                continue;
223
4
            }
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
12
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
310
12
                const auto* type = assert_cast<const DataTypeTimeV2*>(
311
12
                        block.get_by_position(arguments[0]).type.get());
312
12
                auto scale = type->get_scale();
313
314
12
                DateV2Value<DateTimeV2ValueType> dtmv2;
315
12
                dtmv2.from_unixtime(context->state()->timestamp_ms() / 1000,
316
12
                                    context->state()->nano_seconds(),
317
12
                                    context->state()->timezone_obj(), scale);
318
12
                dtmv2.reset_time_part();
319
320
12
                auto time_value = col_from->get_data()[i];
321
12
                int32_t hour = TimeValue::hour(time_value);
322
12
                int32_t minute = TimeValue::minute(time_value);
323
12
                int32_t second = TimeValue::second(time_value);
324
12
                int32_t microsecond = TimeValue::microsecond(time_value);
325
12
                bool neg = TimeValue::sign(time_value) < 0;
326
327
12
                dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
328
12
                dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
329
12
                dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
330
12
                dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>(
331
12
                        TimeInterval(MICROSECOND, microsecond, neg));
332
333
12
                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
12
        }
471
472
        if constexpr (Nullable) {
473
            block.get_by_position(result).column =
474
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
475
4
        } else {
476
4
            block.get_by_position(result).column = std::move(col_to);
477
4
        }
478
4
        return Status::OK();
479
4
    }
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
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
4
        for (size_t i = 0; i < input_rows_count; ++i) {
221
2
            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
2
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
419
                // from Datetime to Time
420
2
                auto dtmv2 = col_from->get_data()[i];
421
422
2
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(
423
2
                        block.get_by_position(arguments[0]).type.get());
424
2
                auto scale = type->get_scale();
425
2
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(
426
2
                        block.get_by_position(result).type.get());
427
2
                UInt32 to_scale = to_type->get_scale();
428
429
2
                uint32_t hour = dtmv2.hour();
430
2
                uint32_t minute = dtmv2.minute();
431
2
                uint32_t second = dtmv2.second();
432
2
                uint32_t microseconds = dtmv2.microsecond();
433
2
                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
2
                    DCHECK(to_scale <= 6)
437
0
                            << "to_scale should be in range [0, 6], but got " << to_scale;
438
2
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
439
2
                    uint32_t remainder = microseconds % divisor;
440
2
                    microseconds = (microseconds / divisor) * divisor;
441
2
                    if (remainder >= divisor / 2) {
442
                        // do rounding up
443
2
                        microseconds += divisor;
444
2
                    }
445
2
                }
446
447
                // carry on if microseconds >= 1000000
448
2
                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
2
                auto time = TimeValue::limit_with_bound(
462
2
                        TimeValue::make_time(hour, minute, second, microseconds));
463
2
                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_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
14
                        const NullMap::value_type* null_map = nullptr) const override {
489
14
        const auto& col_from =
490
14
                assert_cast<const ColumnTimeStampTz&>(*block.get_by_position(arguments[0]).column)
491
14
                        .get_data();
492
493
14
        auto col_to = ColumnDateTimeV2::create(input_rows_count);
494
14
        auto& col_to_data = col_to->get_data();
495
14
        const auto& local_time_zone = context->state()->timezone_obj();
496
497
14
        const auto tz_scale = block.get_by_position(arguments[0]).type->get_scale();
498
14
        const auto dt_scale = block.get_by_position(result).type->get_scale();
499
500
34
        for (int i = 0; i < input_rows_count; ++i) {
501
28
            if (null_map && null_map[i]) {
502
2
                continue;
503
2
            }
504
26
            TimestampTzValue from_tz {col_from[i]};
505
26
            DateV2Value<DateTimeV2ValueType> dt;
506
26
            if (!from_tz.to_datetime(dt, local_time_zone, dt_scale, tz_scale)) {
507
                // The failed local conversion may also be unformattable. Render the stored
508
                // UTC fields so reporting the cast error cannot throw a second exception.
509
8
                return Status::InvalidArgument(
510
8
                        "can not cast from  timestamptz : {} UTC to datetime in timezone : {}",
511
8
                        from_tz.utc_dt().to_string(tz_scale), context->state()->timezone());
512
8
            }
513
18
            col_to_data[i] = dt.to_date_int_val();
514
18
        }
515
516
6
        block.get_by_position(result).column = std::move(col_to);
517
6
        return Status::OK();
518
14
    }
519
};
520
521
template <>
522
class CastToImpl<CastModeType::NonStrictMode, DataTypeTimeStampTz, DataTypeDateTimeV2>
523
        : public CastToBase {
524
public:
525
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
526
                        uint32_t result, size_t input_rows_count,
527
10
                        const NullMap::value_type*) const override {
528
10
        const auto& col_from =
529
10
                assert_cast<const ColumnTimeStampTz&>(*block.get_by_position(arguments[0]).column)
530
10
                        .get_data();
531
532
10
        auto col_to = ColumnDateTimeV2::create(input_rows_count);
533
10
        auto& col_to_data = col_to->get_data();
534
10
        auto col_null = ColumnBool::create(input_rows_count, 0);
535
10
        auto& col_null_map = col_null->get_data();
536
10
        const auto& local_time_zone = context->state()->timezone_obj();
537
538
10
        const auto tz_scale = block.get_by_position(arguments[0]).type->get_scale();
539
10
        const auto dt_scale = block.get_by_position(result).type->get_scale();
540
541
36
        for (int i = 0; i < input_rows_count; ++i) {
542
26
            TimestampTzValue from_tz {col_from[i]};
543
26
            DateV2Value<DateTimeV2ValueType> dt;
544
26
            if (from_tz.to_datetime(dt, local_time_zone, dt_scale, tz_scale)) {
545
20
                col_to_data[i] = dt;
546
20
            } else {
547
6
                col_null_map[i] = 1;
548
6
                col_to_data[i] = MIN_DATETIME_V2;
549
6
            }
550
26
        }
551
10
        block.get_by_position(result).column =
552
10
                ColumnNullable::create(std::move(col_to), std::move(col_null));
553
10
        return Status::OK();
554
10
    }
555
};
556
557
} // namespace doris