Coverage Report

Created: 2026-10-28 22:39

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(RuntimeState* state, const ColumnWithTypeAndName& source_column,
52
                        ColumnWithTypeAndName& target_column, size_t /*input_rows_count*/,
53
116
                        const NullMap::value_type* parent_null_map = nullptr) const override {
54
116
        const auto* col_from =
55
116
                assert_cast<const DataTypeString::ColumnType*>(source_column.column.get());
56
57
116
        auto to_type = target_column.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 = &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(serde->from_string_strict_mode_batch(*col_from, *column_to, options,
68
108
                                                                 parent_null_map));
69
4
            target_column.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
            target_column.column = std::move(nullable_col_to);
75
8
        }
76
77
0
        return Status::OK();
78
116
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeStringENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
53
1
                        const NullMap::value_type* parent_null_map = nullptr) const override {
54
1
        const auto* col_from =
55
1
                assert_cast<const DataTypeString::ColumnType*>(source_column.column.get());
56
57
1
        auto to_type = target_column.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 = &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(serde->from_string_strict_mode_batch(*col_from, *column_to, options,
68
1
                                                                 parent_null_map));
69
1
            target_column.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
            target_column.column = std::move(nullable_col_to);
75
        }
76
77
0
        return Status::OK();
78
1
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeStringENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeStringENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeStringENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeStringENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
53
48
                        const NullMap::value_type* parent_null_map = nullptr) const override {
54
48
        const auto* col_from =
55
48
                assert_cast<const DataTypeString::ColumnType*>(source_column.column.get());
56
57
48
        auto to_type = target_column.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 = &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(serde->from_string_strict_mode_batch(*col_from, *column_to, options,
68
48
                                                                 parent_null_map));
69
1
            target_column.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
            target_column.column = std::move(nullable_col_to);
75
        }
76
77
0
        return Status::OK();
78
48
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeStringENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
53
4
                        const NullMap::value_type* parent_null_map = nullptr) const override {
54
4
        const auto* col_from =
55
4
                assert_cast<const DataTypeString::ColumnType*>(source_column.column.get());
56
57
4
        auto to_type = target_column.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 = &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(serde->from_string_strict_mode_batch(*col_from, *column_to, options,
68
                                                                 parent_null_map));
69
            target_column.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
            target_column.column = std::move(nullable_col_to);
75
4
        }
76
77
0
        return Status::OK();
78
4
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeStringENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
53
48
                        const NullMap::value_type* parent_null_map = nullptr) const override {
54
48
        const auto* col_from =
55
48
                assert_cast<const DataTypeString::ColumnType*>(source_column.column.get());
56
57
48
        auto to_type = target_column.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 = &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(serde->from_string_strict_mode_batch(*col_from, *column_to, options,
68
48
                                                                 parent_null_map));
69
1
            target_column.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
            target_column.column = std::move(nullable_col_to);
75
        }
76
77
0
        return Status::OK();
78
48
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeStringENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
53
3
                        const NullMap::value_type* parent_null_map = nullptr) const override {
54
3
        const auto* col_from =
55
3
                assert_cast<const DataTypeString::ColumnType*>(source_column.column.get());
56
57
3
        auto to_type = target_column.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 = &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(serde->from_string_strict_mode_batch(*col_from, *column_to, options,
68
                                                                 parent_null_map));
69
            target_column.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
            target_column.column = std::move(nullable_col_to);
75
3
        }
76
77
0
        return Status::OK();
78
3
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeStringENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
53
11
                        const NullMap::value_type* parent_null_map = nullptr) const override {
54
11
        const auto* col_from =
55
11
                assert_cast<const DataTypeString::ColumnType*>(source_column.column.get());
56
57
11
        auto to_type = target_column.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 = &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(serde->from_string_strict_mode_batch(*col_from, *column_to, options,
68
11
                                                                 parent_null_map));
69
1
            target_column.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
            target_column.column = std::move(nullable_col_to);
75
        }
76
77
0
        return Status::OK();
78
11
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeStringENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
53
1
                        const NullMap::value_type* parent_null_map = nullptr) const override {
54
1
        const auto* col_from =
55
1
                assert_cast<const DataTypeString::ColumnType*>(source_column.column.get());
56
57
1
        auto to_type = target_column.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 = &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(serde->from_string_strict_mode_batch(*col_from, *column_to, options,
68
                                                                 parent_null_map));
69
            target_column.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
            target_column.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(RuntimeState* state, const ColumnWithTypeAndName& source_column,
86
                        ColumnWithTypeAndName& target_column, size_t /*input_rows_count*/,
87
40
                        const NullMap::value_type* parent_null_map = nullptr) const override {
88
40
        const auto* col_from =
89
40
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
90
40
        auto to_type = target_column.type;
91
40
        auto nested_to_type = remove_nullable(to_type);
92
40
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
93
40
                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
40
        if constexpr (CastMode == CastModeType::StrictMode) {
98
24
            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
24
            if constexpr (IsDataTypeInt<FromDataType>) {
101
12
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
102
12
                        *col_from, *column_to, parent_null_map));
103
12
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
104
11
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
105
11
                        *col_from, *column_to, parent_null_map));
106
11
            } 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, parent_null_map));
111
1
            }
112
2
            target_column.column = std::move(column_to);
113
24
        } 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
            target_column.column = std::move(nullable_col_to);
128
16
        }
129
130
0
        return Status::OK();
131
40
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Line
Count
Source
87
7
                        const NullMap::value_type* parent_null_map = nullptr) const override {
88
7
        const auto* col_from =
89
7
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
90
7
        auto to_type = target_column.type;
91
7
        auto nested_to_type = remove_nullable(to_type);
92
7
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
93
7
                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
7
        if constexpr (CastMode == CastModeType::StrictMode) {
98
7
            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
7
            if constexpr (IsDataTypeInt<FromDataType>) {
101
7
                RETURN_IF_ERROR(concrete_serde->template from_int_strict_mode_batch<FromDataType>(
102
7
                        *col_from, *column_to, parent_null_map));
103
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
104
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
105
                        *col_from, *column_to, parent_null_map));
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, parent_null_map));
111
            }
112
1
            target_column.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
            target_column.column = std::move(nullable_col_to);
128
        }
129
130
0
        return Status::OK();
131
7
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Line
Count
Source
87
2
                        const NullMap::value_type* parent_null_map = nullptr) const override {
88
2
        const auto* col_from =
89
2
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
90
2
        auto to_type = target_column.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, parent_null_map));
103
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
104
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
105
                        *col_from, *column_to, parent_null_map));
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, parent_null_map));
111
            }
112
            target_column.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
            target_column.column = std::move(nullable_col_to);
128
2
        }
129
130
0
        return Status::OK();
131
2
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Line
Count
Source
87
6
                        const NullMap::value_type* parent_null_map = nullptr) const override {
88
6
        const auto* col_from =
89
6
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
90
6
        auto to_type = target_column.type;
91
6
        auto nested_to_type = remove_nullable(to_type);
92
6
        auto concrete_serde = std::dynamic_pointer_cast<typename ToDataType::SerDeType>(
93
6
                nested_to_type->get_serde());
94
95
        // datelike types serde must have template functions for those types. but because of they need to be
96
        // template functions, so we cannot make them virtual. that's why we assert_cast `serde` before.
97
6
        if constexpr (CastMode == CastModeType::StrictMode) {
98
6
            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, parent_null_map));
103
6
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
104
6
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
105
6
                        *col_from, *column_to, parent_null_map));
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, parent_null_map));
111
            }
112
1
            target_column.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
            target_column.column = std::move(nullable_col_to);
128
        }
129
130
0
        return Status::OK();
131
6
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Line
Count
Source
87
2
                        const NullMap::value_type* parent_null_map = nullptr) const override {
88
2
        const auto* col_from =
89
2
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
90
2
        auto to_type = target_column.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, parent_null_map));
103
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
104
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
105
                        *col_from, *column_to, parent_null_map));
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, parent_null_map));
111
            }
112
            target_column.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
            target_column.column = std::move(nullable_col_to);
128
2
        }
129
130
0
        return Status::OK();
131
2
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Line
Count
Source
87
2
                        const NullMap::value_type* parent_null_map = nullptr) const override {
88
2
        const auto* col_from =
89
2
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
90
2
        auto to_type = target_column.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, parent_null_map));
103
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
104
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
105
                        *col_from, *column_to, parent_null_map));
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, parent_null_map));
111
            }
112
            target_column.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
            target_column.column = std::move(nullable_col_to);
128
2
        }
129
130
0
        return Status::OK();
131
2
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Line
Count
Source
87
5
                        const NullMap::value_type* parent_null_map = nullptr) const override {
88
5
        const auto* col_from =
89
5
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
90
5
        auto to_type = target_column.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, parent_null_map));
103
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
104
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
105
                        *col_from, *column_to, parent_null_map));
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, parent_null_map));
111
            }
112
0
            target_column.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
            target_column.column = std::move(nullable_col_to);
128
        }
129
130
0
        return Status::OK();
131
5
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Line
Count
Source
87
2
                        const NullMap::value_type* parent_null_map = nullptr) const override {
88
2
        const auto* col_from =
89
2
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
90
2
        auto to_type = target_column.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, parent_null_map));
103
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
104
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
105
                        *col_from, *column_to, parent_null_map));
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, parent_null_map));
111
            }
112
            target_column.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
            target_column.column = std::move(nullable_col_to);
128
2
        }
129
130
0
        return Status::OK();
131
2
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Line
Count
Source
87
5
                        const NullMap::value_type* parent_null_map = nullptr) const override {
88
5
        const auto* col_from =
89
5
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
90
5
        auto to_type = target_column.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, parent_null_map));
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, parent_null_map));
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, parent_null_map));
111
            }
112
0
            target_column.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
            target_column.column = std::move(nullable_col_to);
128
        }
129
130
0
        return Status::OK();
131
5
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Line
Count
Source
87
2
                        const NullMap::value_type* parent_null_map = nullptr) const override {
88
2
        const auto* col_from =
89
2
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
90
2
        auto to_type = target_column.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, parent_null_map));
103
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
104
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
105
                        *col_from, *column_to, parent_null_map));
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, parent_null_map));
111
            }
112
            target_column.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
            target_column.column = std::move(nullable_col_to);
128
2
        }
129
130
0
        return Status::OK();
131
2
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Line
Count
Source
87
1
                        const NullMap::value_type* parent_null_map = nullptr) const override {
88
1
        const auto* col_from =
89
1
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
90
1
        auto to_type = target_column.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, parent_null_map));
103
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
104
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
105
                        *col_from, *column_to, parent_null_map));
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, parent_null_map));
111
1
            }
112
0
            target_column.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
            target_column.column = std::move(nullable_col_to);
128
        }
129
130
0
        return Status::OK();
131
1
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Line
Count
Source
87
3
                        const NullMap::value_type* parent_null_map = nullptr) const override {
88
3
        const auto* col_from =
89
3
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
90
3
        auto to_type = target_column.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, parent_null_map));
103
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
104
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
105
                        *col_from, *column_to, parent_null_map));
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, parent_null_map));
111
            }
112
            target_column.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
            target_column.column = std::move(nullable_col_to);
128
3
        }
129
130
0
        return Status::OK();
131
3
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE3EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE4EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE5EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE6EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Line
Count
Source
87
1
                        const NullMap::value_type* parent_null_map = nullptr) const override {
88
1
        const auto* col_from =
89
1
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
90
1
        auto to_type = target_column.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, parent_null_map));
103
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
104
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
105
                        *col_from, *column_to, parent_null_map));
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, parent_null_map));
111
            }
112
            target_column.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
            target_column.column = std::move(nullable_col_to);
128
1
        }
129
130
0
        return Status::OK();
131
1
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE7EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE8EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeNumberILNS_13PrimitiveTypeE9EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Line
Count
Source
87
1
                        const NullMap::value_type* parent_null_map = nullptr) const override {
88
1
        const auto* col_from =
89
1
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
90
1
        auto to_type = target_column.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, parent_null_map));
103
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
104
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
105
                        *col_from, *column_to, parent_null_map));
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, parent_null_map));
111
            }
112
            target_column.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
            target_column.column = std::move(nullable_col_to);
128
1
        }
129
130
0
        return Status::OK();
131
1
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE28EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE29EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Line
Count
Source
87
1
                        const NullMap::value_type* parent_null_map = nullptr) const override {
88
1
        const auto* col_from =
89
1
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
90
1
        auto to_type = target_column.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, parent_null_map));
103
            } else if constexpr (IsDataTypeFloat<FromDataType>) {
104
                RETURN_IF_ERROR(concrete_serde->template from_float_strict_mode_batch<FromDataType>(
105
                        *col_from, *column_to, parent_null_map));
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, parent_null_map));
111
            }
