Coverage Report

Created: 2025-06-20 03:12

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