Coverage Report

Created: 2025-07-23 18:49

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.1M
void check_cast_value(U b) {
32
12.1M
    if constexpr (IsUnsignedV<U>) {
33
2.95M
        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
2.95M
    } else if constexpr (IsUnsignedV<T>) {
40
1.33k
        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.16M
    } else {
47
9.16M
        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.16M
    }
54
12.1M
}
_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.09M
void check_cast_value(U b) {
32
1.09M
    if constexpr (IsUnsignedV<U>) {
33
1.09M
        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.09M
}
_ZN5doris16check_cast_valueIimEEvT0_
Line
Count
Source
31
1.66M
void check_cast_value(U b) {
32
1.66M
    if constexpr (IsUnsignedV<U>) {
33
1.66M
        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.66M
}
_ZN5doris16check_cast_valueIilEEvT0_
Line
Count
Source
31
9.13M
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.13M
    } else {
47
9.13M
        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.13M
    }
54
9.13M
}
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_valueIiiEEvT0_
Line
Count
Source
31
228
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
228
    } else {
47
228
        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
228
    }
54
228
}
_ZN5doris16check_cast_valueIhiEEvT0_
Line
Count
Source
31
1.33k
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.33k
    } else if constexpr (IsUnsignedV<T>) {
40
1.33k
        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.33k
}
_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
34.4k
void check_cast_value(U b) {
32
34.4k
    if constexpr (IsUnsignedV<U>) {
33
34.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
34.4k
}
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.1M
T cast_set(U b) {
74
12.1M
    if constexpr (need_check_value) {
75
12.1M
        check_cast_value<T>(b);
76
12.1M
    }
77
12.1M
    return static_cast<T>(b);
78
12.1M
}
_ZN5doris8cast_setIalLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
28.2k
T cast_set(U b) {
74
28.2k
    if constexpr (need_check_value) {
75
28.2k
        check_cast_value<T>(b);
76
28.2k
    }
77
28.2k
    return static_cast<T>(b);
78
28.2k
}
_ZN5doris8cast_setIjmLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
1.09M
T cast_set(U b) {
74
1.09M
    if constexpr (need_check_value) {
75
1.09M
        check_cast_value<T>(b);
76
1.09M
    }
77
1.09M
    return static_cast<T>(b);
78
1.09M
}
Unexecuted instantiation: _ZN5doris8cast_setIciLb0EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
_ZN5doris8cast_setIimLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
1.66M
T cast_set(U b) {
74
1.66M
    if constexpr (need_check_value) {
75
1.66M
        check_cast_value<T>(b);
76
1.66M
    }
77
1.66M
    return static_cast<T>(b);
78
1.66M
}
_ZN5doris8cast_setIilLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
9.13M
T cast_set(U b) {
74
9.13M
    if constexpr (need_check_value) {
75
9.13M
        check_cast_value<T>(b);
76
9.13M
    }
77
9.13M
    return static_cast<T>(b);
78
9.13M
}
_ZN5doris8cast_setIhjLb0EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
8
T cast_set(U b) {
74
    if constexpr (need_check_value) {
75
        check_cast_value<T>(b);
76
    }
77
8
    return static_cast<T>(b);
78
8
}
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_setIiiLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
228
T cast_set(U b) {
74
228
    if constexpr (need_check_value) {
75
228
        check_cast_value<T>(b);
76
228
    }
77
228
    return static_cast<T>(b);
78
228
}
_ZN5doris8cast_setIhiLb1EQaa11IsIntegralVIT_E11IsIntegralVIT0_EEES1_S2_
Line
Count
Source
73
1.33k
T cast_set(U b) {
74
1.33k
    if constexpr (need_check_value) {
75
1.33k
        check_cast_value<T>(b);
76
1.33k
    }
77
1.33k
    return static_cast<T>(b);
78
1.33k
}
_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
34.4k
T cast_set(U b) {
74
34.4k
    if constexpr (need_check_value) {
75
34.4k
        check_cast_value<T>(b);
76
34.4k
    }
77
34.4k
    return static_cast<T>(b);
78
34.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_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