Coverage Report

Created: 2025-06-16 12:20

/root/doris/be/src/util/binary_cast.hpp
Line
Count
Source (jump to first uncovered line)
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 <cstddef>
21
#include <cstdint>
22
#include <type_traits>
23
24
#include "runtime/decimalv2_value.h"
25
#include "util/types.h"
26
#include "vec/core/wide_integer.h"
27
#include "vec/runtime/vdatetime_value.h"
28
namespace doris {
29
union TypeConverter {
30
    uint64_t u64;
31
    int64_t i64;
32
    uint32_t u32[2];
33
    int32_t i32[2];
34
    uint8_t u8[8];
35
    float flt[2];
36
    double dbl;
37
};
38
39
template <typename C0, typename C1, typename T0, typename T1>
40
constexpr bool match_v = std::is_same_v<C0, C1> && std::is_same_v<T0, T1>;
41
42
union DecimalInt128Union {
43
    DecimalV2Value decimal;
44
    PackedInt128 packed128;
45
    __int128_t i128;
46
};
47
48
static_assert(sizeof(DecimalV2Value) == sizeof(PackedInt128));
49
static_assert(sizeof(DecimalV2Value) == sizeof(__int128_t));
50
51
union VecDateTimeInt64Union {
52
    doris::VecDateTimeValue dt;
53
    __int64_t i64;
54
20.8k
    ~VecDateTimeInt64Union() {}
55
};
56
57
union DateV2UInt32Union {
58
    DateV2Value<DateV2ValueType> dt;
59
    uint32_t ui32;
60
845
    ~DateV2UInt32Union() {}
61
};
62
63
union DateTimeV2UInt64Union {
64
    DateV2Value<DateTimeV2ValueType> dt;
65
    uint64_t ui64;
66
2.22k
    ~DateTimeV2UInt64Union() {}
67
};
68
69
// similar to reinterpret_cast but won't break strict-aliasing rules
70
template <typename From, typename To>
71
24.0k
To binary_cast(From from) {
72
24.0k
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
24.0k
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
24.0k
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
24.0k
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
24.0k
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
24.0k
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
24.0k
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
24.0k
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
24.0k
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
24.0k
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
24.0k
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
24.0k
    constexpr bool from_ui64_to_datetime_v2 =
87
24.0k
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
24.0k
    constexpr bool from_datetime_v2_to_ui64 =
90
24.0k
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
24.0k
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
24.0k
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
24.0k
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
24.0k
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
24.0k
    if constexpr (from_u64_to_db) {
98
24.0k
        TypeConverter conv;
99
24.0k
        conv.u64 = from;
100
24.0k
        return conv.dbl;
101
24.0k
    } else if constexpr (from_i64_to_db) {
102
24.0k
        TypeConverter conv;
103
24.0k
        conv.i64 = from;
104
24.0k
        return conv.dbl;
105
24.0k
    } else if constexpr (from_db_to_i64) {
106
24.0k
        TypeConverter conv;
107
24.0k
        conv.dbl = from;
108
24.0k
        return conv.i64;
109
24.0k
    } else if constexpr (from_db_to_u64) {
110
24.0k
        TypeConverter conv;
111
24.0k
        conv.dbl = from;
112
24.0k
        return conv.u64;
113
24.0k
    } else if constexpr (from_i64_to_vec_dt) {
114
23.2k
        VecDateTimeInt64Union conv = {.i64 = from};
115
23.2k
        return conv.dt;
116
23.2k
    } else if constexpr (from_ui32_to_date_v2) {
117
22.4k
        DateV2UInt32Union conv = {.ui32 = from};
118
22.4k
        return conv.dt;
119
22.4k
    } else if constexpr (from_date_v2_to_ui32) {
120
22.4k
        DateV2UInt32Union conv = {.dt = from};
121
22.4k
        return conv.ui32;
122
22.4k
    } else if constexpr (from_ui64_to_datetime_v2) {
123
20.8k
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
20.8k
        return conv.dt;
125
20.8k
    } else if constexpr (from_datetime_v2_to_ui64) {
126
20.1k
        DateTimeV2UInt64Union conv = {.dt = from};
127
20.1k
        return conv.ui64;
128
20.1k
    } else if constexpr (from_vec_dt_to_i64) {
129
49
        VecDateTimeInt64Union conv = {.dt = from};
130
49
        return conv.i64;
131
49
    } else if constexpr (from_i128_to_decv2) {
132
46
        DecimalInt128Union conv;
133
46
        conv.i128 = from;
134
46
        return conv.decimal;
135
46
    } else if constexpr (from_decv2_to_i128) {
136
46
        DecimalInt128Union conv;
137
46
        conv.decimal = from;
138
46
        return conv.i128;
139
46
    } else {
140
24.0k
        LOG(FATAL) << "__builtin_unreachable";
141
24.0k
        __builtin_unreachable();
142
24.0k
    }
143
24.0k
}
Unexecuted instantiation: _ZN5doris11binary_castIdlEET0_T_
Unexecuted instantiation: _ZN5doris11binary_castIldEET0_T_
Unexecuted instantiation: _ZN5doris11binary_castImdEET0_T_
_ZN5doris11binary_castIjNS_11DateV2ValueINS_15DateV2ValueTypeEEEEET0_T_
Line
Count
Source
71
758
To binary_cast(From from) {
72
758
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
758
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
758
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
758
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
758
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
758
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
758
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
758
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
758
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
758
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
758
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
758
    constexpr bool from_ui64_to_datetime_v2 =
87
758
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
758
    constexpr bool from_datetime_v2_to_ui64 =
90
758
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
758
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
758
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
758
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
758
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
758
    if constexpr (from_u64_to_db) {
98
758
        TypeConverter conv;
99
758
        conv.u64 = from;
100
758
        return conv.dbl;
101
758
    } else if constexpr (from_i64_to_db) {
102
758
        TypeConverter conv;
103
758
        conv.i64 = from;
104
758
        return conv.dbl;
105
758
    } else if constexpr (from_db_to_i64) {
106
758
        TypeConverter conv;
107
758
        conv.dbl = from;
108
758
        return conv.i64;
109
758
    } else if constexpr (from_db_to_u64) {
110
758
        TypeConverter conv;
111
758
        conv.dbl = from;
112
758
        return conv.u64;
113
758
    } else if constexpr (from_i64_to_vec_dt) {
114
758
        VecDateTimeInt64Union conv = {.i64 = from};
115
758
        return conv.dt;
116
758
    } else if constexpr (from_ui32_to_date_v2) {
117
758
        DateV2UInt32Union conv = {.ui32 = from};
118
758
        return conv.dt;
119
758
    } else if constexpr (from_date_v2_to_ui32) {
120
758
        DateV2UInt32Union conv = {.dt = from};
121
758
        return conv.ui32;
122
758
    } else if constexpr (from_ui64_to_datetime_v2) {
123
758
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
758
        return conv.dt;
125
758
    } else if constexpr (from_datetime_v2_to_ui64) {
126
758
        DateTimeV2UInt64Union conv = {.dt = from};
127
758
        return conv.ui64;
128
758
    } else if constexpr (from_vec_dt_to_i64) {
129
758
        VecDateTimeInt64Union conv = {.dt = from};
130
758
        return conv.i64;
131
758
    } else if constexpr (from_i128_to_decv2) {
132
758
        DecimalInt128Union conv;
133
758
        conv.i128 = from;
134
758
        return conv.decimal;
135
758
    } else if constexpr (from_decv2_to_i128) {
136
758
        DecimalInt128Union conv;
137
758
        conv.decimal = from;
138
758
        return conv.i128;
139
758
    } else {
140
758
        LOG(FATAL) << "__builtin_unreachable";
141
758
        __builtin_unreachable();
142
758
    }
143
758
}
_ZN5doris11binary_castImNS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEET0_T_
Line
Count
Source
71
1.51k
To binary_cast(From from) {
72
1.51k
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
1.51k
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
1.51k
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
1.51k
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
1.51k
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
1.51k
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
1.51k
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
1.51k
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
1.51k
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
1.51k
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
1.51k
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
1.51k
    constexpr bool from_ui64_to_datetime_v2 =
87
1.51k
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
1.51k
    constexpr bool from_datetime_v2_to_ui64 =
90
1.51k
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
1.51k
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
1.51k
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
1.51k
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
1.51k
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
1.51k
    if constexpr (from_u64_to_db) {
98
1.51k
        TypeConverter conv;
99
1.51k
        conv.u64 = from;
100
1.51k
        return conv.dbl;
101
1.51k
    } else if constexpr (from_i64_to_db) {
102
1.51k
        TypeConverter conv;
103
1.51k
        conv.i64 = from;
104
1.51k
        return conv.dbl;
105
1.51k
    } else if constexpr (from_db_to_i64) {
106
1.51k
        TypeConverter conv;
107
1.51k
        conv.dbl = from;
108
1.51k
        return conv.i64;
109
1.51k
    } else if constexpr (from_db_to_u64) {
110
1.51k
        TypeConverter conv;
111
1.51k
        conv.dbl = from;
112
1.51k
        return conv.u64;
113
1.51k
    } else if constexpr (from_i64_to_vec_dt) {
114
1.51k
        VecDateTimeInt64Union conv = {.i64 = from};
115
1.51k
        return conv.dt;
116
1.51k
    } else if constexpr (from_ui32_to_date_v2) {
117
1.51k
        DateV2UInt32Union conv = {.ui32 = from};
118
1.51k
        return conv.dt;
119
1.51k
    } else if constexpr (from_date_v2_to_ui32) {
120
1.51k
        DateV2UInt32Union conv = {.dt = from};
121
1.51k
        return conv.ui32;
122
1.51k
    } else if constexpr (from_ui64_to_datetime_v2) {
123
1.51k
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
1.51k
        return conv.dt;
125
1.51k
    } else if constexpr (from_datetime_v2_to_ui64) {
126
1.51k
        DateTimeV2UInt64Union conv = {.dt = from};
127
1.51k
        return conv.ui64;
128
1.51k
    } else if constexpr (from_vec_dt_to_i64) {
129
1.51k
        VecDateTimeInt64Union conv = {.dt = from};
130
1.51k
        return conv.i64;
131
1.51k
    } else if constexpr (from_i128_to_decv2) {
132
1.51k
        DecimalInt128Union conv;
133
1.51k
        conv.i128 = from;
134
1.51k
        return conv.decimal;
135
1.51k
    } else if constexpr (from_decv2_to_i128) {
136
1.51k
        DecimalInt128Union conv;
137
1.51k
        conv.decimal = from;
138
1.51k
        return conv.i128;
139
1.51k
    } else {
140
1.51k
        LOG(FATAL) << "__builtin_unreachable";
141
1.51k
        __builtin_unreachable();
142
1.51k
    }
143
1.51k
}
_ZN5doris11binary_castIlNS_16VecDateTimeValueEEET0_T_
Line
Count
Source
71
760
To binary_cast(From from) {
72
760
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
760
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
760
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
760
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
760
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
760
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
760
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
760
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
760
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
760
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
760
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
760
    constexpr bool from_ui64_to_datetime_v2 =
87
760
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
760
    constexpr bool from_datetime_v2_to_ui64 =
90
760
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
760
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
760
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
760
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
760
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
760
    if constexpr (from_u64_to_db) {
98
760
        TypeConverter conv;
99
760
        conv.u64 = from;
100
760
        return conv.dbl;
101
760
    } else if constexpr (from_i64_to_db) {
102
760
        TypeConverter conv;
103
760
        conv.i64 = from;
104
760
        return conv.dbl;
105
760
    } else if constexpr (from_db_to_i64) {
106
760
        TypeConverter conv;
107
760
        conv.dbl = from;
108
760
        return conv.i64;
109
760
    } else if constexpr (from_db_to_u64) {
110
760
        TypeConverter conv;
111
760
        conv.dbl = from;
112
760
        return conv.u64;
113
760
    } else if constexpr (from_i64_to_vec_dt) {
114
760
        VecDateTimeInt64Union conv = {.i64 = from};
115
760
        return conv.dt;
116
760
    } else if constexpr (from_ui32_to_date_v2) {
117
760
        DateV2UInt32Union conv = {.ui32 = from};
118
760
        return conv.dt;
119
760
    } else if constexpr (from_date_v2_to_ui32) {
120
760
        DateV2UInt32Union conv = {.dt = from};
121
760
        return conv.ui32;
122
760
    } else if constexpr (from_ui64_to_datetime_v2) {
123
760
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
760
        return conv.dt;
125
760
    } else if constexpr (from_datetime_v2_to_ui64) {
126
760
        DateTimeV2UInt64Union conv = {.dt = from};
127
760
        return conv.ui64;
128
760
    } else if constexpr (from_vec_dt_to_i64) {
129
760
        VecDateTimeInt64Union conv = {.dt = from};
130
760
        return conv.i64;
131
760
    } else if constexpr (from_i128_to_decv2) {
132
760
        DecimalInt128Union conv;
133
760
        conv.i128 = from;
134
760
        return conv.decimal;
135
760
    } else if constexpr (from_decv2_to_i128) {
136
760
        DecimalInt128Union conv;
137
760
        conv.decimal = from;
138
760
        return conv.i128;
139
760
    } else {
140
760
        LOG(FATAL) << "__builtin_unreachable";
141
760
        __builtin_unreachable();
142
760
    }
143
760
}
_ZN5doris11binary_castINS_14DecimalV2ValueEnEET0_T_
Line
Count
Source
71
46
To binary_cast(From from) {
72
46
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
46
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
46
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
46
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
46
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
46
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
46
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
46
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
46
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
46
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
46
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
46
    constexpr bool from_ui64_to_datetime_v2 =
87
46
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
46
    constexpr bool from_datetime_v2_to_ui64 =
90
46
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
46
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
46
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
46
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
46
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
46
    if constexpr (from_u64_to_db) {
98
46
        TypeConverter conv;
99
46
        conv.u64 = from;
100
46
        return conv.dbl;
101
46
    } else if constexpr (from_i64_to_db) {
102
46
        TypeConverter conv;
103
46
        conv.i64 = from;
104
46
        return conv.dbl;
105
46
    } else if constexpr (from_db_to_i64) {
106
46
        TypeConverter conv;
107
46
        conv.dbl = from;
108
46
        return conv.i64;
109
46
    } else if constexpr (from_db_to_u64) {
110
46
        TypeConverter conv;
111
46
        conv.dbl = from;
112
46
        return conv.u64;
113
46
    } else if constexpr (from_i64_to_vec_dt) {
114
46
        VecDateTimeInt64Union conv = {.i64 = from};
115
46
        return conv.dt;
116
46
    } else if constexpr (from_ui32_to_date_v2) {
117
46
        DateV2UInt32Union conv = {.ui32 = from};
118
46
        return conv.dt;
119
46
    } else if constexpr (from_date_v2_to_ui32) {
120
46
        DateV2UInt32Union conv = {.dt = from};
121
46
        return conv.ui32;
122
46
    } else if constexpr (from_ui64_to_datetime_v2) {
123
46
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
46
        return conv.dt;
125
46
    } else if constexpr (from_datetime_v2_to_ui64) {
126
46
        DateTimeV2UInt64Union conv = {.dt = from};
127
46
        return conv.ui64;
128
46
    } else if constexpr (from_vec_dt_to_i64) {
129
46
        VecDateTimeInt64Union conv = {.dt = from};
130
46
        return conv.i64;
131
46
    } else if constexpr (from_i128_to_decv2) {
132
46
        DecimalInt128Union conv;
133
46
        conv.i128 = from;
134
46
        return conv.decimal;
135
46
    } else if constexpr (from_decv2_to_i128) {
136
46
        DecimalInt128Union conv;
137
46
        conv.decimal = from;
138
46
        return conv.i128;
139
46
    } else {
140
46
        LOG(FATAL) << "__builtin_unreachable";
141
46
        __builtin_unreachable();
142
46
    }
143
46
}
_ZN5doris11binary_castINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEmEET0_T_
Line
Count
Source
71
707
To binary_cast(From from) {
72
707
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
707
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
707
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
707
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
707
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
707
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
707
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
707
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
707
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
707
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
707
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
707
    constexpr bool from_ui64_to_datetime_v2 =
87
707
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
707
    constexpr bool from_datetime_v2_to_ui64 =
90
707
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
707
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
707
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
707
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
707
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
707
    if constexpr (from_u64_to_db) {
98
707
        TypeConverter conv;
99
707
        conv.u64 = from;
100
707
        return conv.dbl;
101
707
    } else if constexpr (from_i64_to_db) {
102
707
        TypeConverter conv;
103
707
        conv.i64 = from;
104
707
        return conv.dbl;
105
707
    } else if constexpr (from_db_to_i64) {
106
707
        TypeConverter conv;
107
707
        conv.dbl = from;
108
707
        return conv.i64;
109
707
    } else if constexpr (from_db_to_u64) {
110
707
        TypeConverter conv;
111
707
        conv.dbl = from;
112
707
        return conv.u64;
113
707
    } else if constexpr (from_i64_to_vec_dt) {
114
707
        VecDateTimeInt64Union conv = {.i64 = from};
115
707
        return conv.dt;
116
707
    } else if constexpr (from_ui32_to_date_v2) {
117
707
        DateV2UInt32Union conv = {.ui32 = from};
118
707
        return conv.dt;
119
707
    } else if constexpr (from_date_v2_to_ui32) {
120
707
        DateV2UInt32Union conv = {.dt = from};
121
707
        return conv.ui32;
122
707
    } else if constexpr (from_ui64_to_datetime_v2) {
123
707
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
707
        return conv.dt;
125
707
    } else if constexpr (from_datetime_v2_to_ui64) {
126
707
        DateTimeV2UInt64Union conv = {.dt = from};
127
707
        return conv.ui64;
128
707
    } else if constexpr (from_vec_dt_to_i64) {
129
707
        VecDateTimeInt64Union conv = {.dt = from};
130
707
        return conv.i64;
131
707
    } else if constexpr (from_i128_to_decv2) {
132
707
        DecimalInt128Union conv;
133
707
        conv.i128 = from;
134
707
        return conv.decimal;
135
707
    } else if constexpr (from_decv2_to_i128) {
136
707
        DecimalInt128Union conv;
137
707
        conv.decimal = from;
138
707
        return conv.i128;
139
707
    } else {
140
707
        LOG(FATAL) << "__builtin_unreachable";
141
707
        __builtin_unreachable();
142
707
    }
143
707
}
_ZN5doris11binary_castINS_16VecDateTimeValueElEET0_T_
Line
Count
Source
71
20.1k
To binary_cast(From from) {
72
20.1k
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
20.1k
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
20.1k
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
20.1k
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
20.1k
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
20.1k
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
20.1k
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
20.1k
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
20.1k
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
20.1k
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
20.1k
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
20.1k
    constexpr bool from_ui64_to_datetime_v2 =
87
20.1k
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
20.1k
    constexpr bool from_datetime_v2_to_ui64 =
90
20.1k
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
20.1k
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
20.1k
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
20.1k
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
20.1k
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
20.1k
    if constexpr (from_u64_to_db) {
98
20.1k
        TypeConverter conv;
99
20.1k
        conv.u64 = from;
100
20.1k
        return conv.dbl;
101
20.1k
    } else if constexpr (from_i64_to_db) {
102
20.1k
        TypeConverter conv;
103
20.1k
        conv.i64 = from;
104
20.1k
        return conv.dbl;
105
20.1k
    } else if constexpr (from_db_to_i64) {
106
20.1k
        TypeConverter conv;
107
20.1k
        conv.dbl = from;
108
20.1k
        return conv.i64;
109
20.1k
    } else if constexpr (from_db_to_u64) {
110
20.1k
        TypeConverter conv;
111
20.1k
        conv.dbl = from;
112
20.1k
        return conv.u64;
113
20.1k
    } else if constexpr (from_i64_to_vec_dt) {
114
20.1k
        VecDateTimeInt64Union conv = {.i64 = from};
115
20.1k
        return conv.dt;
116
20.1k
    } else if constexpr (from_ui32_to_date_v2) {
117
20.1k
        DateV2UInt32Union conv = {.ui32 = from};
118
20.1k
        return conv.dt;
119
20.1k
    } else if constexpr (from_date_v2_to_ui32) {
120
20.1k
        DateV2UInt32Union conv = {.dt = from};
121
20.1k
        return conv.ui32;
122
20.1k
    } else if constexpr (from_ui64_to_datetime_v2) {
123
20.1k
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
20.1k
        return conv.dt;
125
20.1k
    } else if constexpr (from_datetime_v2_to_ui64) {
126
20.1k
        DateTimeV2UInt64Union conv = {.dt = from};
127
20.1k
        return conv.ui64;
128
20.1k
    } else if constexpr (from_vec_dt_to_i64) {
129
20.1k
        VecDateTimeInt64Union conv = {.dt = from};
130
20.1k
        return conv.i64;
131
20.1k
    } else if constexpr (from_i128_to_decv2) {
132
20.1k
        DecimalInt128Union conv;
133
20.1k
        conv.i128 = from;
134
20.1k
        return conv.decimal;
135
20.1k
    } else if constexpr (from_decv2_to_i128) {
136
20.1k
        DecimalInt128Union conv;
137
20.1k
        conv.decimal = from;
138
20.1k
        return conv.i128;
139
20.1k
    } else {
140
20.1k
        LOG(FATAL) << "__builtin_unreachable";
141
20.1k
        __builtin_unreachable();
142
20.1k
    }
143
20.1k
}
_ZN5doris11binary_castINS_11DateV2ValueINS_15DateV2ValueTypeEEEjEET0_T_
Line
Count
Source
71
87
To binary_cast(From from) {
72
87
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
87
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
87
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
87
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
87
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
87
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
87
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
87
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
87
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
87
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
87
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
87
    constexpr bool from_ui64_to_datetime_v2 =
87
87
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
87
    constexpr bool from_datetime_v2_to_ui64 =
90
87
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
87
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
87
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
87
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
87
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
87
    if constexpr (from_u64_to_db) {
98
87
        TypeConverter conv;
99
87
        conv.u64 = from;
100
87
        return conv.dbl;
101
87
    } else if constexpr (from_i64_to_db) {
102
87
        TypeConverter conv;
103
87
        conv.i64 = from;
104
87
        return conv.dbl;
105
87
    } else if constexpr (from_db_to_i64) {
106
87
        TypeConverter conv;
107
87
        conv.dbl = from;
108
87
        return conv.i64;
109
87
    } else if constexpr (from_db_to_u64) {
110
87
        TypeConverter conv;
111
87
        conv.dbl = from;
112
87
        return conv.u64;
113
87
    } else if constexpr (from_i64_to_vec_dt) {
114
87
        VecDateTimeInt64Union conv = {.i64 = from};
115
87
        return conv.dt;
116
87
    } else if constexpr (from_ui32_to_date_v2) {
117
87
        DateV2UInt32Union conv = {.ui32 = from};
118
87
        return conv.dt;
119
87
    } else if constexpr (from_date_v2_to_ui32) {
120
87
        DateV2UInt32Union conv = {.dt = from};
121
87
        return conv.ui32;
122
87
    } else if constexpr (from_ui64_to_datetime_v2) {
123
87
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
87
        return conv.dt;
125
87
    } else if constexpr (from_datetime_v2_to_ui64) {
126
87
        DateTimeV2UInt64Union conv = {.dt = from};
127
87
        return conv.ui64;
128
87
    } else if constexpr (from_vec_dt_to_i64) {
129
87
        VecDateTimeInt64Union conv = {.dt = from};
130
87
        return conv.i64;
131
87
    } else if constexpr (from_i128_to_decv2) {
132
87
        DecimalInt128Union conv;
133
87
        conv.i128 = from;
134
87
        return conv.decimal;
135
87
    } else if constexpr (from_decv2_to_i128) {
136
87
        DecimalInt128Union conv;
137
87
        conv.decimal = from;
138
87
        return conv.i128;
139
87
    } else {
140
87
        LOG(FATAL) << "__builtin_unreachable";
141
87
        __builtin_unreachable();
142
87
    }
143
87
}
_ZN5doris11binary_castInNS_14DecimalV2ValueEEET0_T_
Line
Count
Source
71
3
To binary_cast(From from) {
72
3
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
3
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
3
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
3
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
3
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
3
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
3
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
3
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
3
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
3
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
3
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
3
    constexpr bool from_ui64_to_datetime_v2 =
87
3
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
3
    constexpr bool from_datetime_v2_to_ui64 =
90
3
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
3
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
3
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
3
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
3
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
3
    if constexpr (from_u64_to_db) {
98
3
        TypeConverter conv;
99
3
        conv.u64 = from;
100
3
        return conv.dbl;
101
3
    } else if constexpr (from_i64_to_db) {
102
3
        TypeConverter conv;
103
3
        conv.i64 = from;
104
3
        return conv.dbl;
105
3
    } else if constexpr (from_db_to_i64) {
106
3
        TypeConverter conv;
107
3
        conv.dbl = from;
108
3
        return conv.i64;
109
3
    } else if constexpr (from_db_to_u64) {
110
3
        TypeConverter conv;
111
3
        conv.dbl = from;
112
3
        return conv.u64;
113
3
    } else if constexpr (from_i64_to_vec_dt) {
114
3
        VecDateTimeInt64Union conv = {.i64 = from};
115
3
        return conv.dt;
116
3
    } else if constexpr (from_ui32_to_date_v2) {
117
3
        DateV2UInt32Union conv = {.ui32 = from};
118
3
        return conv.dt;
119
3
    } else if constexpr (from_date_v2_to_ui32) {
120
3
        DateV2UInt32Union conv = {.dt = from};
121
3
        return conv.ui32;
122
3
    } else if constexpr (from_ui64_to_datetime_v2) {
123
3
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
3
        return conv.dt;
125
3
    } else if constexpr (from_datetime_v2_to_ui64) {
126
3
        DateTimeV2UInt64Union conv = {.dt = from};
127
3
        return conv.ui64;
128
3
    } else if constexpr (from_vec_dt_to_i64) {
129
3
        VecDateTimeInt64Union conv = {.dt = from};
130
3
        return conv.i64;
131
3
    } else if constexpr (from_i128_to_decv2) {
132
3
        DecimalInt128Union conv;
133
3
        conv.i128 = from;
134
3
        return conv.decimal;
135
3
    } else if constexpr (from_decv2_to_i128) {
136
3
        DecimalInt128Union conv;
137
3
        conv.decimal = from;
138
3
        return conv.i128;
139
3
    } else {
140
3
        LOG(FATAL) << "__builtin_unreachable";
141
3
        __builtin_unreachable();
142
3
    }
143
3
}
144
145
} // namespace doris