Coverage Report

Created: 2025-07-25 22:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/common/cast_set.h
Line
Count
Source
1
2
// Licensed to the Apache Software Foundation (ASF) under one
3
// or more contributor license agreements.  See the NOTICE file
4
// distributed with this work for additional information
5
// regarding copyright ownership.  The ASF licenses this file
6
// to you under the Apache License, Version 2.0 (the
7
// "License"); you may not use this file except in compliance
8
// with the License.  You may obtain a copy of the License at
9
//
10
//   http://www.apache.org/licenses/LICENSE-2.0
11
//
12
// Unless required by applicable law or agreed to in writing,
13
// software distributed under the License is distributed on an
14
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
// KIND, either express or implied.  See the License for the
16
// specific language governing permissions and limitations
17
// under the License.
18
19
#pragma once
20
21
#include <limits>
22
#include <type_traits>
23
24
#include "common/exception.h"
25
#include "common/status.h"
26
#include "vec/core/extended_types.h"
27
28
namespace doris {
29
30
template <typename T, typename U>
31
12.5M
void check_cast_value(U b) {
32
12.5M
    if constexpr (IsUnsignedV<U>) {
33
3.31M
        if (b > std::numeric_limits<T>::max()) {
34
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
35
0
                                   "value {} cast  to type {} out of range [{},{}]", b,
36
0
                                   typeid(T).name(), std::numeric_limits<T>::min(),
37
0
                                   std::numeric_limits<T>::max());
38
0
        }
39
3.31M
    } else if constexpr (IsUnsignedV<T>) {
40
1.31k
        if (b < 0 || b > std::numeric_limits<T>::max()) {
41
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
42
0
                                   "value {} cast  to type {} out of range [{},{}]", b,
43
0
                                   typeid(T).name(), std::numeric_limits<T>::min(),
44
0
                                   std::numeric_limits<T>::max());
45
0
        }
46
9.19M
    } else {
47
9.19M
        if (b < std::numeric_limits<T>::min() || b > std::numeric_limits<T>::max()) {
48
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
49
0
                                   "value {} cast  to type {} out of range [{},{}]", b,
50
0
                                   typeid(T).name(), std::numeric_limits<T>::min(),
51
0
                                   std::numeric_limits<T>::max());
52
0
        }
53
9.19M
    }
54
12.5M
}
_ZN5doris16check_cast_valueIalEEvT0_
Line
Count
Source
31
28.6k
void check_cast_value(U b) {
32
    if constexpr (IsUnsignedV<U>) {
33
        if (b > std::numeric_limits<T>::max()) {
34
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
35
                                   "value {} cast  to type {} out of range [{},{}]", b,
36
                                   typeid(T).name(), std::numeric_limits<T>::min(),
37
                                   std::numeric_limits<T>::max());
38
        }
39
    } else if constexpr (IsUnsignedV<T>) {
40
        if (b < 0 || b > std::numeric_limits<T>::max()) {
41
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
42
                                   "value {} cast  to type {} out of range [{},{}]", b,
43
                                   typeid(T).name(), std::numeric_limits<T>::min(),
44
                                   std::numeric_limits<T>::max());
45
        }
46
28.6k
    } else {
47
28.6k
        if (b < std::numeric_limits<T>::min() || b > std::numeric_limits<T>::max()) {
48
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
49
0
                                   "value {} cast  to type {} out of range [{},{}]", b,
50
0
                                   typeid(T).name(), std::numeric_limits<T>::min(),
51
0
                                   std::numeric_limits<T>::max());
52
0
        }
53
28.6k
    }