112
            target_column.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
            target_column.column = std::move(nullable_col_to);
128
1
        }
129
130
0
        return Status::OK();
131
1
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE20EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE30EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_15DataTypeDecimalILNS_13PrimitiveTypeE35EEENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS9_mPKh
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(RuntimeState* state, const ColumnWithTypeAndName& source_column,
139
                        ColumnWithTypeAndName& target_column, size_t input_rows_count,
140
6
                        const NullMap::value_type* parent_null_map = nullptr) const override {
141
6
        const auto& col_from = assert_cast<const ColumnTimeStampNs&>(*source_column.column);
142
6
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
143
144
26
        for (size_t i = 0; i < input_rows_count; ++i) {
145
20
            if (parent_null_map && parent_null_map[i]) {
146
0
                continue;
147
0
            }
148
149
20
            const auto& source = col_from.get_data()[i];
150
20
            if constexpr (IsDateType<ToDataType>) {
151
3
                const auto civil = source.to_datetime();
152
3
                DataTypeDateTimeV2::cast_to_date(civil, col_to->get_data()[i]);
153
3
            } else if constexpr (IsDateV2Type<ToDataType>) {
154
3
                col_to->get_data()[i] = source.to_date();
155
3
            } else if constexpr (IsDateTimeType<ToDataType>) {
156
3
                const auto civil = source.to_datetime();
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 = target_column.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 = target_column.type->get_scale();
167
3
                const int64_t seconds = source.time_part_to_seconds();
168
3
                uint32_t hour = static_cast<uint32_t>(seconds / 3600);
169
3
                uint32_t minute = static_cast<uint32_t>(seconds / 60 % 60);
170
3
                uint32_t second = static_cast<uint32_t>(seconds % 60);
171
3
                uint32_t nanoseconds = source.nanosecond();
172
3
                const auto divisor = static_cast<uint32_t>(common::exp10_i64(9 - to_scale));
173
3
                const uint32_t remainder = nanoseconds % divisor;
174
3
                nanoseconds = nanoseconds / divisor * divisor;
175
3
                if (remainder >= divisor / 2) {
176
2
                    nanoseconds += divisor;
177
2
                }
178
3
                uint32_t microseconds = nanoseconds / TimeStampNsValue::NANOS_PER_MICROSECOND;
179
3
                if (microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
180
1
                    microseconds = 0;
181
1
                    if (++second == 60) {
182
1
                        second = 0;
183
1
                        if (++minute == 60) {
184
1
                            minute = 0;
185
1
                            ++hour;
186
1
                        }
187
1
                    }
188
1
                }
189
3
                col_to->get_data()[i] =
190
3
                        ((hour * 60 + minute) * 60 + second) * TimeValue::ONE_SECOND_MICROSECONDS +
191
3
                        microseconds;
192
3
            }
193
20
        }
194
195
6
        target_column.column = std::move(col_to);
196
6
        return Status::OK();
197
6
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_19DataTypeTimeStampNsENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_19DataTypeTimeStampNsENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
140
1
                        const NullMap::value_type* parent_null_map = nullptr) const override {
141
1
        const auto& col_from = assert_cast<const ColumnTimeStampNs&>(*source_column.column);
142
1
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
143
144
4
        for (size_t i = 0; i < input_rows_count; ++i) {
145
3
            if (parent_null_map && parent_null_map[i]) {
146
0
                continue;
147
0
            }
148
149
3
            const auto& source = col_from.get_data()[i];
150
3
            if constexpr (IsDateType<ToDataType>) {
151
3
                const auto civil = source.to_datetime();
152
3
                DataTypeDateTimeV2::cast_to_date(civil, col_to->get_data()[i]);
153
            } else if constexpr (IsDateV2Type<ToDataType>) {
154
                col_to->get_data()[i] = source.to_date();
155
            } else if constexpr (IsDateTimeType<ToDataType>) {
156
                const auto civil = source.to_datetime();
157
                DataTypeDateTimeV2::cast_to_date_time(civil, col_to->get_data()[i]);
158
            } else if constexpr (IsDateTimeV2Type<ToDataType>) {
159
                const auto to_scale = target_column.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 = target_column.type->get_scale();
167
                const int64_t seconds = source.time_part_to_seconds();
168
                uint32_t hour = static_cast<uint32_t>(seconds / 3600);
169
                uint32_t minute = static_cast<uint32_t>(seconds / 60 % 60);
170
                uint32_t second = static_cast<uint32_t>(seconds % 60);
171
                uint32_t nanoseconds = source.nanosecond();
172
                const auto divisor = static_cast<uint32_t>(common::exp10_i64(9 - to_scale));
173
                const uint32_t remainder = nanoseconds % divisor;
174
                nanoseconds = nanoseconds / divisor * divisor;
175
                if (remainder >= divisor / 2) {
176
                    nanoseconds += divisor;
177
                }
178
                uint32_t microseconds = nanoseconds / TimeStampNsValue::NANOS_PER_MICROSECOND;
179
                if (microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
180
                    microseconds = 0;
181
                    if (++second == 60) {
182
                        second = 0;
183
                        if (++minute == 60) {
184
                            minute = 0;
185
                            ++hour;
186
                        }
187
                    }
188
                }
189
                col_to->get_data()[i] =
190
                        ((hour * 60 + minute) * 60 + second) * TimeValue::ONE_SECOND_MICROSECONDS +
191
                        microseconds;
192
            }
193
3
        }
194
195
1
        target_column.column = std::move(col_to);
196
1
        return Status::OK();
197
1
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_19DataTypeTimeStampNsENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_19DataTypeTimeStampNsENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
140
1
                        const NullMap::value_type* parent_null_map = nullptr) const override {
141
1
        const auto& col_from = assert_cast<const ColumnTimeStampNs&>(*source_column.column);
142
1
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
143
144
4
        for (size_t i = 0; i < input_rows_count; ++i) {
145
3
            if (parent_null_map && parent_null_map[i]) {
146
0
                continue;
147
0
            }
148
149
3
            const auto& source = col_from.get_data()[i];
150
            if constexpr (IsDateType<ToDataType>) {
151
                const auto civil = source.to_datetime();
152
                DataTypeDateTimeV2::cast_to_date(civil, col_to->get_data()[i]);
153
            } else if constexpr (IsDateV2Type<ToDataType>) {
154
                col_to->get_data()[i] = source.to_date();
155
3
            } else if constexpr (IsDateTimeType<ToDataType>) {
156
3
                const auto civil = source.to_datetime();
157
3
                DataTypeDateTimeV2::cast_to_date_time(civil, col_to->get_data()[i]);
158
            } else if constexpr (IsDateTimeV2Type<ToDataType>) {
159
                const auto to_scale = target_column.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 = target_column.type->get_scale();
167
                const int64_t seconds = source.time_part_to_seconds();
168
                uint32_t hour = static_cast<uint32_t>(seconds / 3600);
169
                uint32_t minute = static_cast<uint32_t>(seconds / 60 % 60);
170
                uint32_t second = static_cast<uint32_t>(seconds % 60);
171
                uint32_t nanoseconds = source.nanosecond();
172
                const auto divisor = static_cast<uint32_t>(common::exp10_i64(9 - to_scale));
173
                const uint32_t remainder = nanoseconds % divisor;
174
                nanoseconds = nanoseconds / divisor * divisor;
175
                if (remainder >= divisor / 2) {
176
                    nanoseconds += divisor;
177
                }
178
                uint32_t microseconds = nanoseconds / TimeStampNsValue::NANOS_PER_MICROSECOND;
179
                if (microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
180
                    microseconds = 0;
181
                    if (++second == 60) {
182
                        second = 0;
183
                        if (++minute == 60) {
184
                            minute = 0;
185
                            ++hour;
186
                        }
187
                    }
188
                }
189
                col_to->get_data()[i] =
190
                        ((hour * 60 + minute) * 60 + second) * TimeValue::ONE_SECOND_MICROSECONDS +
191
                        microseconds;
192
            }
193
3
        }
194
195
1
        target_column.column = std::move(col_to);
196
1
        return Status::OK();
197
1
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_19DataTypeTimeStampNsENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_19DataTypeTimeStampNsENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
140
1
                        const NullMap::value_type* parent_null_map = nullptr) const override {
141
1
        const auto& col_from = assert_cast<const ColumnTimeStampNs&>(*source_column.column);
142
1
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
143
144
4
        for (size_t i = 0; i < input_rows_count; ++i) {
145
3
            if (parent_null_map && parent_null_map[i]) {
146
0
                continue;
147
0
            }
148
149
3
            const auto& source = col_from.get_data()[i];
150
            if constexpr (IsDateType<ToDataType>) {
151
                const auto civil = source.to_datetime();
152
                DataTypeDateTimeV2::cast_to_date(civil, col_to->get_data()[i]);
153
3
            } else if constexpr (IsDateV2Type<ToDataType>) {
154
3
                col_to->get_data()[i] = source.to_date();
155
            } else if constexpr (IsDateTimeType<ToDataType>) {
156
                const auto civil = source.to_datetime();
157
                DataTypeDateTimeV2::cast_to_date_time(civil, col_to->get_data()[i]);
158
            } else if constexpr (IsDateTimeV2Type<ToDataType>) {
159
                const auto to_scale = target_column.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 = target_column.type->get_scale();
167
                const int64_t seconds = source.time_part_to_seconds();
168
                uint32_t hour = static_cast<uint32_t>(seconds / 3600);
169
                uint32_t minute = static_cast<uint32_t>(seconds / 60 % 60);
170
                uint32_t second = static_cast<uint32_t>(seconds % 60);
171
                uint32_t nanoseconds = source.nanosecond();
172
                const auto divisor = static_cast<uint32_t>(common::exp10_i64(9 - to_scale));
173
                const uint32_t remainder = nanoseconds % divisor;
174
                nanoseconds = nanoseconds / divisor * divisor;
175
                if (remainder >= divisor / 2) {
176
                    nanoseconds += divisor;
177
                }
178
                uint32_t microseconds = nanoseconds / TimeStampNsValue::NANOS_PER_MICROSECOND;
179
                if (microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
180
                    microseconds = 0;
181
                    if (++second == 60) {
182
                        second = 0;
183
                        if (++minute == 60) {
184
                            minute = 0;
185
                            ++hour;
186
                        }
187
                    }
188
                }
189
                col_to->get_data()[i] =
190
                        ((hour * 60 + minute) * 60 + second) * TimeValue::ONE_SECOND_MICROSECONDS +
191
                        microseconds;
192
            }
193
3
        }
194
195
1
        target_column.column = std::move(col_to);
196
1
        return Status::OK();
197
1
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_19DataTypeTimeStampNsENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
140
1
                        const NullMap::value_type* parent_null_map = nullptr) const override {
141
1
        const auto& col_from = assert_cast<const ColumnTimeStampNs&>(*source_column.column);
142
1
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
143
144
5
        for (size_t i = 0; i < input_rows_count; ++i) {
145
4
            if (parent_null_map && parent_null_map[i]) {
146
0
                continue;
147
0
            }
148
149
4
            const auto& source = col_from.get_data()[i];
150
            if constexpr (IsDateType<ToDataType>) {
151
                const auto civil = source.to_datetime();
152
                DataTypeDateTimeV2::cast_to_date(civil, col_to->get_data()[i]);
153
            } else if constexpr (IsDateV2Type<ToDataType>) {
154
                col_to->get_data()[i] = source.to_date();
155
            } else if constexpr (IsDateTimeType<ToDataType>) {
156
                const auto civil = source.to_datetime();
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 = target_column.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 = target_column.type->get_scale();
167
                const int64_t seconds = source.time_part_to_seconds();
168
                uint32_t hour = static_cast<uint32_t>(seconds / 3600);
169
                uint32_t minute = static_cast<uint32_t>(seconds / 60 % 60);
170
                uint32_t second = static_cast<uint32_t>(seconds % 60);
171
                uint32_t nanoseconds = source.nanosecond();
172
                const auto divisor = static_cast<uint32_t>(common::exp10_i64(9 - to_scale));
173
                const uint32_t remainder = nanoseconds % divisor;
174
                nanoseconds = nanoseconds / divisor * divisor;
175
                if (remainder >= divisor / 2) {
176
                    nanoseconds += divisor;
177
                }
178
                uint32_t microseconds = nanoseconds / TimeStampNsValue::NANOS_PER_MICROSECOND;
179
                if (microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
180
                    microseconds = 0;
181
                    if (++second == 60) {
182
                        second = 0;
183
                        if (++minute == 60) {
184
                            minute = 0;
185
                            ++hour;
186
                        }
187
                    }
188
                }
189
                col_to->get_data()[i] =
190
                        ((hour * 60 + minute) * 60 + second) * TimeValue::ONE_SECOND_MICROSECONDS +
191
                        microseconds;
192
            }
193
4
        }
194
195
1
        target_column.column = std::move(col_to);
196
1
        return Status::OK();
197
1
    }
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_19DataTypeTimeStampNsENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
140
1
                        const NullMap::value_type* parent_null_map = nullptr) const override {
141
1
        const auto& col_from = assert_cast<const ColumnTimeStampNs&>(*source_column.column);
142
1
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
143
144
5
        for (size_t i = 0; i < input_rows_count; ++i) {
145
4
            if (parent_null_map && parent_null_map[i]) {
146
0
                continue;
147
0
            }
148
149
4
            const auto& source = col_from.get_data()[i];
150
            if constexpr (IsDateType<ToDataType>) {
151
                const auto civil = source.to_datetime();
152
                DataTypeDateTimeV2::cast_to_date(civil, col_to->get_data()[i]);
153
            } else if constexpr (IsDateV2Type<ToDataType>) {
154
                col_to->get_data()[i] = source.to_date();
155
            } else if constexpr (IsDateTimeType<ToDataType>) {
156
                const auto civil = source.to_datetime();
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 = target_column.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 = target_column.type->get_scale();
167
                const int64_t seconds = source.time_part_to_seconds();
168
                uint32_t hour = static_cast<uint32_t>(seconds / 3600);
169
                uint32_t minute = static_cast<uint32_t>(seconds / 60 % 60);
170
                uint32_t second = static_cast<uint32_t>(seconds % 60);
171
                uint32_t nanoseconds = source.nanosecond();
172
                const auto divisor = static_cast<uint32_t>(common::exp10_i64(9 - to_scale));
173
                const uint32_t remainder = nanoseconds % divisor;
174
                nanoseconds = nanoseconds / divisor * divisor;
175
                if (remainder >= divisor / 2) {
176
                    nanoseconds += divisor;
177
                }
178
                uint32_t microseconds = nanoseconds / TimeStampNsValue::NANOS_PER_MICROSECOND;
179
                if (microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
180
                    microseconds = 0;
181
                    if (++second == 60) {
182
                        second = 0;
183
                        if (++minute == 60) {
184
                            minute = 0;
185
                            ++hour;
186
                        }
187
                    }
188
                }
189
                col_to->get_data()[i] =
190
                        ((hour * 60 + minute) * 60 + second) * TimeValue::ONE_SECOND_MICROSECONDS +
191
                        microseconds;
192
            }
193
4
        }
194
195
1
        target_column.column = std::move(col_to);
196
1
        return Status::OK();
197
1
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_19DataTypeTimeStampNsENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_19DataTypeTimeStampNsENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
140
1
                        const NullMap::value_type* parent_null_map = nullptr) const override {
141
1
        const auto& col_from = assert_cast<const ColumnTimeStampNs&>(*source_column.column);
142
1
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
143
144
4
        for (size_t i = 0; i < input_rows_count; ++i) {
145
3
            if (parent_null_map && parent_null_map[i]) {
146
0
                continue;
147
0
            }
148
149
3
            const auto& source = col_from.get_data()[i];
150
            if constexpr (IsDateType<ToDataType>) {
151
                const auto civil = source.to_datetime();
152
                DataTypeDateTimeV2::cast_to_date(civil, col_to->get_data()[i]);
153
            } else if constexpr (IsDateV2Type<ToDataType>) {
154
                col_to->get_data()[i] = source.to_date();
155
            } else if constexpr (IsDateTimeType<ToDataType>) {
156
                const auto civil = source.to_datetime();
157
                DataTypeDateTimeV2::cast_to_date_time(civil, col_to->get_data()[i]);
158
            } else if constexpr (IsDateTimeV2Type<ToDataType>) {
159
                const auto to_scale = target_column.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 = target_column.type->get_scale();
167
3
                const int64_t seconds = source.time_part_to_seconds();
168
3
                uint32_t hour = static_cast<uint32_t>(seconds / 3600);
169
3
                uint32_t minute = static_cast<uint32_t>(seconds / 60 % 60);
170
3
                uint32_t second = static_cast<uint32_t>(seconds % 60);
171
3
                uint32_t nanoseconds = source.nanosecond();
172
3
                const auto divisor = static_cast<uint32_t>(common::exp10_i64(9 - to_scale));
173
3
                const uint32_t remainder = nanoseconds % divisor;
174
3
                nanoseconds = nanoseconds / divisor * divisor;
175
3
                if (remainder >= divisor / 2) {
176
2
                    nanoseconds += divisor;
177
2
                }
178
3
                uint32_t microseconds = nanoseconds / TimeStampNsValue::NANOS_PER_MICROSECOND;
179
3
                if (microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
180
1
                    microseconds = 0;
181
1
                    if (++second == 60) {
182
1
                        second = 0;
183
1
                        if (++minute == 60) {
184
1
                            minute = 0;
185
1
                            ++hour;
186
1
                        }
187
1
                    }
188
1
                }
189
3
                col_to->get_data()[i] =
190
3
                        ((hour * 60 + minute) * 60 + second) * TimeValue::ONE_SECOND_MICROSECONDS +
191
3
                        microseconds;
192
3
            }
193
3
        }
194
195
1
        target_column.column = std::move(col_to);
196
1
        return Status::OK();
197
1
    }
