Coverage Report

Created: 2026-09-24 12:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/function/datetime_errors.h
Line
Count
Source
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 <string>
21
#include <string_view>
22
23
#include "common/exception.h"
24
#include "common/status.h"
25
#include "core/binary_cast.hpp"
26
#include "core/types.h"
27
#include "core/value/timestamptz_value.h"
28
29
namespace doris {
30
// Convert a native datelike value to printable string using DateValueType::to_string
31
// Note: DateValueType must support to_string(char*) -> char*
32
//       NativeT is the corresponding FieldType of the DataType
33
template <typename DateValueType>
34
257
inline std::string datelike_to_string(DateValueType value) {
35
257
    char buf[40];
36
257
    char* end = value.to_string(buf);
37
    // minus 1 to skip trailing '\0'
38
257
    return std::string(buf, end - 1);
39
257
}
_ZN5doris18datelike_to_stringINS_16TimeStampNsValueEEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEET_
Line
Count
Source
34
55
inline std::string datelike_to_string(DateValueType value) {
35
55
    char buf[40];
36
55
    char* end = value.to_string(buf);
37
    // minus 1 to skip trailing '\0'
38
55
    return std::string(buf, end - 1);
39
55
}
_ZN5doris18datelike_to_stringINS_11DateV2ValueINS_15DateV2ValueTypeEEEEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEET_
Line
Count
Source
34
76
inline std::string datelike_to_string(DateValueType value) {
35
76
    char buf[40];
36
76
    char* end = value.to_string(buf);
37
    // minus 1 to skip trailing '\0'
38
76
    return std::string(buf, end - 1);
39
76
}
_ZN5doris18datelike_to_stringINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEET_
Line
Count
Source
34
126
inline std::string datelike_to_string(DateValueType value) {
35
126
    char buf[40];
36
126
    char* end = value.to_string(buf);
37
    // minus 1 to skip trailing '\0'
38
126
    return std::string(buf, end - 1);
39
126
}
40
41
// Specialization for TimestampTzValue: output UTC time for error messages
42
template <>
43
33
inline std::string datelike_to_string<TimestampTzValue>(TimestampTzValue native) {
44
    // Use UTC timezone for error messages
45
33
    return native.to_string(cctz::utc_time_zone());
46
33
}
47
48
// Throw for operations with one datelike argument
49
template <typename DateValueType>
50
12
[[noreturn]] inline void throw_out_of_bound_one_date(const char* op, DateValueType arg0) {
51
12
    throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {} out of range", op,
52
12
                    datelike_to_string<DateValueType>(arg0));
53
12
}
_ZN5doris27throw_out_of_bound_one_dateINS_16TimeStampNsValueEEEvPKcT_
Line
Count
Source
50
11
[[noreturn]] inline void throw_out_of_bound_one_date(const char* op, DateValueType arg0) {
51
11
    throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {} out of range", op,
52
11
                    datelike_to_string<DateValueType>(arg0));
53
11
}
Unexecuted instantiation: _ZN5doris27throw_out_of_bound_one_dateINS_11DateV2ValueINS_15DateV2ValueTypeEEEEEvPKcT_
_ZN5doris27throw_out_of_bound_one_dateINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEEvPKcT_
Line
Count
Source
50
1
[[noreturn]] inline void throw_out_of_bound_one_date(const char* op, DateValueType arg0) {
51
1
    throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {} out of range", op,
52
1
                    datelike_to_string<DateValueType>(arg0));
53
1
}
Unexecuted instantiation: _ZN5doris27throw_out_of_bound_one_dateINS_16TimestampTzValueEEEvPKcT_
54
55
// Throw for operations with a datelike and an integer (e.g. period)
56
template <typename DateValueType>
57
[[noreturn]] inline void throw_out_of_bound_date_int(const char* op, DateValueType arg0,
58
243
                                                     Int64 delta) {
59
243
    throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {}, {} out of range", op,
60
243
                    datelike_to_string<DateValueType>(arg0), delta);
61
243
}
_ZN5doris27throw_out_of_bound_date_intINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEEvPKcT_l
Line
Count
Source
58
90
                                                     Int64 delta) {
59
90
    throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {}, {} out of range", op,
60
90
                    datelike_to_string<DateValueType>(arg0), delta);
61
90
}
_ZN5doris27throw_out_of_bound_date_intINS_11DateV2ValueINS_15DateV2ValueTypeEEEEEvPKcT_l
Line
Count
Source
58
76
                                                     Int64 delta) {
59
76
    throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {}, {} out of range", op,
60
76
                    datelike_to_string<DateValueType>(arg0), delta);