54
28.6k
}
_ZN5doris16check_cast_valueIjmEEvT0_
Line
Count
Source
31
1.08M
void check_cast_value(U b) {
32
1.08M
    if constexpr (IsUnsignedV<U>) {
33
1.08M
        if (b > std::numeric_limits<T>::max()) {
34
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
35
0
                                   "value {} cast  to type {} out of range [{},{}]", b,
36
0
                                   typeid(T).name(), std::numeric_limits<T>::min(),
37
0
                                   std::numeric_limits<T>::max());
38
0
        }
39
    } else if constexpr (IsUnsignedV<T>) {
40
        if (b < 0 || b > std::numeric_limits<T>::max()) {
41
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
42
                                   "value {} cast  to type {} out of range [{},{}]", b,
43
                                   typeid(T).name(), std::numeric_limits<T>::min(),
44
                                   std::numeric_limits<T>::max());
45
        }
46
    } else {
47
        if (b < std::numeric_limits<T>::min() || b > std::numeric_limits<T>::max()) {
48
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
49
                                   "value {} cast  to type {} out of range [{},{}]", b,
50
                                   typeid(T).name(), std::numeric_limits<T>::min(),
51
                                   std::numeric_limits<T>::max());
52
        }
53
    }
54
1.08M
}
_ZN5doris16check_cast_valueIimEEvT0_
Line
Count
Source
31
2.04M
void check_cast_value(U b) {
32
2.04M
    if constexpr (IsUnsignedV<U>) {
33
2.04M
        if (b > std::numeric_limits<T>::max()) {
34
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
35
0
                                   "value {} cast  to type {} out of range [{},{}]", b,
36
0
                                   typeid(T).name(), std::numeric_limits<T>::min(),
37
0
                                   std::numeric_limits<T>::max());
38
0
        }
39
    } else if constexpr (IsUnsignedV<T>) {
40
        if (b < 0 || b > std::numeric_limits<T>::max()) {
41
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
42
                                   "value {} cast  to type {} out of range [{},{}]", b,
43
                                   typeid(T).name(), std::numeric_limits<T>::min(),
44
                                   std::numeric_limits<T>::max());
45
        }
46
    } else {
47
        if (b < std::numeric_limits<T>::min() || b > std::numeric_limits<T>::max()) {
48
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
49
                                   "value {} cast  to type {} out of range [{},{}]", b,
50
                                   typeid(T).name(), std::numeric_limits<T>::min(),
51
                                   std::numeric_limits<T>::max());
52
        }
53
    }
54
2.04M
}
_ZN5doris16check_cast_valueIilEEvT0_
Line
Count
Source
31
9.14M
void check_cast_value(U b) {
32
    if constexpr (IsUnsignedV<U>) {
33
        if (b > std::numeric_limits<T>::max()) {
34
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
35
                                   "value {} cast  to type {} out of range [{},{}]", b,
36
                                   typeid(T).name(), std::numeric_limits<T>::min(),
37
                                   std::numeric_limits<T>::max());
38
        }
39
    } else if constexpr (IsUnsignedV<T>) {
40
        if (b < 0 || b > std::numeric_limits<T>::max()) {
41
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
42
                                   "value {} cast  to type {} out of range [{},{}]", b,
43
                                   typeid(T).name(), std::numeric_limits<T>::min(),
44
                                   std::numeric_limits<T>::max());
45
        }
46
9.14M
    } else {
47
9.14M
        if (b < std::numeric_limits<T>::min() || b > std::numeric_limits<T>::max()) {
48
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
49
0
                                   "value {} cast  to type {} out of range [{},{}]", b,
50
0
                                   typeid(T).name(), std::numeric_limits<T>::min(),
51
0
                                   std::numeric_limits<T>::max());
52
0
        }
53
9.14M
    }
54
9.14M
}
_ZN5doris16check_cast_valueIiiEEvT0_
Line
Count
Source
31
21.3k
void check_cast_value(U b) {
32
    if constexpr (IsUnsignedV<U>) {
33
        if (b > std::numeric_limits<T>::max()) {
34
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
35
                                   "value {} cast  to type {} out of range [{},{}]", b,
36
                                   typeid(T).name(), std::numeric_limits<T>::min(),
37
                                   std::numeric_limits<T>::max());
38
        }
39
    } else if constexpr (IsUnsignedV<T>) {
40
        if (b < 0 || b > std::numeric_limits<T>::max()) {
41
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
42
                                   "value {} cast  to type {} out of range [{},{}]", b,
43
                                   typeid(T).name(), std::numeric_limits<T>::min(),
44
                                   std::numeric_limits<T>::max());
45
        }