198
};
199
200
template <CastModeType CastMode, typename FromDataType, typename ToDataType>
201
    requires(IsDatelikeTypes<FromDataType> && IsDatelikeTypes<ToDataType>)
202
class CastToImpl<CastMode, FromDataType, ToDataType> : public CastToBase {
203
public:
204
    Status execute_impl(RuntimeState* state, const ColumnWithTypeAndName& source_column,
205
                        ColumnWithTypeAndName& target_column, size_t input_rows_count,
206
10
                        const NullMap::value_type* parent_null_map = nullptr) const override {
207
10
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
208
10
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
209
210
10
        const auto* col_from =
211
10
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
212
10
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
213
10
        ColumnUInt8::MutablePtr col_nullmap;
214
215
10
        if constexpr (Nullable) {
216
1
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
217
1
        }
218
219
36
        for (size_t i = 0; i < input_rows_count; ++i) {
220
26
            if (parent_null_map && parent_null_map[i]) {
221
8
                continue;
222
8
            }
223
18
            if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) {
224
                // from Date to Date
225
0
                auto dtv1 = col_from->get_data()[i];
226
0
                dtv1.cast_to_date();
227
0
                col_to->get_data()[i] =
228
0
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2());
229
0
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) {
230
0
                DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
231
0
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) {
232
                // from Datetime to Date
233
0
                col_to->get_data()[i] = col_from->get_data()[i];
234
0
                DataTypeDate::cast_to_date(col_to->get_data()[i]);
235
0
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
236
0
                DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
237
0
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) {
238
0
                auto dtmv1 = col_from->get_data()[i];
239
0
                col_to->get_data()[i] =
240
0
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2());
241
2
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
242
2
                DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]);
243
2
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
244
                // from Time to Date
245
0
                VecDateTimeValue dtv;
246
0
                dtv.cast_to_date();
247
0
                dtv.from_unixtime(state->timestamp_ms() / 1000, 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(state->timestamp_ms() / 1000, state->timezone_obj());
263
264
6
                auto time_value = col_from->get_data()[i];
265
6
                int32_t hour = TimeValue::hour(time_value);
266
6
                int32_t minute = TimeValue::minute(time_value);
267
6
                int32_t second = TimeValue::second(time_value);
268
6
                bool neg = TimeValue::sign(time_value) < 0;
269
270
6
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
271
6
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
272
6
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
273
274
6
                col_to->get_data()[i] = dtv;
275
6
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) {
276
                // from Date to Datetime
277
0
                col_to->get_data()[i] = col_from->get_data()[i];
278
0
                DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]);
279
0
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
280
0
                DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]);
281
0
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
282
0
                auto dtv1 = col_from->get_data()[i];
283
0
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
284
0
                        dtv1.to_datetime_v2());
285
2
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
286
2
                DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i],
287
2
                                                     col_to->get_data()[i]);
288
2
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
289
                // from Time to Datetime
290
0
                VecDateTimeValue dtv; // datetime by default
291
0
                dtv.from_unixtime(state->timestamp_ms() / 1000, state->timezone_obj());
292
0
                dtv.reset_time_part();
293
294
0
                auto time_value = col_from->get_data()[i];
295
0
                int32_t hour = TimeValue::hour(time_value);
296
0
                int32_t minute = TimeValue::minute(time_value);
297
0
                int32_t second = TimeValue::second(time_value);
298
0
                bool neg = TimeValue::sign(time_value) < 0;
299
300
0
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
301
0
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
302
0
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
303
304
0
                col_to->get_data()[i] = dtv;
305
6
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
306
6
                const auto* type = assert_cast<const DataTypeTimeV2*>(source_column.type.get());
307
6
                auto scale = type->get_scale();
308
309
6
                DateV2Value<DateTimeV2ValueType> dtmv2;
310
6
                dtmv2.from_unixtime(state->timestamp_ms() / 1000, state->nano_seconds(),
311
6
                                    state->timezone_obj(), scale);
312
6
                dtmv2.reset_time_part();
313
314
6
                auto time_value = col_from->get_data()[i];
315
6
                int32_t hour = TimeValue::hour(time_value);
316
6
                int32_t minute = TimeValue::minute(time_value);
317
6
                int32_t second = TimeValue::second(time_value);
318
6
                int32_t microsecond = TimeValue::microsecond(time_value);
319
6
                bool neg = TimeValue::sign(time_value) < 0;
320
321
6
                dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
322
6
                dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
323
6
                dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
324
6
                dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>(
325
6
                        TimeInterval(MICROSECOND, microsecond, neg));
326
327
6
                col_to->get_data()[i] = dtmv2;
328
6
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
329
                // from Datetime to Datetime
330
0
                auto dtmv1 = col_from->get_data()[i];
331
0
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
332
0
                        dtmv1.to_datetime_v2());
333
0
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
334
0
                DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i],
335
0
                                                      col_to->get_data()[i]);
336
1
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
337
1
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(source_column.type.get());
338
1
                auto scale = type->get_scale();
339
340
1
                const auto* to_type =
341
1
                        assert_cast<const DataTypeDateTimeV2*>(target_column.type.get());
342
1
                UInt32 to_scale = to_type->get_scale();
343
344
1
                bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i],
345
1
                                                    col_from->get_data()[i]);
346
1
                if (!success) {
347
0
                    if constexpr (CastMode == CastModeType::StrictMode) {
348
0
                        auto format_options = DataTypeSerDe::get_default_format_options();
349
0
                        auto time_zone = cctz::utc_time_zone();
350
0
                        format_options.timezone =
351
0
                                state != nullptr ? &state->timezone_obj() : &time_zone;
352
0
                        return Status::InvalidArgument(
353
0
                                "DatetimeV2 overflow when casting {} from {} to {}",
354
0
                                type->to_string(*col_from, i, format_options), type->get_name(),
355
0
                                to_type->get_name());
356
0
                    } else {
357
0
                        col_nullmap->get_data()[i] = true;
358
                        //TODO: maybe we can remove all set operations on nested of null cell.
359
                        // the correctness should be keep by downstream user with replace_... or manually
360
                        // process null data if need.
361
0
                        col_to->get_data()[i] =
362
0
                                binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
363
0
                                        MIN_DATETIME_V2);
364
0
                    }
365
0
                }
366
367
1
            } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
368
0
                const auto* type = assert_cast<const DataTypeTimeV2*>(source_column.type.get());
369
0
                auto scale = type->get_scale();
370
371
0
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(target_column.type.get());
372
0
                UInt32 to_scale = to_type->get_scale();
373
374
0
                if (to_scale >= scale) {
375
                    // nothing to do, just copy
376
0
                    col_to->get_data()[i] = col_from->get_data()[i];
377
0
                } else {
378
0
                    double time = col_from->get_data()[i];
379
0
                    auto sign = TimeValue::sign(time);
380
0
                    time = std::abs(time);
381
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
382
                    // 999956: 56 > 100/2, then round up to 1000000
383
0
                    uint32_t microseconds = TimeValue::microsecond(time);
384
0
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
385
0
                    uint32_t remainder = microseconds % divisor;
386
387
0
                    if (remainder >= divisor / 2) { // need to round up
388
                        // do rounding up
389
0
                        uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor;
390
                        // need carry on
391
0
                        if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
392
0
                            DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS);
393
0
                            time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) *
394
0
                                   TimeValue::ONE_SECOND_MICROSECONDS;
395
396
                            // the input data must be valid, so max to '838:59:59.0'. this value won't carry on
397
                            // to second.
398
0
                            DCHECK(TimeValue::valid(time)) << col_from->get_data()[i];
399
0
                        } else {
400
0
                            time = TimeValue::reset_microsecond(time, rounded_microseconds);
401
0
                        }
