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 | 129 | inline std::string datelike_to_string(DateValueType value) { |
35 | 129 | char buf[40]; |
36 | 129 | char* end = value.to_string(buf); |
37 | | // minus 1 to skip trailing '\0' |
38 | 129 | return std::string(buf, end - 1); |
39 | 129 | } _ZN5doris18datelike_to_stringINS_11DateV2ValueINS_15DateV2ValueTypeEEEEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEET_ Line | Count | Source | 34 | 37 | inline std::string datelike_to_string(DateValueType value) { | 35 | 37 | char buf[40]; | 36 | 37 | char* end = value.to_string(buf); | 37 | | // minus 1 to skip trailing '\0' | 38 | 37 | return std::string(buf, end - 1); | 39 | 37 | } |
_ZN5doris18datelike_to_stringINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEET_ Line | Count | Source | 34 | 92 | inline std::string datelike_to_string(DateValueType value) { | 35 | 92 | char buf[40]; | 36 | 92 | char* end = value.to_string(buf); | 37 | | // minus 1 to skip trailing '\0' | 38 | 92 | return std::string(buf, end - 1); | 39 | 92 | } |
|
40 | | |
41 | | // Specialization for TimestampTzValue: output UTC time for error messages |
42 | | template <> |
43 | 0 | inline std::string datelike_to_string<TimestampTzValue>(TimestampTzValue native) { |
44 | | // Use UTC timezone for error messages |
45 | 0 | return native.to_string(cctz::utc_time_zone()); |
46 | 0 | } |
47 | | |
48 | | // Throw for operations with one datelike argument |
49 | | template <typename DateValueType> |
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_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 | 93 | Int32 delta) { |
59 | 93 | throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {}, {} out of range", op, |
60 | 93 | datelike_to_string<DateValueType>(arg0), delta); |
61 | 93 | } _ZN5doris27throw_out_of_bound_date_intINS_11DateV2ValueINS_15DateV2ValueTypeEEEEEvPKcT_i Line | Count | Source | 58 | 37 | Int32 delta) { | 59 | 37 | throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {}, {} out of range", op, | 60 | 37 | datelike_to_string<DateValueType>(arg0), delta); | 61 | 37 | } |
_ZN5doris27throw_out_of_bound_date_intINS_11DateV2ValueINS_19DateTimeV2ValueTypeEEEEEvPKcT_i Line | Count | Source | 58 | 56 | Int32 delta) { | 59 | 56 | throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {}, {} out of range", op, | 60 | 56 | datelike_to_string<DateValueType>(arg0), delta); | 61 | 56 | } |
Unexecuted instantiation: _ZN5doris27throw_out_of_bound_date_intINS_16TimestampTzValueEEEvPKcT_i |
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_16TimestampTzValueEEEvPKcT_St17basic_string_viewIcSt11char_traitsIcEE |
70 | | |
71 | | // Throw for operations with a single integer argument (e.g., from_days daynr) |
72 | 15 | [[noreturn]] inline void throw_out_of_bound_int(const char* op, int64_t value) { |
73 | 15 | throw Exception(ErrorCode::OUT_OF_BOUND, "Operation {} of {} out of range", op, value); |
74 | 15 | } |
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 | } |
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_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_16TimestampTzValueEEEvPKcT_S4_ |
109 | | |
110 | | // Throw for operations with an invalid string argument (e.g., from_iso8601_date) |
111 | 24 | [[noreturn]] inline void throw_invalid_string(const char* op, std::string_view s) { |
112 | 24 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Operation {} of {} is invalid", op, s); |
113 | 24 | } |
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 | 24 | std::string_view s1) { |
118 | 24 | throw Exception(ErrorCode::INVALID_ARGUMENT, "Operation {} of {}, {} is invalid", op, s0, s1); |
119 | 24 | } |
120 | | |
121 | | // Helper to get time unit name for error messages |
122 | 94 | constexpr const char* get_time_unit_name(TimeUnit unit) { |
123 | 94 | switch (unit) { |
124 | 19 | case TimeUnit::YEAR: |
125 | 19 | return "year_add"; |
126 | 0 | case TimeUnit::QUARTER: |
127 | 0 | return "quarter_add"; |
128 | 18 | case TimeUnit::MONTH: |
129 | 18 | return "month_add"; |
130 | 6 | case TimeUnit::WEEK: |
131 | 6 | return "week_add"; |
132 | 3 | case TimeUnit::DAY: |
133 | 3 | return "day_add"; |
134 | 7 | case TimeUnit::HOUR: |
135 | 7 | return "hour_add"; |
136 | 4 | case TimeUnit::MINUTE: |
137 | 4 | return "minute_add"; |
138 | 5 | case TimeUnit::SECOND: |
139 | 5 | return "second_add"; |
140 | 3 | case TimeUnit::MILLISECOND: |
141 | 3 | return "millisecond_add"; |
142 | 6 | case TimeUnit::MICROSECOND: |
143 | 6 | 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 | 2 | case TimeUnit::SECOND_MICROSECOND: |
165 | 2 | return "second_microsecond_add"; |
166 | 0 | default: |
167 | 0 | return "date_add"; |
168 | 94 | } |
169 | 94 | } |
170 | | } // namespace doris |