Coverage Report

Created: 2024-11-22 12:06

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