61
76
}
_ZN5doris27throw_out_of_bound_date_intINS_16TimeStampNsValueEEEvPKcT_l
Line
Count
Source
58
44
                                                     Int64 delta) {
59
44
    throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {}, {} out of range", op,
60
44
                    datelike_to_string<DateValueType>(arg0), delta);
61
44
}
_ZN5doris27throw_out_of_bound_date_intINS_16TimestampTzValueEEEvPKcT_l
Line
Count
Source
58
33
                                                     Int64 delta) {
59
33
    throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {}, {} out of range", op,
60
33
                    datelike_to_string<DateValueType>(arg0), delta);
61
33
}
62
63
// Throw for operations with a datelike and a string interval(e.g., date_add(date, interval '-1 2:3:4' day_second))
64
template <typename DateValueType>
65
[[noreturn]] inline void throw_out_of_bound_date_string(const char* op, DateValueType arg0,
66
0
                                                        std::string_view delta) {
67
0
    throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {}, {} out of range", op,
68
0
                    datelike_to_string<DateValueType>(arg0), delta);
69
0
}
Unexecuted instantiation: _ZN5doris30throw_out_of_bound_date_stringINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEEvPKcT_St17basic_string_viewIcSt11char_traitsIcEE
Unexecuted instantiation: _ZN5doris30throw_out_of_bound_date_stringINS_16TimeStampNsValueEEEvPKcT_St17basic_string_viewIcSt11char_traitsIcEE
Unexecuted instantiation: _ZN5doris30throw_out_of_bound_date_stringINS_16TimestampTzValueEEEvPKcT_St17basic_string_viewIcSt11char_traitsIcEE
70
71
// Throw for operations with a single integer argument (e.g., from_days daynr)
72
148
[[noreturn]] inline void throw_out_of_bound_int(const char* op, int64_t value) {
73
148
    throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {} out of range", op, value);
74
148
}
75
76
// Throw for operations with two integer arguments (e.g., makedate(year, day))
77
2
[[noreturn]] inline void throw_out_of_bound_two_ints(const char* op, int64_t a, int64_t b) {
78
2
    throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {}, {} out of range", op, a, b);
79
2
}
80
81
// for convert_tz
82
template <typename DateValueType>
83
[[noreturn]] inline void throw_out_of_bound_convert_tz(DateValueType arg0,
84
                                                       std::string_view from_name,
85
1
                                                       std::string_view to_name) {
86
1
    throw Exception(ErrorCode::OUT_OF_BOUND, "Cannot convert {} from {} to {}",
87
1
                    datelike_to_string<DateValueType>(arg0), from_name, to_name);
88
1
}
_ZN5doris29throw_out_of_bound_convert_tzINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEEvT_St17basic_string_viewIcSt11char_traitsIcEES8_
Line
Count
Source
85
1
                                                       std::string_view to_name) {
86
1
    throw Exception(ErrorCode::OUT_OF_BOUND, "Cannot convert {} from {} to {}",
87
1
                    datelike_to_string<DateValueType>(arg0), from_name, to_name);
88
1
}
Unexecuted instantiation: _ZN5doris29throw_out_of_bound_convert_tzINS_16TimeStampNsValueEEEvT_St17basic_string_viewIcSt11char_traitsIcEES6_
89
90
// Throw for operations with a datelike, an integer and an origin datelike
91
// (e.g. time_round(datetime, period, origin))
92
template <typename DateValueType>
93
[[noreturn]] inline void throw_out_of_bound_int_date(const char* op, DateValueType arg0,
94
16
                                                     Int32 delta, DateValueType origin) {
95
16
    throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {}, {}, {} out of range", op,
96
16
                    datelike_to_string<DateValueType>(arg0), delta,
97
16
                    datelike_to_string<DateValueType>(origin));
98
16
}
Unexecuted instantiation: _ZN5doris27throw_out_of_bound_int_dateINS_11DateV2ValueINS_15DateV2ValueTypeEEEEEvPKcT_iS6_
_ZN5doris27throw_out_of_bound_int_dateINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEEvPKcT_iS6_
Line
Count
Source
94
16
                                                     Int32 delta, DateValueType origin) {
95
16
    throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {}, {}, {} out of range", op,
96
16
                    datelike_to_string<DateValueType>(arg0), delta,
97
16
                    datelike_to_string<DateValueType>(origin));
