Coverage Report

Created: 2025-04-27 14:25

/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.7k
    ~VecDateTimeInt64Union() {}
55
};
56
57
union DateV2UInt32Union {
58
    DateV2Value<DateV2ValueType> dt;
59
    uint32_t ui32;
60
752
    ~DateV2UInt32Union() {}
61
};
62
63
union DateTimeV2UInt64Union {
64
    DateV2Value<DateTimeV2ValueType> dt;
65
    uint64_t ui64;
66
2.12k
    ~DateTimeV2UInt64Union() {}
67
};
68
69
// similar to reinterpret_cast but won't break strict-aliasing rules
70
template <typename From, typename To>
71
23.6k
To binary_cast(From from) {
72
23.6k
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
23.6k
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
23.6k
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
23.6k
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
23.6k
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
23.6k
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
23.6k
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
23.6k
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
23.6k
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
23.6k
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
23.6k
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
23.6k
    constexpr bool from_ui64_to_datetime_v2 =
87
23.6k
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
23.6k
    constexpr bool from_datetime_v2_to_ui64 =
90
23.6k
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
23.6k
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
23.6k
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
23.6k
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
23.6k
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
23.6k
    if constexpr (from_u64_to_db) {
98
23.6k
        TypeConverter conv;
99
23.6k
        conv.u64 = from;
100
23.6k
        return conv.dbl;
101
23.6k
    } else if constexpr (from_i64_to_db) {
102
23.6k
        TypeConverter conv;
103
23.6k
        conv.i64 = from;
104
23.6k
        return conv.dbl;
105
23.6k
    } else if constexpr (from_db_to_i64) {
106
23.6k
        TypeConverter conv;
107
23.6k
        conv.dbl = from;
108
23.6k
        return conv.i64;
109
23.6k
    } else if constexpr (from_db_to_u64) {
110
23.6k
        TypeConverter conv;
111
23.6k
        conv.dbl = from;
112
23.6k
        return conv.u64;
113
23.6k
    } else if constexpr (from_i64_to_vec_dt) {
114
23.0k
        VecDateTimeInt64Union conv = {.i64 = from};
115
23.0k
        return conv.dt;
116
23.0k
    } else if constexpr (from_ui32_to_date_v2) {
117
22.3k
        DateV2UInt32Union conv = {.ui32 = from};
118
22.3k
        return conv.dt;
119
22.3k
    } else if constexpr (from_date_v2_to_ui32) {
120
22.2k
        DateV2UInt32Union conv = {.dt = from};
121
22.2k
        return conv.ui32;
122
22.2k
    } 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
42
        VecDateTimeInt64Union conv = {.dt = from};
130
42
        return conv.i64;
131
42
    } else if constexpr (from_i128_to_decv2) {
132
42
        DecimalInt128Union conv;
133
42
        conv.i128 = from;
134
42
        return conv.decimal;
135
42
    } else if constexpr (from_decv2_to_i128) {
136
42
        DecimalInt128Union conv;
137
42
        conv.decimal = from;
138
42
        return conv.i128;
139
42
    } else {
140
23.6k
        LOG(FATAL) << "__builtin_unreachable";
141
23.6k
        __builtin_unreachable();
142
23.6k
    }