46
21.3k
    } else {
47
21.3k
        if (b < std::numeric_limits<T>::min() || b > std::numeric_limits<T>::max()) {
48
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
49
0
                                   "value {} cast  to type {} out of range [{},{}]", b,
50
0
                                   typeid(T).name(), std::numeric_limits<T>::min(),
51
0
                                   std::numeric_limits<T>::max());
52
0
        }
53
21.3k
    }
54
21.3k
}
Unexecuted instantiation: _ZN5doris16check_cast_valueIlmEEvT0_
_ZN5doris16check_cast_valueIsmEEvT0_
Line
Count
Source
31
2.01k
void check_cast_value(U b) {
32
2.01k
    if constexpr (IsUnsignedV<U>) {
33
2.01k
        if (b > std::numeric_limits<T>::max()) {
34
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
35
0
                                   "value {} cast  to type {} out of range [{},{}]", b,
36
0
                                   typeid(T).name(), std::numeric_limits<T>::min(),
37
0
                                   std::numeric_limits<T>::max());
38
0
        }
39
    } else if constexpr (IsUnsignedV<T>) {
40
        if (b < 0 || b > std::numeric_limits<T>::max()) {
41
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
42
                                   "value {} cast  to type {} out of range [{},{}]", b,
43
                                   typeid(T).name(), std::numeric_limits<T>::min(),
44
                                   std::numeric_limits<T>::max());
45
        }
46
    } else {
47
        if (b < std::numeric_limits<T>::min() || b > std::numeric_limits<T>::max()) {
48
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
49
                                   "value {} cast  to type {} out of range [{},{}]", b,
50
                                   typeid(T).name(), std::numeric_limits<T>::min(),
51
                                   std::numeric_limits<T>::max());
52
        }
53
    }
54
2.01k
}
Unexecuted instantiation: _ZN5doris16check_cast_valueIjlEEvT0_
_ZN5doris16check_cast_valueIhiEEvT0_
Line
Count
Source
31
1.31k
void check_cast_value(U b) {
32
    if constexpr (IsUnsignedV<U>) {
33
        if (b > std::numeric_limits<T>::max()) {
34
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
35
                                   "value {} cast  to type {} out of range [{},{}]", b,
36
                                   typeid(T).name(), std::numeric_limits<T>::min(),
37
                                   std::numeric_limits<T>::max());
38
        }
39
1.31k
    } else if constexpr (IsUnsignedV<T>) {
40
1.31k
        if (b < 0 || b > std::numeric_limits<T>::max()) {
41
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
42
0
                                   "value {} cast  to type {} out of range [{},{}]", b,
43
0
                                   typeid(T).name(), std::numeric_limits<T>::min(),
44
0
                                   std::numeric_limits<T>::max());
45
0
        }
46
    } else {
47
        if (b < std::numeric_limits<T>::min() || b > std::numeric_limits<T>::max()) {
48
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
49
                                   "value {} cast  to type {} out of range [{},{}]", b,
50
                                   typeid(T).name(), std::numeric_limits<T>::min(),
51
                                   std::numeric_limits<T>::max());
52
        }
53
    }
54
1.31k
}
_ZN5doris16check_cast_valueImmEEvT0_
Line
Count
Source
31
155k
void check_cast_value(U b) {
32
155k
    if constexpr (IsUnsignedV<U>) {
33
155k
        if (b > std::numeric_limits<T>::max()) {
34
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
35
0
                                   "value {} cast  to type {} out of range [{},{}]", b,
36
0
                                   typeid(T).name(), std::numeric_limits<T>::min(),
37
0
                                   std::numeric_limits<T>::max());
38
0
        }
39
    } else if constexpr (IsUnsignedV<T>) {
40
        if (b < 0 || b > std::numeric_limits<T>::max()) {
41
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
42
                                   "value {} cast  to type {} out of range [{},{}]", b,
43
                                   typeid(T).name(), std::numeric_limits<T>::min(),
44
                                   std::numeric_limits<T>::max());
45
        }