98
16
}
Unexecuted instantiation: _ZN5doris27throw_out_of_bound_int_dateINS_16TimeStampNsValueEEEvPKcT_iS4_
Unexecuted instantiation: _ZN5doris27throw_out_of_bound_int_dateINS_16TimestampTzValueEEEvPKcT_iS4_
99
100
// Throw for operations with two datelike arguments
101
// (e.g. time_round(datetime, origin))
102
template <typename DateValueType>
103
[[noreturn]] inline void throw_out_of_bound_date_date(const char* op, DateValueType arg0,
104
1
                                                      DateValueType arg1) {
105
1
    throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {}, {} out of range", op,
106
1
                    datelike_to_string<DateValueType>(arg0),
107
1
                    datelike_to_string<DateValueType>(arg1));
108
1
}
Unexecuted instantiation: _ZN5doris28throw_out_of_bound_date_dateINS_11DateV2ValueINS_15DateV2ValueTypeEEEEEvPKcT_S6_
_ZN5doris28throw_out_of_bound_date_dateINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEEvPKcT_S6_
Line
Count
Source
104
1
                                                      DateValueType arg1) {
105
1
    throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {}, {} out of range", op,
106
1
                    datelike_to_string<DateValueType>(arg0),
107
1
                    datelike_to_string<DateValueType>(arg1));
108
1
}
Unexecuted instantiation: _ZN5doris28throw_out_of_bound_date_dateINS_16TimeStampNsValueEEEvPKcT_S4_
Unexecuted instantiation: _ZN5doris28throw_out_of_bound_date_dateINS_16TimestampTzValueEEEvPKcT_S4_
109
110
// Throw for operations with an invalid string argument (e.g., from_iso8601_date)
111
28
[[noreturn]] inline void throw_invalid_string(const char* op, std::string_view s) {
112
28
    throw Exception(ErrorCode::INVALID_ARGUMENT, "Operation {} of {} is invalid", op, s);
113
28
}
114
115
// Throw for operations with two invalid string arguments (e.g., unix_timestamp with format)
116
[[noreturn]] inline void throw_invalid_strings(const char* op, std::string_view s0,
117
118
                                               std::string_view s1) {
118
118
    throw Exception(ErrorCode::INVALID_ARGUMENT, "Operation {} of {}, {} is invalid", op, s0, s1);
119
118
}
120
121
// Helper to get time unit name for error messages
122
241
constexpr const char* get_time_unit_name(TimeUnit unit) {
123
241
    switch (unit) {
124
20
    case TimeUnit::YEAR:
125
20
        return "year_add";
126
0
    case TimeUnit::QUARTER:
127
0
        return "quarter_add";
128
155
    case TimeUnit::MONTH:
129
155
        return "month_add";
130
6
    case TimeUnit::WEEK:
131
6
        return "week_add";
132
5
    case TimeUnit::DAY:
133
5
        return "day_add";
134
7
    case TimeUnit::HOUR:
135
7
        return "hour_add";
136
4
    case TimeUnit::MINUTE:
137
4
        return "minute_add";
138
7
    case TimeUnit::SECOND:
139
7
        return "second_add";
140
3
    case TimeUnit::MILLISECOND:
141
3
        return "millisecond_add";
142
7
    case TimeUnit::MICROSECOND:
143
7
        return "microsecond_add";
144
2
    case TimeUnit::YEAR_MONTH:
145
2
        return "year_month_add";
146
2
    case TimeUnit::DAY_HOUR:
147
2
        return "day_hour_add";
148
2
    case TimeUnit::DAY_MINUTE:
149
2
        return "day_minute_add";
150
3
    case TimeUnit::DAY_SECOND:
151
3
        return "day_second_add";
152
2
    case TimeUnit::DAY_MICROSECOND:
153
2
        return "day_microsecond_add";
154
2
    case TimeUnit::HOUR_MINUTE:
155
2
        return "hour_minute_add";
156
2
    case TimeUnit::HOUR_SECOND:
157
2
        return "hour_second_add";
158
2
    case TimeUnit::HOUR_MICROSECOND:
159
2
        return "hour_microsecond_add";
160
2
    case TimeUnit::MINUTE_SECOND:
161
2
        return "minute_second_add";
162
2
    case TimeUnit::MINUTE_MICROSECOND:
163
2
        return "minute_microsecond_add";
164
6
    case TimeUnit::SECOND_MICROSECOND:
165
6
        return "second_microsecond_add";
166
0
    default:
167
0
        return "date_add";
168
241
    }
169
241
}
170
} // namespace doris