402
0
                    } else {
403
                        // truncate
404
0
                        time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor);
405
0
                    }
406
0
                    col_to->get_data()[i] = sign * time;
407
0
                }
408
1
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
409
                // from Datetime to Time
410
1
                auto dtmv2 = col_from->get_data()[i];
411
412
1
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(source_column.type.get());
413
1
                auto scale = type->get_scale();
414
1
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(target_column.type.get());
415
1
                UInt32 to_scale = to_type->get_scale();
416
417
1
                uint32_t hour = dtmv2.hour();
418
1
                uint32_t minute = dtmv2.minute();
419
1
                uint32_t second = dtmv2.second();
420
1
                uint32_t microseconds = dtmv2.microsecond();
421
1
                if (to_scale < scale) { // need to round
422
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
423
                    // 999956: 56 > 100/2, then round up to 1000000
424
1
                    DCHECK(to_scale <= 6)
425
0
                            << "to_scale should be in range [0, 6], but got " << to_scale;
426
1
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
427
1
                    uint32_t remainder = microseconds % divisor;
428
1
                    microseconds = (microseconds / divisor) * divisor;
429
1
                    if (remainder >= divisor / 2) {
430
                        // do rounding up
431
1
                        microseconds += divisor;
432
1
                    }
433
1
                }
434
435
                // carry on if microseconds >= 1000000
436
1
                if (microseconds >= 1000000) {
437
0
                    microseconds -= 1000000;
438
0
                    second += 1;
439
0
                    if (second >= 60) {
440
0
                        second -= 60;
441
0
                        minute += 1;
442
0
                        if (minute >= 60) {
443
0
                            minute -= 60;
444
0
                            hour += 1;
445
0
                        }
446
0
                    }
447
0
                }
448
449
1
                auto time = TimeValue::limit_with_bound(
450
1
                        TimeValue::make_time(hour, minute, second, microseconds));
451
1
                col_to->get_data()[i] = time;
452
1
            } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) {
453
0
                auto dtmv1 = col_from->get_data()[i];
454
0
                auto time = TimeValue::limit_with_bound(
455
0
                        TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second()));
456
0
                col_to->get_data()[i] = time;
457
0
            }
458
18
        }
459
460
10
        if constexpr (Nullable) {
461
1
            target_column.column =
462
1
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
463
9
        } else {
464
9
            target_column.column = std::move(col_to);
465
9
        }
466
10
        return Status::OK();
467
10
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_12DataTypeDateES2_E12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS6_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_12DataTypeDateES2_E12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS6_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeDateV2ENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeDateV2ENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_18DataTypeDateTimeV2ENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_18DataTypeDateTimeV2ENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_16DataTypeDateTimeENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_16DataTypeDateTimeENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeTimeV2ENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeTimeV2ENS_12DataTypeDateEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_12DataTypeDateENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_12DataTypeDateENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeDateV2ENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeDateV2ENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_18DataTypeDateTimeV2ENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_18DataTypeDateTimeV2ENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_16DataTypeDateTimeES2_E12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS6_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_16DataTypeDateTimeES2_E12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS6_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeTimeV2ENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeTimeV2ENS_16DataTypeDateTimeEE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_12DataTypeDateENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_12DataTypeDateENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeDateV2ES2_E12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS6_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeDateV2ES2_E12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS6_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_18DataTypeDateTimeV2ENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_18DataTypeDateTimeV2ENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
206
2
                        const NullMap::value_type* parent_null_map = nullptr) const override {
207
2
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
208
2
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
209
210
2
        const auto* col_from =
211
2
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
212
2
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
213
2
        ColumnUInt8::MutablePtr col_nullmap;
214
215
        if constexpr (Nullable) {
216
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
217
        }
218
219
6
        for (size_t i = 0; i < input_rows_count; ++i) {
220
4
            if (parent_null_map && parent_null_map[i]) {
221
2
                continue;
222
2
            }
223
            if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) {
224
                // from Date to Date
225
                auto dtv1 = col_from->get_data()[i];
226
                dtv1.cast_to_date();
227
                col_to->get_data()[i] =
228
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2());
229
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) {
230
                DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
231
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) {
232
                // from Datetime to Date
233
                col_to->get_data()[i] = col_from->get_data()[i];
234
                DataTypeDate::cast_to_date(col_to->get_data()[i]);
235
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
236
                DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
237
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) {
238
                auto dtmv1 = col_from->get_data()[i];
239
                col_to->get_data()[i] =
240
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2());
241
2
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
242
2
                DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]);
243
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
244
                // from Time to Date
245
                VecDateTimeValue dtv;
246
                dtv.cast_to_date();
247
                dtv.from_unixtime(state->timestamp_ms() / 1000, 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(state->timestamp_ms() / 1000, state->timezone_obj());
263
264
                auto time_value = col_from->get_data()[i];
265
                int32_t hour = TimeValue::hour(time_value);
266
                int32_t minute = TimeValue::minute(time_value);
267
                int32_t second = TimeValue::second(time_value);
268
                bool neg = TimeValue::sign(time_value) < 0;
269
270
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
271
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
272
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
273
274
                col_to->get_data()[i] = dtv;
275
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) {
276
                // from Date to Datetime
277
                col_to->get_data()[i] = col_from->get_data()[i];
278
                DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]);
279
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
280
                DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]);
281
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
282
                auto dtv1 = col_from->get_data()[i];
283
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
284
                        dtv1.to_datetime_v2());
285
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
286
                DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i],
287
                                                     col_to->get_data()[i]);
288
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
289
                // from Time to Datetime
290
                VecDateTimeValue dtv; // datetime by default
291
                dtv.from_unixtime(state->timestamp_ms() / 1000, state->timezone_obj());
292
                dtv.reset_time_part();
293
294
                auto time_value = col_from->get_data()[i];
295
                int32_t hour = TimeValue::hour(time_value);
296
                int32_t minute = TimeValue::minute(time_value);
297
                int32_t second = TimeValue::second(time_value);
298
                bool neg = TimeValue::sign(time_value) < 0;
299
300
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
301
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
302
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
303
304
                col_to->get_data()[i] = dtv;
305
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
306
                const auto* type = assert_cast<const DataTypeTimeV2*>(source_column.type.get());
307
                auto scale = type->get_scale();
308
309
                DateV2Value<DateTimeV2ValueType> dtmv2;
310
                dtmv2.from_unixtime(state->timestamp_ms() / 1000, state->nano_seconds(),
311
                                    state->timezone_obj(), scale);
312
                dtmv2.reset_time_part();
313
314
                auto time_value = col_from->get_data()[i];
315
                int32_t hour = TimeValue::hour(time_value);
316
                int32_t minute = TimeValue::minute(time_value);
317
                int32_t second = TimeValue::second(time_value);
318
                int32_t microsecond = TimeValue::microsecond(time_value);
319
                bool neg = TimeValue::sign(time_value) < 0;
320
321
                dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
322
                dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
323
                dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
324
                dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>(
325
                        TimeInterval(MICROSECOND, microsecond, neg));
326
327
                col_to->get_data()[i] = dtmv2;
328
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
329
                // from Datetime to Datetime
330
                auto dtmv1 = col_from->get_data()[i];
331
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
332
                        dtmv1.to_datetime_v2());
333
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
334
                DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i],
335
                                                      col_to->get_data()[i]);
336
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
337
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(source_column.type.get());
338
                auto scale = type->get_scale();
339
340
                const auto* to_type =
341
                        assert_cast<const DataTypeDateTimeV2*>(target_column.type.get());
342
                UInt32 to_scale = to_type->get_scale();
343
344
                bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i],
345
                                                    col_from->get_data()[i]);
346
                if (!success) {
347
                    if constexpr (CastMode == CastModeType::StrictMode) {
348
                        auto format_options = DataTypeSerDe::get_default_format_options();
349
                        auto time_zone = cctz::utc_time_zone();
350
                        format_options.timezone =
351
                                state != nullptr ? &state->timezone_obj() : &time_zone;
352
                        return Status::InvalidArgument(
353
                                "DatetimeV2 overflow when casting {} from {} to {}",
354
                                type->to_string(*col_from, i, format_options), type->get_name(),
355
                                to_type->get_name());
356
                    } else {
357
                        col_nullmap->get_data()[i] = true;
358
                        //TODO: maybe we can remove all set operations on nested of null cell.
359
                        // the correctness should be keep by downstream user with replace_... or manually
360
                        // process null data if need.
361
                        col_to->get_data()[i] =
362
                                binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
363
                                        MIN_DATETIME_V2);
364
                    }
365
                }
366
367
            } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
368
                const auto* type = assert_cast<const DataTypeTimeV2*>(source_column.type.get());
369
                auto scale = type->get_scale();
370
371
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(target_column.type.get());
372
                UInt32 to_scale = to_type->get_scale();
373
374
                if (to_scale >= scale) {
375
                    // nothing to do, just copy
376
                    col_to->get_data()[i] = col_from->get_data()[i];
377
                } else {
378
                    double time = col_from->get_data()[i];
379
                    auto sign = TimeValue::sign(time);
380
                    time = std::abs(time);
381
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
382
                    // 999956: 56 > 100/2, then round up to 1000000
383
                    uint32_t microseconds = TimeValue::microsecond(time);
384
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
385
                    uint32_t remainder = microseconds % divisor;
386
387
                    if (remainder >= divisor / 2) { // need to round up
388
                        // do rounding up
389
                        uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor;
390
                        // need carry on
391
                        if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
392
                            DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS);
393
                            time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) *
394
                                   TimeValue::ONE_SECOND_MICROSECONDS;
395
396
                            // the input data must be valid, so max to '838:59:59.0'. this value won't carry on
397
                            // to second.
398
                            DCHECK(TimeValue::valid(time)) << col_from->get_data()[i];
399
                        } else {
400
                            time = TimeValue::reset_microsecond(time, rounded_microseconds);
401
                        }
402
                    } else {
403
                        // truncate
404
                        time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor);
405
                    }
406
                    col_to->get_data()[i] = sign * time;
407
                }
408
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
409
                // from Datetime to Time
410
                auto dtmv2 = col_from->get_data()[i];
411
412
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(source_column.type.get());
413
                auto scale = type->get_scale();
414
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(target_column.type.get());
415
                UInt32 to_scale = to_type->get_scale();
416
417
                uint32_t hour = dtmv2.hour();
418
                uint32_t minute = dtmv2.minute();
419
                uint32_t second = dtmv2.second();
420
                uint32_t microseconds = dtmv2.microsecond();
421
                if (to_scale < scale) { // need to round
422
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
423
                    // 999956: 56 > 100/2, then round up to 1000000
424
                    DCHECK(to_scale <= 6)
425
                            << "to_scale should be in range [0, 6], but got " << to_scale;
426
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
427
                    uint32_t remainder = microseconds % divisor;
428
                    microseconds = (microseconds / divisor) * divisor;
429
                    if (remainder >= divisor / 2) {
430
                        // do rounding up
431
                        microseconds += divisor;
432
                    }
433
                }
434
435
                // carry on if microseconds >= 1000000
436
                if (microseconds >= 1000000) {
437
                    microseconds -= 1000000;
438
                    second += 1;
439
                    if (second >= 60) {
440
                        second -= 60;
441
                        minute += 1;
442
                        if (minute >= 60) {
443
                            minute -= 60;
444
                            hour += 1;
445
                        }
446
                    }
447
                }
448
449
                auto time = TimeValue::limit_with_bound(
450
                        TimeValue::make_time(hour, minute, second, microseconds));
451
                col_to->get_data()[i] = time;
452
            } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) {
453
                auto dtmv1 = col_from->get_data()[i];
454
                auto time = TimeValue::limit_with_bound(
455
                        TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second()));
456
                col_to->get_data()[i] = time;
457
            }
458
2
        }
459
460
        if constexpr (Nullable) {
461
            target_column.column =
462
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
463
2
        } else {
464
2
            target_column.column = std::move(col_to);
465
2
        }
466
2
        return Status::OK();
467
2
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_16DataTypeDateTimeENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_16DataTypeDateTimeENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeTimeV2ENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeTimeV2ENS_14DataTypeDateV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
206
2
                        const NullMap::value_type* parent_null_map = nullptr) const override {
207
2
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
208
2
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
209
210
2
        const auto* col_from =
211
2
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
212
2
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
213
2
        ColumnUInt8::MutablePtr col_nullmap;
214
215
        if constexpr (Nullable) {
216
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
217
        }
218
219
10
        for (size_t i = 0; i < input_rows_count; ++i) {
220
8
            if (parent_null_map && parent_null_map[i]) {
221
2
                continue;
222
2
            }
223
            if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) {
224
                // from Date to Date
225
                auto dtv1 = col_from->get_data()[i];
226
                dtv1.cast_to_date();
227
                col_to->get_data()[i] =
228
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2());
229
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) {
230
                DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
231
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) {
232
                // from Datetime to Date
233
                col_to->get_data()[i] = col_from->get_data()[i];
234
                DataTypeDate::cast_to_date(col_to->get_data()[i]);
235
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
236
                DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
237
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) {
238
                auto dtmv1 = col_from->get_data()[i];
239
                col_to->get_data()[i] =
240
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2());
241
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
242
                DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]);
