Coverage Report

Created: 2024-11-20 18:15

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