46
    } else {
47
        if (b < std::numeric_limits<T>::min() || b > std::numeric_limits<T>::max()) {
48
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
49
                                   "value {} cast  to type {} out of range [{},{}]", b,
50
                                   typeid(T).name(), std::numeric_limits<T>::min(),
51
                                   std::numeric_limits<T>::max());
52
        }
53
    }
54
155k
}
_ZN5doris16check_cast_valueIbmEEvT0_
Line
Count
Source
31
26.4k
void check_cast_value(U b) {
32
26.4k
    if constexpr (IsUnsignedV<U>) {
33
26.4k
        if (b > std::numeric_limits<T>::max()) {
34
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
35
0
                                   "value {} cast  to type {} out of range [{},{}]", b,
36
0
                                   typeid(T).name(), std::numeric_limits<T>::min(),
37
0
                                   std::numeric_limits<T>::max());
38
0
        }
39
    } else if constexpr (IsUnsignedV<T>) {
40
        if (b < 0 || b > std::numeric_limits<T>::max()) {
41
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
42
                                   "value {} cast  to type {} out of range [{},{}]", b,
43
                                   typeid(T).name(), std::numeric_limits<T>::min(),
44
                                   std::numeric_limits<T>::max());
45
        }
46
    } else {
47
        if (b < std::numeric_limits<T>::min() || b > std::numeric_limits<T>::max()) {
48
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
49
                                   "value {} cast  to type {} out of range [{},{}]", b,
50
                                   typeid(T).name(), std::numeric_limits<T>::min(),
51
                                   std::numeric_limits<T>::max());
52
        }
53
    }
54
26.4k
}
Unexecuted instantiation: _ZN5doris16check_cast_valueIhsEEvT0_
Unexecuted instantiation: _ZN5doris16check_cast_valueIhlEEvT0_
Unexecuted instantiation: _ZN5doris16check_cast_valueIliEEvT0_
Unexecuted instantiation: _ZN5doris16check_cast_valueIllEEvT0_
Unexecuted instantiation: _ZN5doris16check_cast_valueIlnEEvT0_
55
56
template <typename T, typename U, bool need_check_value = true>
57
    requires IsIntegralV<T> && IsIntegralV<U>
58
void cast_set(T& a, U b) {
59
    if constexpr (need_check_value) {
60
        check_cast_value<T>(b);
61
    }
62
    a = static_cast<T>(b);
63
}
64
65
template <typename T, typename U>
66
    requires std::is_floating_point_v<T> and std::is_integral_v<U>
67
void cast_set(T& a, U b) {
68
    a = static_cast<T>(b);
69
}
70
71
template <typename T, typename U, bool need_check_value = true>
72
    requires IsIntegralV<T> && IsIntegralV<U>