243
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
244
                // from Time to Date
245
                VecDateTimeValue dtv;
246
                dtv.cast_to_date();
247
                dtv.from_unixtime(state->timestamp_ms() / 1000, 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(state->timestamp_ms() / 1000, state->timezone_obj());
263
264
6
                auto time_value = col_from->get_data()[i];
265
6
                int32_t hour = TimeValue::hour(time_value);
266
6
                int32_t minute = TimeValue::minute(time_value);
267
6
                int32_t second = TimeValue::second(time_value);
268
6
                bool neg = TimeValue::sign(time_value) < 0;
269
270
6
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
271
6
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
272
6
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
273
274
6
                col_to->get_data()[i] = dtv;
275
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) {
276
                // from Date to Datetime
277
                col_to->get_data()[i] = col_from->get_data()[i];
278
                DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]);
279
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
280
                DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]);
281
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
282
                auto dtv1 = col_from->get_data()[i];
283
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
284
                        dtv1.to_datetime_v2());
285
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
286
                DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i],
287
                                                     col_to->get_data()[i]);
288
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
289
                // from Time to Datetime
290
                VecDateTimeValue dtv; // datetime by default
291
                dtv.from_unixtime(state->timestamp_ms() / 1000, state->timezone_obj());
292
                dtv.reset_time_part();
293
294
                auto time_value = col_from->get_data()[i];
295
                int32_t hour = TimeValue::hour(time_value);
296
                int32_t minute = TimeValue::minute(time_value);
297
                int32_t second = TimeValue::second(time_value);
298
                bool neg = TimeValue::sign(time_value) < 0;
299
300
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
301
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
302
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
303
304
                col_to->get_data()[i] = dtv;
305
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
306
                const auto* type = assert_cast<const DataTypeTimeV2*>(source_column.type.get());
307
                auto scale = type->get_scale();
308
309
                DateV2Value<DateTimeV2ValueType> dtmv2;
310
                dtmv2.from_unixtime(state->timestamp_ms() / 1000, state->nano_seconds(),
311
                                    state->timezone_obj(), scale);
312
                dtmv2.reset_time_part();
313
314
                auto time_value = col_from->get_data()[i];
315
                int32_t hour = TimeValue::hour(time_value);
316
                int32_t minute = TimeValue::minute(time_value);
317
                int32_t second = TimeValue::second(time_value);
318
                int32_t microsecond = TimeValue::microsecond(time_value);
319
                bool neg = TimeValue::sign(time_value) < 0;
320
321
                dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
322
                dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
323
                dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
324
                dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>(
325
                        TimeInterval(MICROSECOND, microsecond, neg));
326
327
                col_to->get_data()[i] = dtmv2;
328
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
329
                // from Datetime to Datetime
330
                auto dtmv1 = col_from->get_data()[i];
331
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
332
                        dtmv1.to_datetime_v2());
333
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
334
                DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i],
335
                                                      col_to->get_data()[i]);
336
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
337
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(source_column.type.get());
338
                auto scale = type->get_scale();
339
340
                const auto* to_type =
341
                        assert_cast<const DataTypeDateTimeV2*>(target_column.type.get());
342
                UInt32 to_scale = to_type->get_scale();
343
344
                bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i],
345
                                                    col_from->get_data()[i]);
346
                if (!success) {
347
                    if constexpr (CastMode == CastModeType::StrictMode) {
348
                        auto format_options = DataTypeSerDe::get_default_format_options();
349
                        auto time_zone = cctz::utc_time_zone();
350
                        format_options.timezone =
351
                                state != nullptr ? &state->timezone_obj() : &time_zone;
352
                        return Status::InvalidArgument(
353
                                "DatetimeV2 overflow when casting {} from {} to {}",
354
                                type->to_string(*col_from, i, format_options), type->get_name(),
355
                                to_type->get_name());
356
                    } else {
357
                        col_nullmap->get_data()[i] = true;
358
                        //TODO: maybe we can remove all set operations on nested of null cell.
359
                        // the correctness should be keep by downstream user with replace_... or manually
360
                        // process null data if need.
361
                        col_to->get_data()[i] =
362
                                binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
363
                                        MIN_DATETIME_V2);
364
                    }
365
                }
366
367
            } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
368
                const auto* type = assert_cast<const DataTypeTimeV2*>(source_column.type.get());
369
                auto scale = type->get_scale();
370
371
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(target_column.type.get());
372
                UInt32 to_scale = to_type->get_scale();
373
374
                if (to_scale >= scale) {
375
                    // nothing to do, just copy
376
                    col_to->get_data()[i] = col_from->get_data()[i];
377
                } else {
378
                    double time = col_from->get_data()[i];
379
                    auto sign = TimeValue::sign(time);
380
                    time = std::abs(time);
381
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
382
                    // 999956: 56 > 100/2, then round up to 1000000
383
                    uint32_t microseconds = TimeValue::microsecond(time);
384
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
385
                    uint32_t remainder = microseconds % divisor;
386
387
                    if (remainder >= divisor / 2) { // need to round up
388
                        // do rounding up
389
                        uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor;
390
                        // need carry on
391
                        if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
392
                            DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS);
393
                            time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) *
394
                                   TimeValue::ONE_SECOND_MICROSECONDS;
395
396
                            // the input data must be valid, so max to '838:59:59.0'. this value won't carry on
397
                            // to second.
398
                            DCHECK(TimeValue::valid(time)) << col_from->get_data()[i];
399
                        } else {
400
                            time = TimeValue::reset_microsecond(time, rounded_microseconds);
401
                        }
402
                    } else {
403
                        // truncate
404
                        time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor);
405
                    }
406
                    col_to->get_data()[i] = sign * time;
407
                }
408
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
409
                // from Datetime to Time
410
                auto dtmv2 = col_from->get_data()[i];
411
412
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(source_column.type.get());
413
                auto scale = type->get_scale();
414
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(target_column.type.get());
415
                UInt32 to_scale = to_type->get_scale();
416
417
                uint32_t hour = dtmv2.hour();
418
                uint32_t minute = dtmv2.minute();
419
                uint32_t second = dtmv2.second();
420
                uint32_t microseconds = dtmv2.microsecond();
421
                if (to_scale < scale) { // need to round
422
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
423
                    // 999956: 56 > 100/2, then round up to 1000000
424
                    DCHECK(to_scale <= 6)
425
                            << "to_scale should be in range [0, 6], but got " << to_scale;
426
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
427
                    uint32_t remainder = microseconds % divisor;
428
                    microseconds = (microseconds / divisor) * divisor;
429
                    if (remainder >= divisor / 2) {
430
                        // do rounding up
431
                        microseconds += divisor;
432
                    }
433
                }
434
435
                // carry on if microseconds >= 1000000
436
                if (microseconds >= 1000000) {
437
                    microseconds -= 1000000;
438
                    second += 1;
439
                    if (second >= 60) {
440
                        second -= 60;
441
                        minute += 1;
442
                        if (minute >= 60) {
443
                            minute -= 60;
444
                            hour += 1;
445
                        }
446
                    }
447
                }
448
449
                auto time = TimeValue::limit_with_bound(
450
                        TimeValue::make_time(hour, minute, second, microseconds));
451
                col_to->get_data()[i] = time;
452
            } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) {
453
                auto dtmv1 = col_from->get_data()[i];
454
                auto time = TimeValue::limit_with_bound(
455
                        TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second()));
456
                col_to->get_data()[i] = time;
457
            }
458
6
        }
459
460
        if constexpr (Nullable) {
461
            target_column.column =
462
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
463
2
        } else {
464
2
            target_column.column = std::move(col_to);
465
2
        }
466
2
        return Status::OK();
467
2
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_12DataTypeDateENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_12DataTypeDateENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeDateV2ENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeDateV2ENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
206
2
                        const NullMap::value_type* parent_null_map = nullptr) const override {
207
2
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
208
2
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
209
210
2
        const auto* col_from =
211
2
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
212
2
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
213
2
        ColumnUInt8::MutablePtr col_nullmap;
214
215
        if constexpr (Nullable) {
216
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
217
        }
218
219
6
        for (size_t i = 0; i < input_rows_count; ++i) {
220
4
            if (parent_null_map && parent_null_map[i]) {
221
2
                continue;
222
2
            }
223
            if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) {
224
                // from Date to Date
225
                auto dtv1 = col_from->get_data()[i];
226
                dtv1.cast_to_date();
227
                col_to->get_data()[i] =
228
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2());
229
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) {
230
                DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
231
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) {
232
                // from Datetime to Date
233
                col_to->get_data()[i] = col_from->get_data()[i];
234
                DataTypeDate::cast_to_date(col_to->get_data()[i]);
235
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
236
                DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
237
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) {
238
                auto dtmv1 = col_from->get_data()[i];
239
                col_to->get_data()[i] =
240
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2());
241
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
242
                DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]);
243
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
244
                // from Time to Date
245
                VecDateTimeValue dtv;
246
                dtv.cast_to_date();
247
                dtv.from_unixtime(state->timestamp_ms() / 1000, 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(state->timestamp_ms() / 1000, state->timezone_obj());
263
264
                auto time_value = col_from->get_data()[i];
265
                int32_t hour = TimeValue::hour(time_value);
266
                int32_t minute = TimeValue::minute(time_value);
267
                int32_t second = TimeValue::second(time_value);
268
                bool neg = TimeValue::sign(time_value) < 0;
269
270
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
271
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
272
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
273
274
                col_to->get_data()[i] = dtv;
275
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) {
276
                // from Date to Datetime
277
                col_to->get_data()[i] = col_from->get_data()[i];
278
                DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]);
279
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
280
                DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]);
281
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
282
                auto dtv1 = col_from->get_data()[i];
283
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
284
                        dtv1.to_datetime_v2());
285
2
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
286
2
                DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i],
287
2
                                                     col_to->get_data()[i]);
288
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
289
                // from Time to Datetime
290
                VecDateTimeValue dtv; // datetime by default
291
                dtv.from_unixtime(state->timestamp_ms() / 1000, state->timezone_obj());
292
                dtv.reset_time_part();
293
294
                auto time_value = col_from->get_data()[i];
295
                int32_t hour = TimeValue::hour(time_value);
296
                int32_t minute = TimeValue::minute(time_value);
297
                int32_t second = TimeValue::second(time_value);
298
                bool neg = TimeValue::sign(time_value) < 0;
299
300
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
301
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
302
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
303
304
                col_to->get_data()[i] = dtv;
305
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
306
                const auto* type = assert_cast<const DataTypeTimeV2*>(source_column.type.get());
307
                auto scale = type->get_scale();
308
309
                DateV2Value<DateTimeV2ValueType> dtmv2;
310
                dtmv2.from_unixtime(state->timestamp_ms() / 1000, state->nano_seconds(),
311
                                    state->timezone_obj(), scale);
312
                dtmv2.reset_time_part();
313
314
                auto time_value = col_from->get_data()[i];
315
                int32_t hour = TimeValue::hour(time_value);
316
                int32_t minute = TimeValue::minute(time_value);
317
                int32_t second = TimeValue::second(time_value);
318
                int32_t microsecond = TimeValue::microsecond(time_value);
319
                bool neg = TimeValue::sign(time_value) < 0;
320
321
                dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
322
                dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
323
                dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
324
                dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>(
325
                        TimeInterval(MICROSECOND, microsecond, neg));
326
327
                col_to->get_data()[i] = dtmv2;
328
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
329
                // from Datetime to Datetime
330
                auto dtmv1 = col_from->get_data()[i];
331
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
332
                        dtmv1.to_datetime_v2());
333
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
334
                DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i],
335
                                                      col_to->get_data()[i]);
336
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
337
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(source_column.type.get());
338
                auto scale = type->get_scale();
339
340
                const auto* to_type =
341
                        assert_cast<const DataTypeDateTimeV2*>(target_column.type.get());
342
                UInt32 to_scale = to_type->get_scale();
343
344
                bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i],
345
                                                    col_from->get_data()[i]);