143
23.6k
}
Unexecuted instantiation: _ZN5doris11binary_castIdlEET0_T_
Unexecuted instantiation: _ZN5doris11binary_castIldEET0_T_
Unexecuted instantiation: _ZN5doris11binary_castImdEET0_T_
_ZN5doris11binary_castIjNS_11DateV2ValueINS_15DateV2ValueTypeEEEEET0_T_
Line
Count
Source
71
679
To binary_cast(From from) {
72
679
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
679
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
679
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
679
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
679
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
679
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
679
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
679
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
679
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
679
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
679
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
679
    constexpr bool from_ui64_to_datetime_v2 =
87
679
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
679
    constexpr bool from_datetime_v2_to_ui64 =
90
679
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
679
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
679
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
679
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
679
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
679
    if constexpr (from_u64_to_db) {
98
679
        TypeConverter conv;
99
679
        conv.u64 = from;
100
679
        return conv.dbl;
101
679
    } else if constexpr (from_i64_to_db) {
102
679
        TypeConverter conv;
103
679
        conv.i64 = from;
104
679
        return conv.dbl;
105
679
    } else if constexpr (from_db_to_i64) {
106
679
        TypeConverter conv;
107
679
        conv.dbl = from;
108
679
        return conv.i64;
109
679
    } else if constexpr (from_db_to_u64) {
110
679
        TypeConverter conv;
111
679
        conv.dbl = from;
112
679
        return conv.u64;
113
679
    } else if constexpr (from_i64_to_vec_dt) {
114
679
        VecDateTimeInt64Union conv = {.i64 = from};
115
679
        return conv.dt;
116
679
    } else if constexpr (from_ui32_to_date_v2) {
117
679
        DateV2UInt32Union conv = {.ui32 = from};
118
679
        return conv.dt;
119
679
    } else if constexpr (from_date_v2_to_ui32) {
120
679
        DateV2UInt32Union conv = {.dt = from};
121
679
        return conv.ui32;
122
679
    } else if constexpr (from_ui64_to_datetime_v2) {
123
679
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
679
        return conv.dt;
125
679
    } else if constexpr (from_datetime_v2_to_ui64) {
126
679
        DateTimeV2UInt64Union conv = {.dt = from};
127
679
        return conv.ui64;
128
679
    } else if constexpr (from_vec_dt_to_i64) {
129
679
        VecDateTimeInt64Union conv = {.dt = from};
130
679
        return conv.i64;
131
679
    } else if constexpr (from_i128_to_decv2) {
132
679
        DecimalInt128Union conv;
133
679
        conv.i128 = from;
134
679
        return conv.decimal;
135
679
    } else if constexpr (from_decv2_to_i128) {
136
679
        DecimalInt128Union conv;
137
679
        conv.decimal = from;
138
679
        return conv.i128;
139
679
    } else {
140
679
        LOG(FATAL) << "__builtin_unreachable";
141
679
        __builtin_unreachable();
142
679
    }
143
679
}
_ZN5doris11binary_castImNS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEET0_T_
Line
Count
Source
71
1.43k
To binary_cast(From from) {
72
1.43k
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
1.43k
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
1.43k
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
1.43k
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
1.43k
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
1.43k
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
1.43k
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
1.43k
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
1.43k
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
1.43k
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
1.43k
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
1.43k
    constexpr bool from_ui64_to_datetime_v2 =
87
1.43k
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
1.43k
    constexpr bool from_datetime_v2_to_ui64 =
90
1.43k
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
1.43k
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
1.43k
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
1.43k
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
1.43k
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
1.43k
    if constexpr (from_u64_to_db) {
98
1.43k
        TypeConverter conv;
99
1.43k
        conv.u64 = from;
100
1.43k
        return conv.dbl;
101
1.43k
    } else if constexpr (from_i64_to_db) {
102
1.43k
        TypeConverter conv;
103
1.43k
        conv.i64 = from;
104
1.43k
        return conv.dbl;
105
1.43k
    } else if constexpr (from_db_to_i64) {
106
1.43k
        TypeConverter conv;
107
1.43k
        conv.dbl = from;
108
1.43k
        return conv.i64;
109
1.43k
    } else if constexpr (from_db_to_u64) {
110
1.43k
        TypeConverter conv;
111
1.43k
        conv.dbl = from;
112
1.43k
        return conv.u64;
113
1.43k
    } else if constexpr (from_i64_to_vec_dt) {
114
1.43k
        VecDateTimeInt64Union conv = {.i64 = from};
115
1.43k
        return conv.dt;
116
1.43k
    } else if constexpr (from_ui32_to_date_v2) {
117
1.43k
        DateV2UInt32Union conv = {.ui32 = from};
118
1.43k
        return conv.dt;
119
1.43k
    } else if constexpr (from_date_v2_to_ui32) {
120
1.43k
        DateV2UInt32Union conv = {.dt = from};
121
1.43k
        return conv.ui32;
122
1.43k
    } else if constexpr (from_ui64_to_datetime_v2) {
123
1.43k
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
1.43k
        return conv.dt;
125
1.43k
    } else if constexpr (from_datetime_v2_to_ui64) {
126
1.43k
        DateTimeV2UInt64Union conv = {.dt = from};
127
1.43k
        return conv.ui64;
128
1.43k
    } else if constexpr (from_vec_dt_to_i64) {
129
1.43k
        VecDateTimeInt64Union conv = {.dt = from};
130
1.43k
        return conv.i64;
131
1.43k
    } else if constexpr (from_i128_to_decv2) {
132
1.43k
        DecimalInt128Union conv;
133
1.43k
        conv.i128 = from;
134
1.43k
        return conv.decimal;
135
1.43k
    } else if constexpr (from_decv2_to_i128) {
136
1.43k
        DecimalInt128Union conv;
137
1.43k
        conv.decimal = from;
138
1.43k
        return conv.i128;
139
1.43k
    } else {
140
1.43k
        LOG(FATAL) << "__builtin_unreachable";
141
1.43k
        __builtin_unreachable();
142
1.43k
    }
143
1.43k
}
_ZN5doris11binary_castIlNS_16VecDateTimeValueEEET0_T_
Line
Count
Source
71
626
To binary_cast(From from) {
72
626
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
626
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
626
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
626
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
626
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
626
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
626
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
626
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
626
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
626
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
626
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
626
    constexpr bool from_ui64_to_datetime_v2 =
87
626
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
626
    constexpr bool from_datetime_v2_to_ui64 =
90
626
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
626
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
626
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
626
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
626
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
626
    if constexpr (from_u64_to_db) {
98
626
        TypeConverter conv;
99
626
        conv.u64 = from;
100
626
        return conv.dbl;
101
626
    } else if constexpr (from_i64_to_db) {
102
626
        TypeConverter conv;
103
626
        conv.i64 = from;
104
626
        return conv.dbl;
105
626
    } else if constexpr (from_db_to_i64) {
106
626
        TypeConverter conv;
107
626
        conv.dbl = from;
108
626
        return conv.i64;
109
626
    } else if constexpr (from_db_to_u64) {
110
626
        TypeConverter conv;
111
626
        conv.dbl = from;
112
626
        return conv.u64;
113
626
    } else if constexpr (from_i64_to_vec_dt) {
114
626
        VecDateTimeInt64Union conv = {.i64 = from};
115
626
        return conv.dt;
116
626
    } else if constexpr (from_ui32_to_date_v2) {
117
626
        DateV2UInt32Union conv = {.ui32 = from};
118
626
        return conv.dt;
119
626
    } else if constexpr (from_date_v2_to_ui32) {
120
626
        DateV2UInt32Union conv = {.dt = from};
121
626
        return conv.ui32;
122
626
    } else if constexpr (from_ui64_to_datetime_v2) {
123
626
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
626
        return conv.dt;
125
626
    } else if constexpr (from_datetime_v2_to_ui64) {
126
626
        DateTimeV2UInt64Union conv = {.dt = from};
127
626
        return conv.ui64;
128
626
    } else if constexpr (from_vec_dt_to_i64) {
129
626
        VecDateTimeInt64Union conv = {.dt = from};
130
626
        return conv.i64;
131
626
    } else if constexpr (from_i128_to_decv2) {
132
626
        DecimalInt128Union conv;
133
626
        conv.i128 = from;
134
626
        return conv.decimal;
135
626
    } else if constexpr (from_decv2_to_i128) {
136
626
        DecimalInt128Union conv;
137
626
        conv.decimal = from;
138
626
        return conv.i128;
139
626
    } else {
140
626
        LOG(FATAL) << "__builtin_unreachable";
141
626
        __builtin_unreachable();
142
626
    }
143
626
}
Unexecuted instantiation: _ZN5doris11binary_castInNS_14DecimalV2ValueEEET0_T_
_ZN5doris11binary_castINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEmEET0_T_
Line
Count
Source
71
693
To binary_cast(From from) {
72
693
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
693
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
693
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
693
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
693
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
693
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
693
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
693
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
693
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
693
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
693
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
693
    constexpr bool from_ui64_to_datetime_v2 =
87
693
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
693
    constexpr bool from_datetime_v2_to_ui64 =
90
693
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
693
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
693
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
693
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
693
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
693
    if constexpr (from_u64_to_db) {
98
693
        TypeConverter conv;
99
693
        conv.u64 = from;
100
693
        return conv.dbl;
101
693
    } else if constexpr (from_i64_to_db) {
102
693
        TypeConverter conv;
103
693
        conv.i64 = from;
104
693
        return conv.dbl;
105
693
    } else if constexpr (from_db_to_i64) {
106
693
        TypeConverter conv;
107
693
        conv.dbl = from;
108
693
        return conv.i64;
109
693
    } else if constexpr (from_db_to_u64) {
110
693
        TypeConverter conv;
111
693
        conv.dbl = from;
112
693
        return conv.u64;
113
693
    } else if constexpr (from_i64_to_vec_dt) {
114
693
        VecDateTimeInt64Union conv = {.i64 = from};
115
693
        return conv.dt;
116
693
    } else if constexpr (from_ui32_to_date_v2) {
117
693
        DateV2UInt32Union conv = {.ui32 = from};
118
693
        return conv.dt;
119
693
    } else if constexpr (from_date_v2_to_ui32) {
120
693
        DateV2UInt32Union conv = {.dt = from};
121
693
        return conv.ui32;
122
693
    } else if constexpr (from_ui64_to_datetime_v2) {
123
693
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
693
        return conv.dt;
125
693
    } else if constexpr (from_datetime_v2_to_ui64) {
126
693
        DateTimeV2UInt64Union conv = {.dt = from};
127
693
        return conv.ui64;
128
693
    } else if constexpr (from_vec_dt_to_i64) {
129
693
        VecDateTimeInt64Union conv = {.dt = from};
130
693
        return conv.i64;
131
693
    } else if constexpr (from_i128_to_decv2) {
132
693
        DecimalInt128Union conv;
133
693
        conv.i128 = from;
134
693
        return conv.decimal;
135
693
    } else if constexpr (from_decv2_to_i128) {
136
693
        DecimalInt128Union conv;
137
693
        conv.decimal = from;
138
693
        return conv.i128;
139
693
    } else {
140
693
        LOG(FATAL) << "__builtin_unreachable";
141
693
        __builtin_unreachable();
142
693
    }
143
693
}
_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
73
To binary_cast(From from) {
72
73
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
73
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
73
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
73
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
73
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
73
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
73
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
73
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
73
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
73
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
73
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
73
    constexpr bool from_ui64_to_datetime_v2 =
87
73
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
73
    constexpr bool from_datetime_v2_to_ui64 =
90
73
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
73
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
73
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
73
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
73
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
73
    if constexpr (from_u64_to_db) {
98
73
        TypeConverter conv;
99
73
        conv.u64 = from;
100
73
        return conv.dbl;
101
73
    } else if constexpr (from_i64_to_db) {
102
73
        TypeConverter conv;
103
73
        conv.i64 = from;
104
73
        return conv.dbl;
105
73
    } else if constexpr (from_db_to_i64) {
106
73
        TypeConverter conv;
107
73
        conv.dbl = from;
108
73
        return conv.i64;
109
73
    } else if constexpr (from_db_to_u64) {
110
73
        TypeConverter conv;
111
73
        conv.dbl = from;
112
73
        return conv.u64;
113
73
    } else if constexpr (from_i64_to_vec_dt) {
114
73
        VecDateTimeInt64Union conv = {.i64 = from};
115
73
        return conv.dt;
116
73
    } else if constexpr (from_ui32_to_date_v2) {
117
73
        DateV2UInt32Union conv = {.ui32 = from};
118
73
        return conv.dt;
119
73
    } else if constexpr (from_date_v2_to_ui32) {
120
73
        DateV2UInt32Union conv = {.dt = from};
121
73
        return conv.ui32;
122
73
    } else if constexpr (from_ui64_to_datetime_v2) {
123
73
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
73
        return conv.dt;
125
73
    } else if constexpr (from_datetime_v2_to_ui64) {
126
73
        DateTimeV2UInt64Union conv = {.dt = from};
127
73
        return conv.ui64;
128
73
    } else if constexpr (from_vec_dt_to_i64) {
129
73
        VecDateTimeInt64Union conv = {.dt = from};
130
73
        return conv.i64;
131
73
    } else if constexpr (from_i128_to_decv2) {
132
73
        DecimalInt128Union conv;
133
73
        conv.i128 = from;
134
73
        return conv.decimal;
135
73
    } else if constexpr (from_decv2_to_i128) {
136
73
        DecimalInt128Union conv;
137
73
        conv.decimal = from;
138
73
        return conv.i128;
139
73
    } else {
140
73
        LOG(FATAL) << "__builtin_unreachable";
141
73
        __builtin_unreachable();
142
73
    }
143
73
}
_ZN5doris11binary_castINS_14DecimalV2ValueEnEET0_T_
Line
Count
Source
71
42
To binary_cast(From from) {
72
42
    constexpr bool from_u64_to_db = match_v<From, uint64_t, To, double>;
73
42
    constexpr bool from_i64_to_db = match_v<From, int64_t, To, double>;
74
42
    constexpr bool from_db_to_i64 = match_v<From, double, To, int64_t>;
75
42
    constexpr bool from_db_to_u64 = match_v<From, double, To, uint64_t>;
76
42
    constexpr bool from_i64_to_vec_dt = match_v<From, __int64_t, To, doris::VecDateTimeValue>;
77
42
    constexpr bool from_vec_dt_to_i64 = match_v<From, doris::VecDateTimeValue, To, __int64_t>;
78
42
    constexpr bool from_i128_to_decv2 = match_v<From, __int128_t, To, DecimalV2Value>;
79
42
    constexpr bool from_decv2_to_i128 = match_v<From, DecimalV2Value, To, __int128_t>;
80
42
    constexpr bool from_decv2_to_i256 = match_v<From, DecimalV2Value, To, wide::Int256>;
81
82
42
    constexpr bool from_ui32_to_date_v2 = match_v<From, uint32_t, To, DateV2Value<DateV2ValueType>>;
83
84
42
    constexpr bool from_date_v2_to_ui32 = match_v<From, DateV2Value<DateV2ValueType>, To, uint32_t>;
85
86
42
    constexpr bool from_ui64_to_datetime_v2 =
87
42
            match_v<From, uint64_t, To, DateV2Value<DateTimeV2ValueType>>;
88
89
42
    constexpr bool from_datetime_v2_to_ui64 =
90
42
            match_v<From, DateV2Value<DateTimeV2ValueType>, To, uint64_t>;
91
92
42
    static_assert(from_u64_to_db || from_i64_to_db || from_db_to_i64 || from_db_to_u64 ||
93
42
                  from_i64_to_vec_dt || from_vec_dt_to_i64 || from_i128_to_decv2 ||
94
42
                  from_decv2_to_i128 || from_decv2_to_i256 || from_ui32_to_date_v2 ||
95
42
                  from_date_v2_to_ui32 || from_ui64_to_datetime_v2 || from_datetime_v2_to_ui64);
96
97
42
    if constexpr (from_u64_to_db) {
98
42
        TypeConverter conv;
99
42
        conv.u64 = from;
100
42
        return conv.dbl;
101
42
    } else if constexpr (from_i64_to_db) {
102
42
        TypeConverter conv;
103
42
        conv.i64 = from;
104
42
        return conv.dbl;
105
42
    } else if constexpr (from_db_to_i64) {
106
42
        TypeConverter conv;
107
42
        conv.dbl = from;
108
42
        return conv.i64;
109
42
    } else if constexpr (from_db_to_u64) {
110
42
        TypeConverter conv;
111
42
        conv.dbl = from;
112
42
        return conv.u64;
113
42
    } else if constexpr (from_i64_to_vec_dt) {
114
42
        VecDateTimeInt64Union conv = {.i64 = from};
115
42
        return conv.dt;
116
42
    } else if constexpr (from_ui32_to_date_v2) {
117
42
        DateV2UInt32Union conv = {.ui32 = from};
118
42
        return conv.dt;
119
42
    } else if constexpr (from_date_v2_to_ui32) {
120
42
        DateV2UInt32Union conv = {.dt = from};
121
42
        return conv.ui32;
122
42
    } else if constexpr (from_ui64_to_datetime_v2) {
123
42
        DateTimeV2UInt64Union conv = {.ui64 = from};
124
42
        return conv.dt;
125
42
    } else if constexpr (from_datetime_v2_to_ui64) {
126
42
        DateTimeV2UInt64Union conv = {.dt = from};
127
42
        return conv.ui64;
128
42
    } else if constexpr (from_vec_dt_to_i64) {
129
42
        VecDateTimeInt64Union conv = {.dt = from};
130
42
        return conv.i64;
131
42
    } else if constexpr (from_i128_to_decv2) {
132
42
        DecimalInt128Union conv;
133
42
        conv.i128 = from;
134
42
        return conv.decimal;
135
42
    } else if constexpr (from_decv2_to_i128) {
136
42
        DecimalInt128Union conv;
137
42
        conv.decimal = from;
138
42
        return conv.i128;
139
42
    } else {
140
42
        LOG(FATAL) << "__builtin_unreachable";
141
42
        __builtin_unreachable();
142
42
    }
143
42
}
144
145
} // namespace doris