73
12.5M
T cast_set(U b) {
74
12.5M
    if constexpr (need_check_value) {
75
12.5M
        check_cast_value<T>(b);
76
12.5M
    }
77
12.5M
    return static_cast<T>(b);
78
12.5M
}
_ZN5doris8cast_setIalLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
28.3k
T cast_set(U b) {
74
28.3k
    if constexpr (need_check_value) {
75
28.3k
        check_cast_value<T>(b);
76
28.3k
    }
77
28.3k
    return static_cast<T>(b);
78
28.3k
}
_ZN5doris8cast_setIjmLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
1.08M
T cast_set(U b) {
74
1.08M
    if constexpr (need_check_value) {
75
1.08M
        check_cast_value<T>(b);
76
1.08M
    }
77
1.08M
    return static_cast<T>(b);
78
1.08M
}
Unexecuted instantiation: _ZN5doris8cast_setIciLb0EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
_ZN5doris8cast_setIimLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
2.04M
T cast_set(U b) {
74
2.04M
    if constexpr (need_check_value) {
75
2.04M
        check_cast_value<T>(b);
76
2.04M
    }
77
2.04M
    return static_cast<T>(b);
78
2.04M
}
_ZN5doris8cast_setIilLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
9.14M
T cast_set(U b) {
74
9.14M
    if constexpr (need_check_value) {
75
9.14M
        check_cast_value<T>(b);
76
9.14M
    }
77
9.14M
    return static_cast<T>(b);
78
9.14M
}
_ZN5doris8cast_setIhjLb0EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
14
T cast_set(U b) {
74
    if constexpr (need_check_value) {
75
        check_cast_value<T>(b);
76
    }
77
14
    return static_cast<T>(b);
78
14
}
_ZN5doris8cast_setIiiLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
21.3k
T cast_set(U b) {
74
21.3k
    if constexpr (need_check_value) {
75
21.3k
        check_cast_value<T>(b);
76
21.3k
    }
77
21.3k
    return static_cast<T>(b);
78
21.3k
}
Unexecuted instantiation: _ZN5doris8cast_setIlmLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
_ZN5doris8cast_setIsmLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
2.01k
T cast_set(U b) {
74
2.01k
    if constexpr (need_check_value) {
75
2.01k
        check_cast_value<T>(b);
76
2.01k
    }
77
2.01k
    return static_cast<T>(b);
78
2.01k
}
Unexecuted instantiation: _ZN5doris8cast_setIjlLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
_ZN5doris8cast_setIsiLb0EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
1.01k
T cast_set(U b) {
74
    if constexpr (need_check_value) {
75
        check_cast_value<T>(b);
76
    }
77
1.01k
    return static_cast<T>(b);
78
1.01k
}
_ZN5doris8cast_setIhiLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
1.31k
T cast_set(U b) {
74
1.31k
    if constexpr (need_check_value) {
75
1.31k
        check_cast_value<T>(b);
76
1.31k
    }
77
1.31k
    return static_cast<T>(b);
78
1.31k
}
_ZN5doris8cast_setImmLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
155k
T cast_set(U b) {
74
155k
    if constexpr (need_check_value) {
75
155k
        check_cast_value<T>(b);
76
155k
    }
77
155k
    return static_cast<T>(b);
78
155k
}
_ZN5doris8cast_setIbmLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
26.4k
T cast_set(U b) {
74
26.4k
    if constexpr (need_check_value) {
75
26.4k
        check_cast_value<T>(b);
76
26.4k
    }
77
26.4k
    return static_cast<T>(b);
78
26.4k
}
_ZN5doris8cast_setIaiLb0EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
1.07k
T cast_set(U b) {
74
    if constexpr (need_check_value) {
75
        check_cast_value<T>(b);
76
    }
77
1.07k
    return static_cast<T>(b);
78
1.07k
}
Unexecuted instantiation: _ZN5doris8cast_setIhsLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Unexecuted instantiation: _ZN5doris8cast_setIhlLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Unexecuted instantiation: _ZN5doris8cast_setIliLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Unexecuted instantiation: _ZN5doris8cast_setIllLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Unexecuted instantiation: _ZN5doris8cast_setIlnLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
_ZN5doris8cast_setIjmLb0EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
14
T cast_set(U b) {
74
    if constexpr (need_check_value) {
75
        check_cast_value<T>(b);
76
    }
77
14
    return static_cast<T>(b);
78
14
}
_ZN5doris8cast_setIilLb0EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
294
T cast_set(U b) {
74
    if constexpr (need_check_value) {
75
        check_cast_value<T>(b);
76
    }
77
294
    return static_cast<T>(b);
78
294
}
79
80
template <typename T, typename U>
81
    requires std::is_floating_point_v<T> and std::is_integral_v<U>
82
T cast_set(U b) {
83
    return static_cast<T>(b);
84
}
85
86
} // namespace doris