346
                if (!success) {
347
                    if constexpr (CastMode == CastModeType::StrictMode) {
348
                        auto format_options = DataTypeSerDe::get_default_format_options();
349
                        auto time_zone = cctz::utc_time_zone();
350
                        format_options.timezone =
351
                                state != nullptr ? &state->timezone_obj() : &time_zone;
352
                        return Status::InvalidArgument(
353
                                "DatetimeV2 overflow when casting {} from {} to {}",
354
                                type->to_string(*col_from, i, format_options), type->get_name(),
355
                                to_type->get_name());
356
                    } else {
357
                        col_nullmap->get_data()[i] = true;
358
                        //TODO: maybe we can remove all set operations on nested of null cell.
359
                        // the correctness should be keep by downstream user with replace_... or manually
360
                        // process null data if need.
361
                        col_to->get_data()[i] =
362
                                binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
363
                                        MIN_DATETIME_V2);
364
                    }
365
                }
366
367
            } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
368
                const auto* type = assert_cast<const DataTypeTimeV2*>(source_column.type.get());
369
                auto scale = type->get_scale();
370
371
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(target_column.type.get());
372
                UInt32 to_scale = to_type->get_scale();
373
374
                if (to_scale >= scale) {
375
                    // nothing to do, just copy
376
                    col_to->get_data()[i] = col_from->get_data()[i];
377
                } else {
378
                    double time = col_from->get_data()[i];
379
                    auto sign = TimeValue::sign(time);
380
                    time = std::abs(time);
381
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
382
                    // 999956: 56 > 100/2, then round up to 1000000
383
                    uint32_t microseconds = TimeValue::microsecond(time);
384
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
385
                    uint32_t remainder = microseconds % divisor;
386
387
                    if (remainder >= divisor / 2) { // need to round up
388
                        // do rounding up
389
                        uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor;
390
                        // need carry on
391
                        if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
392
                            DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS);
393
                            time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) *
394
                                   TimeValue::ONE_SECOND_MICROSECONDS;
395
396
                            // the input data must be valid, so max to '838:59:59.0'. this value won't carry on
397
                            // to second.
398
                            DCHECK(TimeValue::valid(time)) << col_from->get_data()[i];
399
                        } else {
400
                            time = TimeValue::reset_microsecond(time, rounded_microseconds);
401
                        }
402
                    } else {
403
                        // truncate
404
                        time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor);
405
                    }
406
                    col_to->get_data()[i] = sign * time;
407
                }
408
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
409
                // from Datetime to Time
410
                auto dtmv2 = col_from->get_data()[i];
411
412
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(source_column.type.get());
413
                auto scale = type->get_scale();
414
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(target_column.type.get());
415
                UInt32 to_scale = to_type->get_scale();
416
417
                uint32_t hour = dtmv2.hour();
418
                uint32_t minute = dtmv2.minute();
419
                uint32_t second = dtmv2.second();
420
                uint32_t microseconds = dtmv2.microsecond();
421
                if (to_scale < scale) { // need to round
422
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
423
                    // 999956: 56 > 100/2, then round up to 1000000
424
                    DCHECK(to_scale <= 6)
425
                            << "to_scale should be in range [0, 6], but got " << to_scale;
426
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
427
                    uint32_t remainder = microseconds % divisor;
428
                    microseconds = (microseconds / divisor) * divisor;
429
                    if (remainder >= divisor / 2) {
430
                        // do rounding up
431
                        microseconds += divisor;
432
                    }
433
                }
434
435
                // carry on if microseconds >= 1000000
436
                if (microseconds >= 1000000) {
437
                    microseconds -= 1000000;
438
                    second += 1;
439
                    if (second >= 60) {
440
                        second -= 60;
441
                        minute += 1;
442
                        if (minute >= 60) {
443
                            minute -= 60;
444
                            hour += 1;
445
                        }
446
                    }
447
                }
448
449
                auto time = TimeValue::limit_with_bound(
450
                        TimeValue::make_time(hour, minute, second, microseconds));
451
                col_to->get_data()[i] = time;
452
            } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) {
453
                auto dtmv1 = col_from->get_data()[i];
454
                auto time = TimeValue::limit_with_bound(
455
                        TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second()));
456
                col_to->get_data()[i] = time;
457
            }
458
2
        }
459
460
        if constexpr (Nullable) {
461
            target_column.column =
462
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
463
2
        } else {
464
2
            target_column.column = std::move(col_to);
465
2
        }
466
2
        return Status::OK();
467
2
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_18DataTypeDateTimeV2ES2_E12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS6_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_18DataTypeDateTimeV2ES2_E12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS6_mPKh
Line
Count
Source
206
1
                        const NullMap::value_type* parent_null_map = nullptr) const override {
207
1
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
208
1
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
209
210
1
        const auto* col_from =
211
1
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
212
1
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
213
1
        ColumnUInt8::MutablePtr col_nullmap;
214
215
1
        if constexpr (Nullable) {
216
1
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
217
1
        }
218
219
2
        for (size_t i = 0; i < input_rows_count; ++i) {
220
1
            if (parent_null_map && parent_null_map[i]) {
221
0
                continue;
222
0
            }
223
            if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) {
224
                // from Date to Date
225
                auto dtv1 = col_from->get_data()[i];
226
                dtv1.cast_to_date();
227
                col_to->get_data()[i] =
228
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2());
229
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) {
230
                DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
231
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) {
232
                // from Datetime to Date
233
                col_to->get_data()[i] = col_from->get_data()[i];
234
                DataTypeDate::cast_to_date(col_to->get_data()[i]);
235
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
236
                DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
237
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) {
238
                auto dtmv1 = col_from->get_data()[i];
239
                col_to->get_data()[i] =
240
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2());
241
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
242
                DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]);
243
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
244
                // from Time to Date
245
                VecDateTimeValue dtv;
246
                dtv.cast_to_date();
247
                dtv.from_unixtime(state->timestamp_ms() / 1000, 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(state->timestamp_ms() / 1000, state->timezone_obj());
263
264
                auto time_value = col_from->get_data()[i];
265
                int32_t hour = TimeValue::hour(time_value);
266
                int32_t minute = TimeValue::minute(time_value);
267
                int32_t second = TimeValue::second(time_value);
268
                bool neg = TimeValue::sign(time_value) < 0;
269
270
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
271
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
272
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
273
274
                col_to->get_data()[i] = dtv;
275
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) {
276
                // from Date to Datetime
277
                col_to->get_data()[i] = col_from->get_data()[i];
278
                DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]);
279
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
280
                DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]);
281
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
282
                auto dtv1 = col_from->get_data()[i];
283
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
284
                        dtv1.to_datetime_v2());
285
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
286
                DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i],
287
                                                     col_to->get_data()[i]);
288
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
289
                // from Time to Datetime
290
                VecDateTimeValue dtv; // datetime by default
291
                dtv.from_unixtime(state->timestamp_ms() / 1000, state->timezone_obj());
292
                dtv.reset_time_part();
293
294
                auto time_value = col_from->get_data()[i];
295
                int32_t hour = TimeValue::hour(time_value);
296
                int32_t minute = TimeValue::minute(time_value);
297
                int32_t second = TimeValue::second(time_value);
298
                bool neg = TimeValue::sign(time_value) < 0;
299
300
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
301
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
302
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
303
304
                col_to->get_data()[i] = dtv;
305
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
306
                const auto* type = assert_cast<const DataTypeTimeV2*>(source_column.type.get());
307
                auto scale = type->get_scale();
308
309
                DateV2Value<DateTimeV2ValueType> dtmv2;
310
                dtmv2.from_unixtime(state->timestamp_ms() / 1000, state->nano_seconds(),
311
                                    state->timezone_obj(), scale);
312
                dtmv2.reset_time_part();
313
314
                auto time_value = col_from->get_data()[i];
315
                int32_t hour = TimeValue::hour(time_value);
316
                int32_t minute = TimeValue::minute(time_value);
317
                int32_t second = TimeValue::second(time_value);
318
                int32_t microsecond = TimeValue::microsecond(time_value);
319
                bool neg = TimeValue::sign(time_value) < 0;
320
321
                dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
322
                dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
323
                dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
324
                dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>(
325
                        TimeInterval(MICROSECOND, microsecond, neg));
326
327
                col_to->get_data()[i] = dtmv2;
328
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
329
                // from Datetime to Datetime
330
                auto dtmv1 = col_from->get_data()[i];
331
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
332
                        dtmv1.to_datetime_v2());
333
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
334
                DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i],
335
                                                      col_to->get_data()[i]);
336
1
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
337
1
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(source_column.type.get());
338
1
                auto scale = type->get_scale();
339
340
1
                const auto* to_type =
341
1
                        assert_cast<const DataTypeDateTimeV2*>(target_column.type.get());
342
1
                UInt32 to_scale = to_type->get_scale();
343
344
1
                bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i],
345
1
                                                    col_from->get_data()[i]);
346
1
                if (!success) {
347
                    if constexpr (CastMode == CastModeType::StrictMode) {
348
                        auto format_options = DataTypeSerDe::get_default_format_options();
349
                        auto time_zone = cctz::utc_time_zone();
350
                        format_options.timezone =
351
                                state != nullptr ? &state->timezone_obj() : &time_zone;
352
                        return Status::InvalidArgument(
353
                                "DatetimeV2 overflow when casting {} from {} to {}",
354
                                type->to_string(*col_from, i, format_options), type->get_name(),
355
                                to_type->get_name());
356
0
                    } else {
357
0
                        col_nullmap->get_data()[i] = true;
358
                        //TODO: maybe we can remove all set operations on nested of null cell.
359
                        // the correctness should be keep by downstream user with replace_... or manually
360
                        // process null data if need.
361
0
                        col_to->get_data()[i] =
362
0
                                binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
363
0
                                        MIN_DATETIME_V2);
364
0
                    }
365
0
                }
366
367
            } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
368
                const auto* type = assert_cast<const DataTypeTimeV2*>(source_column.type.get());
369
                auto scale = type->get_scale();
370
371
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(target_column.type.get());
372
                UInt32 to_scale = to_type->get_scale();
373
374
                if (to_scale >= scale) {
375
                    // nothing to do, just copy
376
                    col_to->get_data()[i] = col_from->get_data()[i];
377
                } else {
378
                    double time = col_from->get_data()[i];
379
                    auto sign = TimeValue::sign(time);
380
                    time = std::abs(time);
381
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
382
                    // 999956: 56 > 100/2, then round up to 1000000
383
                    uint32_t microseconds = TimeValue::microsecond(time);
384
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
385
                    uint32_t remainder = microseconds % divisor;
386
387
                    if (remainder >= divisor / 2) { // need to round up
388
                        // do rounding up
389
                        uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor;
390
                        // need carry on
391
                        if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
392
                            DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS);
393
                            time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) *
394
                                   TimeValue::ONE_SECOND_MICROSECONDS;
395
396
                            // the input data must be valid, so max to '838:59:59.0'. this value won't carry on
397
                            // to second.
398
                            DCHECK(TimeValue::valid(time)) << col_from->get_data()[i];
399
                        } else {
400
                            time = TimeValue::reset_microsecond(time, rounded_microseconds);
401
                        }
402
                    } else {
403
                        // truncate
404
                        time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor);
405
                    }
406
                    col_to->get_data()[i] = sign * time;
407
                }
408
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
409
                // from Datetime to Time
410
                auto dtmv2 = col_from->get_data()[i];
411
412
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(source_column.type.get());
413
                auto scale = type->get_scale();
414
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(target_column.type.get());
415
                UInt32 to_scale = to_type->get_scale();
416
417
                uint32_t hour = dtmv2.hour();
418
                uint32_t minute = dtmv2.minute();
419
                uint32_t second = dtmv2.second();
420
                uint32_t microseconds = dtmv2.microsecond();
421
                if (to_scale < scale) { // need to round
422
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
423
                    // 999956: 56 > 100/2, then round up to 1000000
424
                    DCHECK(to_scale <= 6)
425
                            << "to_scale should be in range [0, 6], but got " << to_scale;
426
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
427
                    uint32_t remainder = microseconds % divisor;
428
                    microseconds = (microseconds / divisor) * divisor;
429
                    if (remainder >= divisor / 2) {
430
                        // do rounding up
431
                        microseconds += divisor;
432
                    }
433
                }
434
435
                // carry on if microseconds >= 1000000
436
                if (microseconds >= 1000000) {
437
                    microseconds -= 1000000;
438
                    second += 1;
439
                    if (second >= 60) {
440
                        second -= 60;
441
                        minute += 1;
442
                        if (minute >= 60) {
443
                            minute -= 60;
444
                            hour += 1;
445
                        }
446
                    }
447
                }
448
449
                auto time = TimeValue::limit_with_bound(
450
                        TimeValue::make_time(hour, minute, second, microseconds));
451
                col_to->get_data()[i] = time;
452
            } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) {
453
                auto dtmv1 = col_from->get_data()[i];
454
                auto time = TimeValue::limit_with_bound(
455
                        TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second()));
456
                col_to->get_data()[i] = time;
457
            }
458
1
        }
