Coverage Report

Created: 2026-08-23 21:30

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