Coverage Report

Created: 2025-05-21 20:37

/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.9k
    ~VecDateTimeInt64Union() {}
55
};
56
57
union DateV2UInt32Union {
58
    DateV2Value<DateV2ValueType> dt;
59
    uint32_t ui32;
60
1.29k
    ~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.4k
To binary_cast(From from) {
72
24.4k
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
24.4k
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
24.4k
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
24.4k
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
24.4k
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
24.4k
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
24.4k
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
24.4k
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
24.4k
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
24.4k
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
24.4k
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
24.4k
    constexpr bool from_ui64_to_datetime_v2 =
87
24.4k
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
24.4k
    constexpr bool from_datetime_v2_to_ui64 =
90
24.4k
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
24.4k
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
24.4k
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
24.4k
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
24.4k
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
24.4k
    if constexpr (from_u64_to_db) {
98
24.4k
        TypeConverter conv;
99
24.4k
        conv.u64 = from;
100
24.4k
        return conv.dbl;
101
24.4k
    } else if constexpr (from_i64_to_db) {
102
24.4k
        TypeConverter conv;
103
24.4k
        conv.i64 = from;
104
24.4k
        return conv.dbl;
105
24.4k
    } else if constexpr (from_db_to_i64) {
106
24.4k
        TypeConverter conv;
107
24.4k
        conv.dbl = from;
108
24.4k
        return conv.i64;
109
24.4k
    } else if constexpr (from_db_to_u64) {
110
24.4k
        TypeConverter conv;
111
24.4k
        conv.dbl = from;
112
24.4k
        return conv.u64;
113
24.4k
    } else if constexpr (from_i64_to_vec_dt) {
114
23.7k
        VecDateTimeInt64Union conv = {.i64 = from};
115
23.7k
        return conv.dt;
116
23.7k
    } else if constexpr (from_ui32_to_date_v2) {
117
22.6k
        DateV2UInt32Union conv = {.ui32 = from};
118
22.6k
        return conv.dt;
119
22.6k
    } 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
48
        VecDateTimeInt64Union conv = {.dt = from};
130
48
        return conv.i64;
131
48
    } else if constexpr (from_i128_to_decv2) {
132
48
        DecimalInt128Union conv;
133
48
        conv.i128 = from;
134
48
        return conv.decimal;
135
48
    } else if constexpr (from_decv2_to_i128) {
136
48
        DecimalInt128Union conv;
137
48
        conv.decimal = from;
138
48
        return conv.i128;
139
48
    } else {
140
24.4k
        LOG(FATAL) << "__builtin_unreachable";
141
24.4k
        __builtin_unreachable();
142
24.4k
    }
143
24.4k
}
Unexecuted instantiation: _ZN5doris11binary_castIdlEET0_T_
Unexecuted instantiation: _ZN5doris11binary_castIldEET0_T_
Unexecuted instantiation: _ZN5doris11binary_castImdEET0_T_
_ZN5doris11binary_castIjNS_11DateV2ValueINS_15DateV2ValueTypeEEEEET0_T_
Line
Count
Source
71
1.05k
To binary_cast(From from) {
72
1.05k
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
1.05k
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
1.05k
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
1.05k
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
1.05k
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
1.05k
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
1.05k
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
1.05k
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
1.05k
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
1.05k
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
1.05k
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
1.05k
    constexpr bool from_ui64_to_datetime_v2 =
87
1.05k
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
1.05k
    constexpr bool from_datetime_v2_to_ui64 =
90
1.05k
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
1.05k
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
1.05k
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
1.05k
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
1.05k
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
1.05k
    if constexpr (from_u64_to_db) {
98
1.05k
        TypeConverter conv;
99
1.05k
        conv.u64 = from;
100
1.05k
        return conv.dbl;
101
1.05k
    } else if constexpr (from_i64_to_db) {
102
1.05k
        TypeConverter conv;
103
1.05k
        conv.i64 = from;
104
1.05k
        return conv.dbl;
105
1.05k
    } else if constexpr (from_db_to_i64) {
106
1.05k
        TypeConverter conv;
107
1.05k
        conv.dbl = from;
108
1.05k
        return conv.i64;
109
1.05k
    } else if constexpr (from_db_to_u64) {
110
1.05k
        TypeConverter conv;
111
1.05k
        conv.dbl = from;
112
1.05k
        return conv.u64;
113
1.05k
    } else if constexpr (from_i64_to_vec_dt) {
114
1.05k
        VecDateTimeInt64Union conv = {.i64 = from};
115
1.05k
        return conv.dt;
116
1.05k
    } else if constexpr (from_ui32_to_date_v2) {
117
1.05k
        DateV2UInt32Union conv = {.ui32 = from};
118
1.05k
        return conv.dt;
119
1.05k
    } else if constexpr (from_date_v2_to_ui32) {
120
1.05k
        DateV2UInt32Union conv = {.dt = from};
121
1.05k
        return conv.ui32;
122
1.05k
    } else if constexpr (from_ui64_to_datetime_v2) {
123
1.05k
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
1.05k
        return conv.dt;
125
1.05k
    } else if constexpr (from_datetime_v2_to_ui64) {
126
1.05k
        DateTimeV2UInt64Union conv = {.dt = from};
127
1.05k
        return conv.ui64;
128
1.05k
    } else if constexpr (from_vec_dt_to_i64) {
129
1.05k
        VecDateTimeInt64Union conv = {.dt = from};
130
1.05k
        return conv.i64;
131
1.05k
    } else if constexpr (from_i128_to_decv2) {
132
1.05k
        DecimalInt128Union conv;
133
1.05k
        conv.i128 = from;
134
1.05k
        return conv.decimal;
135
1.05k
    } else if constexpr (from_decv2_to_i128) {
136
1.05k
        DecimalInt128Union conv;
137
1.05k
        conv.decimal = from;
138
1.05k
        return conv.i128;
139
1.05k
    } else {
140
1.05k
        LOG(FATAL) << "__builtin_unreachable";
141
1.05k
        __builtin_unreachable();
142
1.05k
    }
143
1.05k
}
_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
762
To binary_cast(From from) {
72
762
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
762
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
762
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
762
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
762
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
762
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
762
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
762
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
762
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
762
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
762
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
762
    constexpr bool from_ui64_to_datetime_v2 =
87
762
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
762
    constexpr bool from_datetime_v2_to_ui64 =
90
762
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
762
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
762
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
762
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
762
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
762
    if constexpr (from_u64_to_db) {
98
762
        TypeConverter conv;
99
762
        conv.u64 = from;
100
762
        return conv.dbl;
101
762
    } else if constexpr (from_i64_to_db) {
102
762
        TypeConverter conv;
103
762
        conv.i64 = from;
104
762
        return conv.dbl;
105
762
    } else if constexpr (from_db_to_i64) {
106
762
        TypeConverter conv;
107
762
        conv.dbl = from;
108
762
        return conv.i64;
109
762
    } else if constexpr (from_db_to_u64) {
110
762
        TypeConverter conv;
111
762
        conv.dbl = from;
112
762
        return conv.u64;
113
762
    } else if constexpr (from_i64_to_vec_dt) {
114
762
        VecDateTimeInt64Union conv = {.i64 = from};
115
762
        return conv.dt;
116
762
    } else if constexpr (from_ui32_to_date_v2) {
117
762
        DateV2UInt32Union conv = {.ui32 = from};
118
762
        return conv.dt;
119
762
    } else if constexpr (from_date_v2_to_ui32) {
120
762
        DateV2UInt32Union conv = {.dt = from};
121
762
        return conv.ui32;
122
762
    } else if constexpr (from_ui64_to_datetime_v2) {
123
762
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
762
        return conv.dt;
125
762
    } else if constexpr (from_datetime_v2_to_ui64) {
126
762
        DateTimeV2UInt64Union conv = {.dt = from};
127
762
        return conv.ui64;
128
762
    } else if constexpr (from_vec_dt_to_i64) {
129
762
        VecDateTimeInt64Union conv = {.dt = from};
130
762
        return conv.i64;
131
762
    } else if constexpr (from_i128_to_decv2) {
132
762
        DecimalInt128Union conv;
133
762
        conv.i128 = from;
134
762
        return conv.decimal;
135
762
    } else if constexpr (from_decv2_to_i128) {
136
762
        DecimalInt128Union conv;
137
762
        conv.decimal = from;
138
762
        return conv.i128;
139
762
    } else {
140
762
        LOG(FATAL) << "__builtin_unreachable";
141
762
        __builtin_unreachable();
142
762
    }
143
762
}
Unexecuted instantiation: _ZN5doris11binary_castInNS_14DecimalV2ValueEEET0_T_
_ZN5doris11binary_castINS_14DecimalV2ValueEnEET0_T_
Line
Count
Source
71
48
To binary_cast(From from) {
72
48
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
48
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
48
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
48
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
48
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
48
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
48
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
48
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
48
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
48
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
48
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
48
    constexpr bool from_ui64_to_datetime_v2 =
87
48
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
48
    constexpr bool from_datetime_v2_to_ui64 =
90
48
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
48
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
48
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
48
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
48
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
48
    if constexpr (from_u64_to_db) {
98
48
        TypeConverter conv;
99
48
        conv.u64 = from;
100
48
        return conv.dbl;
101
48
    } else if constexpr (from_i64_to_db) {
102
48
        TypeConverter conv;
103
48
        conv.i64 = from;
104
48
        return conv.dbl;
105
48
    } else if constexpr (from_db_to_i64) {
106
48
        TypeConverter conv;
107
48
        conv.dbl = from;
108
48
        return conv.i64;
109
48
    } else if constexpr (from_db_to_u64) {
110
48
        TypeConverter conv;
111
48
        conv.dbl = from;
112
48
        return conv.u64;
113
48
    } else if constexpr (from_i64_to_vec_dt) {
114
48
        VecDateTimeInt64Union conv = {.i64 = from};
115
48
        return conv.dt;
116
48
    } else if constexpr (from_ui32_to_date_v2) {
117
48
        DateV2UInt32Union conv = {.ui32 = from};
118
48
        return conv.dt;
119
48
    } else if constexpr (from_date_v2_to_ui32) {
120
48
        DateV2UInt32Union conv = {.dt = from};
121
48
        return conv.ui32;
122
48
    } else if constexpr (from_ui64_to_datetime_v2) {
123
48
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
48
        return conv.dt;
125
48
    } else if constexpr (from_datetime_v2_to_ui64) {
126
48
        DateTimeV2UInt64Union conv = {.dt = from};
127
48
        return conv.ui64;
128
48
    } else if constexpr (from_vec_dt_to_i64) {
129
48
        VecDateTimeInt64Union conv = {.dt = from};
130
48
        return conv.i64;
131
48
    } else if constexpr (from_i128_to_decv2) {
132
48
        DecimalInt128Union conv;
133
48
        conv.i128 = from;
134
48
        return conv.decimal;
135
48
    } else if constexpr (from_decv2_to_i128) {
136
48
        DecimalInt128Union conv;
137
48
        conv.decimal = from;
138
48
        return conv.i128;
139
48
    } else {
140
48
        LOG(FATAL) << "__builtin_unreachable";
141
48
        __builtin_unreachable();
142
48
    }
143
48
}
_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
244
To binary_cast(From from) {
72
244
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
244
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
244
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
244
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
244
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
244
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
244
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
244
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
244
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
244
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
244
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
244
    constexpr bool from_ui64_to_datetime_v2 =
87
244
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
244
    constexpr bool from_datetime_v2_to_ui64 =
90
244
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
244
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
244
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
244
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
244
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
244
    if constexpr (from_u64_to_db) {
98
244
        TypeConverter conv;
99
244
        conv.u64 = from;
100
244
        return conv.dbl;
101
244
    } else if constexpr (from_i64_to_db) {
102
244
        TypeConverter conv;
103
244
        conv.i64 = from;
104
244
        return conv.dbl;
105
244
    } else if constexpr (from_db_to_i64) {
106
244
        TypeConverter conv;
107
244
        conv.dbl = from;
108
244
        return conv.i64;
109
244
    } else if constexpr (from_db_to_u64) {
110
244
        TypeConverter conv;
111
244
        conv.dbl = from;
112
244
        return conv.u64;
113
244
    } else if constexpr (from_i64_to_vec_dt) {
114
244
        VecDateTimeInt64Union conv = {.i64 = from};
115
244
        return conv.dt;
116
244
    } else if constexpr (from_ui32_to_date_v2) {
117
244
        DateV2UInt32Union conv = {.ui32 = from};
118
244
        return conv.dt;
119
244
    } else if constexpr (from_date_v2_to_ui32) {
120
244
        DateV2UInt32Union conv = {.dt = from};
121
244
        return conv.ui32;
122
244
    } else if constexpr (from_ui64_to_datetime_v2) {
123
244
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
244
        return conv.dt;
125
244
    } else if constexpr (from_datetime_v2_to_ui64) {
126
244
        DateTimeV2UInt64Union conv = {.dt = from};
127
244
        return conv.ui64;
128
244
    } else if constexpr (from_vec_dt_to_i64) {
129
244
        VecDateTimeInt64Union conv = {.dt = from};
130
244
        return conv.i64;
131
244
    } else if constexpr (from_i128_to_decv2) {
132
244
        DecimalInt128Union conv;
133
244
        conv.i128 = from;
134
244
        return conv.decimal;
135
244
    } else if constexpr (from_decv2_to_i128) {
136
244
        DecimalInt128Union conv;
137
244
        conv.decimal = from;
138
244
        return conv.i128;
139
244
    } else {
140
244
        LOG(FATAL) << "__builtin_unreachable";
141
244
        __builtin_unreachable();
142
244
    }
143
244
}
144
145
} // namespace doris