459
460
1
        if constexpr (Nullable) {
461
1
            target_column.column =
462
1
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
463
        } else {
464
            target_column.column = std::move(col_to);
465
        }
466
1
        return Status::OK();
467
1
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_16DataTypeDateTimeENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_16DataTypeDateTimeENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeTimeV2ENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeTimeV2ENS_18DataTypeDateTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
206
2
                        const NullMap::value_type* parent_null_map = nullptr) const override {
207
2
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
208
2
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
209
210
2
        const auto* col_from =
211
2
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
212
2
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
213
2
        ColumnUInt8::MutablePtr col_nullmap;
214
215
        if constexpr (Nullable) {
216
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
217
        }
218
219
10
        for (size_t i = 0; i < input_rows_count; ++i) {
220
8
            if (parent_null_map && parent_null_map[i]) {
221
2
                continue;
222
2
            }
223
            if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) {
224
                // from Date to Date
225
                auto dtv1 = col_from->get_data()[i];
226
                dtv1.cast_to_date();
227
                col_to->get_data()[i] =
228
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2());
229
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) {
230
                DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
231
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) {
232
                // from Datetime to Date
233
                col_to->get_data()[i] = col_from->get_data()[i];
234
                DataTypeDate::cast_to_date(col_to->get_data()[i]);
235
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
236
                DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
237
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) {
238
                auto dtmv1 = col_from->get_data()[i];
239
                col_to->get_data()[i] =
240
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2());
241
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
242
                DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]);
243
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
244
                // from Time to Date
245
                VecDateTimeValue dtv;
246
                dtv.cast_to_date();
247
                dtv.from_unixtime(state->timestamp_ms() / 1000, 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(state->timestamp_ms() / 1000, state->timezone_obj());
263
264
                auto time_value = col_from->get_data()[i];
265
                int32_t hour = TimeValue::hour(time_value);
266
                int32_t minute = TimeValue::minute(time_value);
267
                int32_t second = TimeValue::second(time_value);
268
                bool neg = TimeValue::sign(time_value) < 0;
269
270
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
271
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
272
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
273
274
                col_to->get_data()[i] = dtv;
275
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) {
276
                // from Date to Datetime
277
                col_to->get_data()[i] = col_from->get_data()[i];
278
                DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]);
279
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
280
                DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]);
281
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
282
                auto dtv1 = col_from->get_data()[i];
283
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
284
                        dtv1.to_datetime_v2());
285
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
286
                DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i],
287
                                                     col_to->get_data()[i]);
288
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
289
                // from Time to Datetime
290
                VecDateTimeValue dtv; // datetime by default
291
                dtv.from_unixtime(state->timestamp_ms() / 1000, state->timezone_obj());
292
                dtv.reset_time_part();
293
294
                auto time_value = col_from->get_data()[i];
295
                int32_t hour = TimeValue::hour(time_value);
296
                int32_t minute = TimeValue::minute(time_value);
297
                int32_t second = TimeValue::second(time_value);
298
                bool neg = TimeValue::sign(time_value) < 0;
299
300
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
301
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
302
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
303
304
                col_to->get_data()[i] = dtv;
305
6
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
306
6
                const auto* type = assert_cast<const DataTypeTimeV2*>(source_column.type.get());
307
6
                auto scale = type->get_scale();
308
309
6
                DateV2Value<DateTimeV2ValueType> dtmv2;
310
6
                dtmv2.from_unixtime(state->timestamp_ms() / 1000, state->nano_seconds(),
311
6
                                    state->timezone_obj(), scale);
312
6
                dtmv2.reset_time_part();
313
314
6
                auto time_value = col_from->get_data()[i];
315
6
                int32_t hour = TimeValue::hour(time_value);
316
6
                int32_t minute = TimeValue::minute(time_value);
317
6
                int32_t second = TimeValue::second(time_value);
318
6
                int32_t microsecond = TimeValue::microsecond(time_value);
319
6
                bool neg = TimeValue::sign(time_value) < 0;
320
321
6
                dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
322
6
                dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
323
6
                dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
324
6
                dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>(
325
6
                        TimeInterval(MICROSECOND, microsecond, neg));
326
327
6
                col_to->get_data()[i] = dtmv2;
328
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
329
                // from Datetime to Datetime
330
                auto dtmv1 = col_from->get_data()[i];
331
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
332
                        dtmv1.to_datetime_v2());
333
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
334
                DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i],
335
                                                      col_to->get_data()[i]);
336
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
337
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(source_column.type.get());
338
                auto scale = type->get_scale();
339
340
                const auto* to_type =
341
                        assert_cast<const DataTypeDateTimeV2*>(target_column.type.get());
342
                UInt32 to_scale = to_type->get_scale();
343
344
                bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i],
345
                                                    col_from->get_data()[i]);
346
                if (!success) {
347
                    if constexpr (CastMode == CastModeType::StrictMode) {
348
                        auto format_options = DataTypeSerDe::get_default_format_options();
349
                        auto time_zone = cctz::utc_time_zone();
350
                        format_options.timezone =
351
                                state != nullptr ? &state->timezone_obj() : &time_zone;
352
                        return Status::InvalidArgument(
353
                                "DatetimeV2 overflow when casting {} from {} to {}",
354
                                type->to_string(*col_from, i, format_options), type->get_name(),
355
                                to_type->get_name());
356
                    } else {
357
                        col_nullmap->get_data()[i] = true;
358
                        //TODO: maybe we can remove all set operations on nested of null cell.
359
                        // the correctness should be keep by downstream user with replace_... or manually
360
                        // process null data if need.
361
                        col_to->get_data()[i] =
362
                                binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
363
                                        MIN_DATETIME_V2);
364
                    }
365
                }
366
367
            } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
368
                const auto* type = assert_cast<const DataTypeTimeV2*>(source_column.type.get());
369
                auto scale = type->get_scale();
370
371
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(target_column.type.get());
372
                UInt32 to_scale = to_type->get_scale();
373
374
                if (to_scale >= scale) {
375
                    // nothing to do, just copy
376
                    col_to->get_data()[i] = col_from->get_data()[i];
377
                } else {
378
                    double time = col_from->get_data()[i];
379
                    auto sign = TimeValue::sign(time);
380
                    time = std::abs(time);
381
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
382
                    // 999956: 56 > 100/2, then round up to 1000000
383
                    uint32_t microseconds = TimeValue::microsecond(time);
384
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
385
                    uint32_t remainder = microseconds % divisor;
386
387
                    if (remainder >= divisor / 2) { // need to round up
388
                        // do rounding up
389
                        uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor;
390
                        // need carry on
391
                        if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
392
                            DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS);
393
                            time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) *
394
                                   TimeValue::ONE_SECOND_MICROSECONDS;
395
396
                            // the input data must be valid, so max to '838:59:59.0'. this value won't carry on
397
                            // to second.
398
                            DCHECK(TimeValue::valid(time)) << col_from->get_data()[i];
399
                        } else {
400
                            time = TimeValue::reset_microsecond(time, rounded_microseconds);
401
                        }
402
                    } else {
403
                        // truncate
404
                        time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor);
405
                    }
406
                    col_to->get_data()[i] = sign * time;
407
                }
408
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
409
                // from Datetime to Time
410
                auto dtmv2 = col_from->get_data()[i];
411
412
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(source_column.type.get());
413
                auto scale = type->get_scale();
414
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(target_column.type.get());
415
                UInt32 to_scale = to_type->get_scale();
416
417
                uint32_t hour = dtmv2.hour();
418
                uint32_t minute = dtmv2.minute();
419
                uint32_t second = dtmv2.second();
420
                uint32_t microseconds = dtmv2.microsecond();
421
                if (to_scale < scale) { // need to round
422
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
423
                    // 999956: 56 > 100/2, then round up to 1000000
424
                    DCHECK(to_scale <= 6)
425
                            << "to_scale should be in range [0, 6], but got " << to_scale;
426
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
427
                    uint32_t remainder = microseconds % divisor;
428
                    microseconds = (microseconds / divisor) * divisor;
429
                    if (remainder >= divisor / 2) {
430
                        // do rounding up
431
                        microseconds += divisor;
432
                    }
433
                }
434
435
                // carry on if microseconds >= 1000000
436
                if (microseconds >= 1000000) {
437
                    microseconds -= 1000000;
438
                    second += 1;
439
                    if (second >= 60) {
440
                        second -= 60;
441
                        minute += 1;
442
                        if (minute >= 60) {
443
                            minute -= 60;
444
                            hour += 1;
445
                        }
446
                    }
447
                }
448
449
                auto time = TimeValue::limit_with_bound(
450
                        TimeValue::make_time(hour, minute, second, microseconds));
451
                col_to->get_data()[i] = time;
452
            } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) {
453
                auto dtmv1 = col_from->get_data()[i];
454
                auto time = TimeValue::limit_with_bound(
455
                        TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second()));
456
                col_to->get_data()[i] = time;
457
            }
458
6
        }
459
460
        if constexpr (Nullable) {
461
            target_column.column =
462
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
463
2
        } else {
464
2
            target_column.column = std::move(col_to);
465
2
        }
466
2
        return Status::OK();
467
2
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_12DataTypeDateENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_12DataTypeDateENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeDateV2ENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeDateV2ENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_18DataTypeDateTimeV2ENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
_ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_18DataTypeDateTimeV2ENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Line
Count
Source
206
1
                        const NullMap::value_type* parent_null_map = nullptr) const override {
207
1
        constexpr bool Nullable = std::is_same_v<FromDataType, ToDataType> &&
208
1
                                  (IsTimeV2Type<FromDataType> || IsDateTimeV2Type<FromDataType>);
209
210
1
        const auto* col_from =
211
1
                assert_cast<const typename FromDataType::ColumnType*>(source_column.column.get());
212
1
        auto col_to = ToDataType::ColumnType::create(input_rows_count);
213
1
        ColumnUInt8::MutablePtr col_nullmap;
214
215
        if constexpr (Nullable) {
216
            col_nullmap = ColumnUInt8::create(input_rows_count, 0);
217
        }
218
219
2
        for (size_t i = 0; i < input_rows_count; ++i) {
220
1
            if (parent_null_map && parent_null_map[i]) {
221
0
                continue;
222
0
            }
223
            if constexpr (IsDateType<FromDataType> && IsDateV2Type<ToDataType>) {
224
                // from Date to Date
225
                auto dtv1 = col_from->get_data()[i];
226
                dtv1.cast_to_date();
227
                col_to->get_data()[i] =
228
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtv1.to_date_v2());
229
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateType<ToDataType>) {
230
                DataTypeDateV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
231
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateType<ToDataType>) {
232
                // from Datetime to Date
233
                col_to->get_data()[i] = col_from->get_data()[i];
234
                DataTypeDate::cast_to_date(col_to->get_data()[i]);
235
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
236
                DataTypeDateTimeV2::cast_to_date(col_from->get_data()[i], col_to->get_data()[i]);
237
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateV2Type<ToDataType>) {
238
                auto dtmv1 = col_from->get_data()[i];
239
                col_to->get_data()[i] =
240
                        binary_cast<uint32_t, DateV2Value<DateV2ValueType>>(dtmv1.to_date_v2());
241
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateV2Type<ToDataType>) {
242
                DataTypeDateTimeV2::cast_to_date_v2(col_from->get_data()[i], col_to->get_data()[i]);
243
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateType<ToDataType>) {
244
                // from Time to Date
245
                VecDateTimeValue dtv;
246
                dtv.cast_to_date();
247
                dtv.from_unixtime(state->timestamp_ms() / 1000, 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(state->timestamp_ms() / 1000, state->timezone_obj());
263
264
                auto time_value = col_from->get_data()[i];
265
                int32_t hour = TimeValue::hour(time_value);
266
                int32_t minute = TimeValue::minute(time_value);
267
                int32_t second = TimeValue::second(time_value);
268
                bool neg = TimeValue::sign(time_value) < 0;
269
270
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
271
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
272
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
273
274
                col_to->get_data()[i] = dtv;
275
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeType<ToDataType>) {
276
                // from Date to Datetime
277
                col_to->get_data()[i] = col_from->get_data()[i];
278
                DataTypeDateTime::cast_to_date_time(col_to->get_data()[i]);
279
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
280
                DataTypeDateV2::cast_to_date_time(col_from->get_data()[i], col_to->get_data()[i]);
281
            } else if constexpr (IsDateType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
282
                auto dtv1 = col_from->get_data()[i];
283
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
284
                        dtv1.to_datetime_v2());
285
            } else if constexpr (IsDateV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
286
                DataTypeDateV2::cast_to_date_time_v2(col_from->get_data()[i],
287
                                                     col_to->get_data()[i]);
288
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
289
                // from Time to Datetime
290
                VecDateTimeValue dtv; // datetime by default
291
                dtv.from_unixtime(state->timestamp_ms() / 1000, state->timezone_obj());
292
                dtv.reset_time_part();
293
294
                auto time_value = col_from->get_data()[i];
295
                int32_t hour = TimeValue::hour(time_value);
296
                int32_t minute = TimeValue::minute(time_value);
297
                int32_t second = TimeValue::second(time_value);
298
                bool neg = TimeValue::sign(time_value) < 0;
299
300
                dtv.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
301
                dtv.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
302
                dtv.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
303
304
                col_to->get_data()[i] = dtv;
305
            } else if constexpr (IsTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
306
                const auto* type = assert_cast<const DataTypeTimeV2*>(source_column.type.get());
307
                auto scale = type->get_scale();
308
309
                DateV2Value<DateTimeV2ValueType> dtmv2;
310
                dtmv2.from_unixtime(state->timestamp_ms() / 1000, state->nano_seconds(),
311
                                    state->timezone_obj(), scale);
312
                dtmv2.reset_time_part();
313
314
                auto time_value = col_from->get_data()[i];
315
                int32_t hour = TimeValue::hour(time_value);
316
                int32_t minute = TimeValue::minute(time_value);
317
                int32_t second = TimeValue::second(time_value);
318
                int32_t microsecond = TimeValue::microsecond(time_value);
319
                bool neg = TimeValue::sign(time_value) < 0;
320
321
                dtmv2.date_add_interval<TimeUnit::HOUR, false>(TimeInterval(HOUR, hour, neg));
322
                dtmv2.date_add_interval<TimeUnit::MINUTE, false>(TimeInterval(MINUTE, minute, neg));
323
                dtmv2.date_add_interval<TimeUnit::SECOND, false>(TimeInterval(SECOND, second, neg));
324
                dtmv2.date_add_interval<TimeUnit::MICROSECOND, false>(
325
                        TimeInterval(MICROSECOND, microsecond, neg));
326
327
                col_to->get_data()[i] = dtmv2;
328
            } else if constexpr (IsDateTimeType<FromDataType> && IsDateTimeV2Type<ToDataType>) {
329
                // from Datetime to Datetime
330
                auto dtmv1 = col_from->get_data()[i];
331
                col_to->get_data()[i] = binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
332
                        dtmv1.to_datetime_v2());
333
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeType<ToDataType>) {
334
                DataTypeDateTimeV2::cast_to_date_time(col_from->get_data()[i],
335
                                                      col_to->get_data()[i]);
336
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsDateTimeV2Type<ToDataType>) {
337
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(source_column.type.get());
338
                auto scale = type->get_scale();
339
340
                const auto* to_type =
341
                        assert_cast<const DataTypeDateTimeV2*>(target_column.type.get());
342
                UInt32 to_scale = to_type->get_scale();
343
344
                bool success = transform_date_scale(to_scale, scale, col_to->get_data()[i],
345
                                                    col_from->get_data()[i]);
346
                if (!success) {
347
                    if constexpr (CastMode == CastModeType::StrictMode) {
348
                        auto format_options = DataTypeSerDe::get_default_format_options();
349
                        auto time_zone = cctz::utc_time_zone();
350
                        format_options.timezone =
351
                                state != nullptr ? &state->timezone_obj() : &time_zone;
352
                        return Status::InvalidArgument(
353
                                "DatetimeV2 overflow when casting {} from {} to {}",
354
                                type->to_string(*col_from, i, format_options), type->get_name(),
355
                                to_type->get_name());
356
                    } else {
357
                        col_nullmap->get_data()[i] = true;
358
                        //TODO: maybe we can remove all set operations on nested of null cell.
359
                        // the correctness should be keep by downstream user with replace_... or manually
360
                        // process null data if need.
361
                        col_to->get_data()[i] =
362
                                binary_cast<uint64_t, DateV2Value<DateTimeV2ValueType>>(
363
                                        MIN_DATETIME_V2);
364
                    }
365
                }
366
367
            } else if constexpr (IsTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
368
                const auto* type = assert_cast<const DataTypeTimeV2*>(source_column.type.get());
369
                auto scale = type->get_scale();
370
371
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(target_column.type.get());
372
                UInt32 to_scale = to_type->get_scale();
373
374
                if (to_scale >= scale) {
375
                    // nothing to do, just copy
376
                    col_to->get_data()[i] = col_from->get_data()[i];
377
                } else {
378
                    double time = col_from->get_data()[i];
379
                    auto sign = TimeValue::sign(time);
380
                    time = std::abs(time);
381
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
382
                    // 999956: 56 > 100/2, then round up to 1000000
383
                    uint32_t microseconds = TimeValue::microsecond(time);
384
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
385
                    uint32_t remainder = microseconds % divisor;
386
387
                    if (remainder >= divisor / 2) { // need to round up
388
                        // do rounding up
389
                        uint32_t rounded_microseconds = ((microseconds / divisor) + 1) * divisor;
390
                        // need carry on
391
                        if (rounded_microseconds >= TimeValue::ONE_SECOND_MICROSECONDS) {
392
                            DCHECK(rounded_microseconds == TimeValue::ONE_SECOND_MICROSECONDS);
393
                            time = ((int64_t)time / TimeValue::ONE_SECOND_MICROSECONDS + 1) *
394
                                   TimeValue::ONE_SECOND_MICROSECONDS;
395
396
                            // the input data must be valid, so max to '838:59:59.0'. this value won't carry on
397
                            // to second.
398
                            DCHECK(TimeValue::valid(time)) << col_from->get_data()[i];
399
                        } else {
400
                            time = TimeValue::reset_microsecond(time, rounded_microseconds);
401
                        }
402
                    } else {
403
                        // truncate
404
                        time = TimeValue::reset_microsecond(time, microseconds / divisor * divisor);
405
                    }
406
                    col_to->get_data()[i] = sign * time;
407
                }
408
1
            } else if constexpr (IsDateTimeV2Type<FromDataType> && IsTimeV2Type<ToDataType>) {
409
                // from Datetime to Time
410
1
                auto dtmv2 = col_from->get_data()[i];
411
412
1
                const auto* type = assert_cast<const DataTypeDateTimeV2*>(source_column.type.get());
413
1
                auto scale = type->get_scale();
414
1
                const auto* to_type = assert_cast<const DataTypeTimeV2*>(target_column.type.get());
415
1
                UInt32 to_scale = to_type->get_scale();
416
417
1
                uint32_t hour = dtmv2.hour();
418
1
                uint32_t minute = dtmv2.minute();
419
1
                uint32_t second = dtmv2.second();
420
1
                uint32_t microseconds = dtmv2.microsecond();
421
1
                if (to_scale < scale) { // need to round
422
                    // e.g. scale reduce to 4, means we need to round the last 2 digits
423
                    // 999956: 56 > 100/2, then round up to 1000000
424
1
                    DCHECK(to_scale <= 6)
425
0
                            << "to_scale should be in range [0, 6], but got " << to_scale;
426
1
                    auto divisor = (uint32_t)common::exp10_i64(6 - to_scale);
427
1
                    uint32_t remainder = microseconds % divisor;
428
1
                    microseconds = (microseconds / divisor) * divisor;
429
1
                    if (remainder >= divisor / 2) {
430
                        // do rounding up
431
1
                        microseconds += divisor;
432
1
                    }
433
1
                }
434
435
                // carry on if microseconds >= 1000000
436
1
                if (microseconds >= 1000000) {
437
0
                    microseconds -= 1000000;
438
0
                    second += 1;
439
0
                    if (second >= 60) {
440
0
                        second -= 60;
441
0
                        minute += 1;
442
0
                        if (minute >= 60) {
443
0
                            minute -= 60;
444
0
                            hour += 1;
445
0
                        }
446
0
                    }
447
0
                }
448
449
1
                auto time = TimeValue::limit_with_bound(
450
1
                        TimeValue::make_time(hour, minute, second, microseconds));
451
1
                col_to->get_data()[i] = time;
452
            } else if constexpr (IsDateTimeType<FromDataType> && IsTimeV2Type<ToDataType>) {
453
                auto dtmv1 = col_from->get_data()[i];
454
                auto time = TimeValue::limit_with_bound(
455
                        TimeValue::make_time(dtmv1.hour(), dtmv1.minute(), dtmv1.second()));
456
                col_to->get_data()[i] = time;
457
            }
458
1
        }
459
460
        if constexpr (Nullable) {
461
            target_column.column =
462
                    ColumnNullable::create(std::move(col_to), std::move(col_nullmap));
463
1
        } else {
464
1
            target_column.column = std::move(col_to);
465
1
        }
466
1
        return Status::OK();
467
1
    }
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_16DataTypeDateTimeENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_16DataTypeDateTimeENS_14DataTypeTimeV2EE12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS7_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE0ENS_14DataTypeTimeV2ES2_E12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS6_mPKh
Unexecuted instantiation: _ZNK5doris10CastToImplILNS_12CastModeTypeE1ENS_14DataTypeTimeV2ES2_E12execute_implEPNS_12RuntimeStateERKNS_21ColumnWithTypeAndNameERS6_mPKh
468
};
469
470
template <>
471
class CastToImpl<CastModeType::StrictMode, DataTypeTimeStampTz, DataTypeDateTimeV2>
472
        : public CastToBase {
473
public:
474
    Status execute_impl(RuntimeState* state, const ColumnWithTypeAndName& source_column,
475
                        ColumnWithTypeAndName& target_column, size_t input_rows_count,
476
7
                        const NullMap::value_type* parent_null_map = nullptr) const override {
477
7
        const auto& col_from =
478
7
                assert_cast<const ColumnTimeStampTz&>(*source_column.column).get_data();
479
480
7
        auto col_to = ColumnDateTimeV2::create(input_rows_count);
481
7
        auto& col_to_data = col_to->get_data();
482
7
        const auto& local_time_zone = state->timezone_obj();
483
484
7
        const auto tz_scale = source_column.type->get_scale();
485
7
        const auto dt_scale = target_column.type->get_scale();
486
487
17
        for (int i = 0; i < input_rows_count; ++i) {
488
14
            if (parent_null_map && parent_null_map[i]) {
489
1
                continue;
490
1
            }
491
13
            TimestampTzValue from_tz {col_from[i]};
492
13
            DateV2Value<DateTimeV2ValueType> dt;
493
13
            if (!from_tz.to_datetime(dt, local_time_zone, dt_scale, tz_scale)) {
494
                // The failed local conversion may also be unformattable. Render the stored
495
                // UTC fields so reporting the cast error cannot throw a second exception.
496
4
                return Status::InvalidArgument(
497
4
                        "can not cast from  timestamptz : {} UTC to datetime in timezone : {}",
498
4
                        from_tz.utc_dt().to_string(tz_scale), state->timezone());
499
4
            }
500
9
            col_to_data[i] = dt.to_date_int_val();
501
9
        }
502
503
3
        target_column.column = std::move(col_to);
504
3
        return Status::OK();
505
7
    }
506
};
507
508
template <>
509
class CastToImpl<CastModeType::NonStrictMode, DataTypeTimeStampTz, DataTypeDateTimeV2>
510
        : public CastToBase {
511
public:
512
    Status execute_impl(RuntimeState* state, const ColumnWithTypeAndName& source_column,
513
                        ColumnWithTypeAndName& target_column, size_t input_rows_count,
514
8
                        const NullMap::value_type* parent_null_map = nullptr) const override {
515
8
        const auto& col_from =
516
8
                assert_cast<const ColumnTimeStampTz&>(*source_column.column).get_data();
517
518
8
        auto col_to = ColumnDateTimeV2::create(input_rows_count);
519
8
        auto& col_to_data = col_to->get_data();
520
8
        auto col_null = ColumnBool::create(input_rows_count, 0);
521
8
        auto& col_null_map = col_null->get_data();
522
8
        const auto& local_time_zone = state->timezone_obj();
523
524
8
        const auto tz_scale = source_column.type->get_scale();
525
8
        const auto dt_scale = target_column.type->get_scale();
526
527
30
        for (int i = 0; i < input_rows_count; ++i) {
528
22
            if (parent_null_map != nullptr && parent_null_map[i] != 0) {
529
4
                continue;
530
4
            }
531
18
            TimestampTzValue from_tz {col_from[i]};
532
18
            DateV2Value<DateTimeV2ValueType> dt;
533
18
            if (from_tz.to_datetime(dt, local_time_zone, dt_scale, tz_scale)) {
534
15
                col_to_data[i] = dt;
535
15
            } else {
536
3
                col_null_map[i] = 1;
537
3
                col_to_data[i] = MIN_DATETIME_V2;
538
3
            }
539
18
        }
540
8
        target_column.column = ColumnNullable::create(std::move(col_to), std::move(col_null));
541
8
        return Status::OK();
542
8
    }
543
};
544
545
} // namespace doris