be/src/exprs/function/function_string_format.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 <fmt/format.h> |
21 | | |
22 | | #include <cmath> |
23 | | #include <cstddef> |
24 | | #include <cstring> |
25 | | #include <limits> |
26 | | #include <string> |
27 | | #include <type_traits> |
28 | | |
29 | | #include "common/status.h" |
30 | | #include "core/assert_cast.h" |
31 | | #include "core/block/block.h" |
32 | | #include "core/block/column_numbers.h" |
33 | | #include "core/column/column_const.h" |
34 | | #include "core/column/column_decimal.h" |
35 | | #include "core/column/column_string.h" |
36 | | #include "core/column/column_vector.h" |
37 | | #include "core/data_type/data_type_decimal.h" |
38 | | #include "core/data_type/data_type_number.h" |
39 | | #include "core/data_type/data_type_string.h" |
40 | | #include "core/data_type/define_primitive_type.h" |
41 | | #include "core/data_type/primitive_type.h" |
42 | | #include "core/extended_types.h" |
43 | | #include "core/string_ref.h" |
44 | | #include "core/types.h" |
45 | | #include "core/value/decimalv2_value.h" |
46 | | #include "exec/common/int_exp.h" |
47 | | #include "exec/common/stringop_substring.h" |
48 | | #include "exec/common/template_helpers.hpp" |
49 | | #include "exprs/function/function.h" |
50 | | #include "exprs/function/function_helpers.h" |
51 | | #include "exprs/function_context.h" |
52 | | #include "exprs/math_functions.h" |
53 | | |
54 | | namespace doris { |
55 | | #include "common/compile_check_avoid_begin.h" |
56 | | |
57 | | // ---------------------------------------------------------------------- |
58 | | // SimpleItoaWithCommas() |
59 | | // Description: converts an integer to a string. |
60 | | // Puts commas every 3 spaces. |
61 | | // Faster than printf("%d")? |
62 | | // |
63 | | // Return value: string |
64 | | // ---------------------------------------------------------------------- |
65 | | template <typename T> |
66 | 1.17k | char* SimpleItoaWithCommas(T i, char* buffer, int32_t buffer_size) { |
67 | 1.17k | char* p = buffer + buffer_size; |
68 | | // Need to use unsigned T instead of T to correctly handle |
69 | 1.17k | MakeUnsignedT<T> n = i; |
70 | 1.17k | if (i < 0) { |
71 | 268 | n = 0 - n; |
72 | 268 | } |
73 | 1.17k | *--p = '0' + n % 10; // this case deals with the number "0" |
74 | 1.17k | n /= 10; |
75 | 1.68k | while (n) { |
76 | 571 | *--p = '0' + n % 10; |
77 | 571 | n /= 10; |
78 | 571 | if (n == 0) { |
79 | 37 | break; |
80 | 37 | } |
81 | | |
82 | 534 | *--p = '0' + n % 10; |
83 | 534 | n /= 10; |
84 | 534 | if (n == 0) { |
85 | 24 | break; |
86 | 24 | } |
87 | | |
88 | 510 | *--p = ','; |
89 | 510 | *--p = '0' + n % 10; |
90 | 510 | n /= 10; |
91 | | // For this unrolling, we check if n == 0 in the main while loop |
92 | 510 | } |
93 | 1.17k | if (i < 0) { |
94 | 268 | *--p = '-'; |
95 | 268 | } |
96 | 1.17k | return p; |
97 | 1.17k | } _ZN5doris20SimpleItoaWithCommasInEEPcT_S1_i Line | Count | Source | 66 | 427 | char* SimpleItoaWithCommas(T i, char* buffer, int32_t buffer_size) { | 67 | 427 | char* p = buffer + buffer_size; | 68 | | // Need to use unsigned T instead of T to correctly handle | 69 | 427 | MakeUnsignedT<T> n = i; | 70 | 427 | if (i < 0) { | 71 | 86 | n = 0 - n; | 72 | 86 | } | 73 | 427 | *--p = '0' + n % 10; // this case deals with the number "0" | 74 | 427 | n /= 10; | 75 | 476 | while (n) { | 76 | 68 | *--p = '0' + n % 10; | 77 | 68 | n /= 10; | 78 | 68 | if (n == 0) { | 79 | 8 | break; | 80 | 8 | } | 81 | | | 82 | 60 | *--p = '0' + n % 10; | 83 | 60 | n /= 10; | 84 | 60 | if (n == 0) { | 85 | 11 | break; | 86 | 11 | } | 87 | | | 88 | 49 | *--p = ','; | 89 | 49 | *--p = '0' + n % 10; | 90 | 49 | n /= 10; | 91 | | // For this unrolling, we check if n == 0 in the main while loop | 92 | 49 | } | 93 | 427 | if (i < 0) { | 94 | 86 | *--p = '-'; | 95 | 86 | } | 96 | 427 | return p; | 97 | 427 | } |
_ZN5doris20SimpleItoaWithCommasIlEEPcT_S1_i Line | Count | Source | 66 | 443 | char* SimpleItoaWithCommas(T i, char* buffer, int32_t buffer_size) { | 67 | 443 | char* p = buffer + buffer_size; | 68 | | // Need to use unsigned T instead of T to correctly handle | 69 | 443 | MakeUnsignedT<T> n = i; | 70 | 443 | if (i < 0) { | 71 | 106 | n = 0 - n; | 72 | 106 | } | 73 | 443 | *--p = '0' + n % 10; // this case deals with the number "0" | 74 | 443 | n /= 10; | 75 | 512 | while (n) { | 76 | 103 | *--p = '0' + n % 10; | 77 | 103 | n /= 10; | 78 | 103 | if (n == 0) { | 79 | 29 | break; | 80 | 29 | } | 81 | | | 82 | 74 | *--p = '0' + n % 10; | 83 | 74 | n /= 10; | 84 | 74 | if (n == 0) { | 85 | 5 | break; | 86 | 5 | } | 87 | | | 88 | 69 | *--p = ','; | 89 | 69 | *--p = '0' + n % 10; | 90 | 69 | n /= 10; | 91 | | // For this unrolling, we check if n == 0 in the main while loop | 92 | 69 | } | 93 | 443 | if (i < 0) { | 94 | 106 | *--p = '-'; | 95 | 106 | } | 96 | 443 | return p; | 97 | 443 | } |
_ZN5doris20SimpleItoaWithCommasIN4wide7integerILm256EiEEEEPcT_S4_i Line | Count | Source | 66 | 306 | char* SimpleItoaWithCommas(T i, char* buffer, int32_t buffer_size) { | 67 | 306 | char* p = buffer + buffer_size; | 68 | | // Need to use unsigned T instead of T to correctly handle | 69 | 306 | MakeUnsignedT<T> n = i; | 70 | 306 | if (i < 0) { | 71 | 76 | n = 0 - n; | 72 | 76 | } | 73 | 306 | *--p = '0' + n % 10; // this case deals with the number "0" | 74 | 306 | n /= 10; | 75 | 698 | while (n) { | 76 | 400 | *--p = '0' + n % 10; | 77 | 400 | n /= 10; | 78 | 400 | if (n == 0) { | 79 | 0 | break; | 80 | 0 | } | 81 | | | 82 | 400 | *--p = '0' + n % 10; | 83 | 400 | n /= 10; | 84 | 400 | if (n == 0) { | 85 | 8 | break; | 86 | 8 | } | 87 | | | 88 | 392 | *--p = ','; | 89 | 392 | *--p = '0' + n % 10; | 90 | 392 | n /= 10; | 91 | | // For this unrolling, we check if n == 0 in the main while loop | 92 | 392 | } | 93 | 306 | if (i < 0) { | 94 | 76 | *--p = '-'; | 95 | 76 | } | 96 | 306 | return p; | 97 | 306 | } |
|
98 | | |
99 | | namespace MoneyFormat { |
100 | | |
101 | 0 | constexpr size_t MAX_FORMAT_LEN_DEC32() { |
102 | 0 | // Decimal(9, 0) |
103 | 0 | // Double the size to avoid some unexpected bug. |
104 | 0 | return 2 * (1 + 9 + (9 / 3) + 3); |
105 | 0 | } |
106 | | |
107 | 0 | constexpr size_t MAX_FORMAT_LEN_DEC64() { |
108 | 0 | // Decimal(18, 0) |
109 | 0 | // Double the size to avoid some unexpected bug. |
110 | 0 | return 2 * (1 + 18 + (18 / 3) + 3); |
111 | 0 | } |
112 | | |
113 | 0 | constexpr size_t MAX_FORMAT_LEN_DEC128V2() { |
114 | 0 | // DecimalV2 has at most 27 digits |
115 | 0 | // Double the size to avoid some unexpected bug. |
116 | 0 | return 2 * (1 + 27 + (27 / 3) + 3); |
117 | 0 | } |
118 | | |
119 | 0 | constexpr size_t MAX_FORMAT_LEN_DEC128V3() { |
120 | 0 | // Decimal(38, 0) |
121 | 0 | // Double the size to avoid some unexpected bug. |
122 | 0 | return 2 * (1 + 39 + (39 / 3) + 3); |
123 | 0 | } |
124 | | |
125 | 0 | constexpr size_t MAX_FORMAT_LEN_INT64() { |
126 | 0 | // INT_MIN = -9223372036854775807 |
127 | 0 | // Double the size to avoid some unexpected bug. |
128 | 0 | return 2 * (1 + 20 + (20 / 3) + 3); |
129 | 0 | } |
130 | | |
131 | 0 | constexpr size_t MAX_FORMAT_LEN_INT128() { |
132 | 0 | // INT128_MIN = -170141183460469231731687303715884105728 |
133 | 0 | return 2 * (1 + 39 + (39 / 3) + 3); |
134 | 0 | } |
135 | | |
136 | | template <typename T, size_t N> |
137 | 31 | StringRef do_money_format(FunctionContext* context, UInt32 scale, T int_value, T frac_value) { |
138 | 31 | static_assert(std::is_integral<T>::value); |
139 | 31 | const bool is_negative = int_value < 0 || frac_value < 0; |
140 | | |
141 | | // do round to frac_part |
142 | | // magic number 2: since we need to round frac_part to 2 digits |
143 | 31 | if (scale > 2) { |
144 | 25 | DCHECK(scale <= 38); |
145 | | // do rounding, so we need to reserve 3 digits. |
146 | 25 | auto multiplier = common::exp10_i128(std::abs(static_cast<int>(scale - 3))); |
147 | | // do devide first to avoid overflow |
148 | | // after round frac_value will be positive by design. |
149 | 25 | frac_value = std::abs(static_cast<int>(frac_value / multiplier)) + 5; |
150 | 25 | frac_value /= 10; |
151 | 25 | } else if (scale < 2) { |
152 | 6 | DCHECK(frac_value < 100); |
153 | | // since scale <= 2, overflow is impossiable |
154 | 6 | frac_value = frac_value * common::exp10_i32(2 - scale); |
155 | 6 | } |
156 | | |
157 | 31 | if (frac_value == 100) { |
158 | 3 | if (is_negative) { |
159 | 2 | int_value -= 1; |
160 | 2 | } else { |
161 | 1 | int_value += 1; |
162 | 1 | } |
163 | 3 | frac_value = 0; |
164 | 3 | } |
165 | | |
166 | 31 | bool append_sign_manually = false; |
167 | 31 | if (is_negative && int_value == 0) { |
168 | | // when int_value is 0, result of SimpleItoaWithCommas will contains just zero |
169 | | // for Decimal like -0.1234, this will leads to problem, because negative sign is discarded. |
170 | | // this is why we introduce argument append_sing_manually. |
171 | 2 | append_sign_manually = true; |
172 | 2 | } |
173 | | |
174 | 31 | char local[N]; |
175 | 31 | char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local)); |
176 | 31 | const Int32 integer_str_len = N - (p - local); |
177 | 31 | const Int32 frac_str_len = 2; |
178 | 31 | const Int32 whole_decimal_str_len = |
179 | 31 | (append_sign_manually ? 1 : 0) + integer_str_len + 1 + frac_str_len; |
180 | | |
181 | 31 | StringRef result = context->create_temp_string_val(whole_decimal_str_len); |
182 | | // Modify a string passed via stringref |
183 | 31 | char* result_data = const_cast<char*>(result.data); |
184 | | |
185 | 31 | if (append_sign_manually) { |
186 | 2 | memset(result_data, '-', 1); |
187 | 2 | } |
188 | | |
189 | 31 | memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len); |
190 | 31 | *(result_data + whole_decimal_str_len - 3) = '.'; |
191 | 31 | *(result_data + whole_decimal_str_len - 2) = '0' + std::abs(static_cast<int>(frac_value / 10)); |
192 | 31 | *(result_data + whole_decimal_str_len - 1) = '0' + std::abs(static_cast<int>(frac_value % 10)); |
193 | 31 | return result; |
194 | 31 | }; _ZN5doris11MoneyFormat15do_money_formatInLm80EEENS_9StringRefEPNS_15FunctionContextEjT_S5_ Line | Count | Source | 137 | 14 | StringRef do_money_format(FunctionContext* context, UInt32 scale, T int_value, T frac_value) { | 138 | 14 | static_assert(std::is_integral<T>::value); | 139 | 14 | const bool is_negative = int_value < 0 || frac_value < 0; | 140 | | | 141 | | // do round to frac_part | 142 | | // magic number 2: since we need to round frac_part to 2 digits | 143 | 14 | if (scale > 2) { | 144 | 14 | DCHECK(scale <= 38); | 145 | | // do rounding, so we need to reserve 3 digits. | 146 | 14 | auto multiplier = common::exp10_i128(std::abs(static_cast<int>(scale - 3))); | 147 | | // do devide first to avoid overflow | 148 | | // after round frac_value will be positive by design. | 149 | 14 | frac_value = std::abs(static_cast<int>(frac_value / multiplier)) + 5; | 150 | 14 | frac_value /= 10; | 151 | 14 | } else if (scale < 2) { | 152 | 0 | DCHECK(frac_value < 100); | 153 | | // since scale <= 2, overflow is impossiable | 154 | 0 | frac_value = frac_value * common::exp10_i32(2 - scale); | 155 | 0 | } | 156 | | | 157 | 14 | if (frac_value == 100) { | 158 | 3 | if (is_negative) { | 159 | 2 | int_value -= 1; | 160 | 2 | } else { | 161 | 1 | int_value += 1; | 162 | 1 | } | 163 | 3 | frac_value = 0; | 164 | 3 | } | 165 | | | 166 | 14 | bool append_sign_manually = false; | 167 | 14 | if (is_negative && int_value == 0) { | 168 | | // when int_value is 0, result of SimpleItoaWithCommas will contains just zero | 169 | | // for Decimal like -0.1234, this will leads to problem, because negative sign is discarded. | 170 | | // this is why we introduce argument append_sing_manually. | 171 | 2 | append_sign_manually = true; | 172 | 2 | } | 173 | | | 174 | 14 | char local[N]; | 175 | 14 | char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local)); | 176 | 14 | const Int32 integer_str_len = N - (p - local); | 177 | 14 | const Int32 frac_str_len = 2; | 178 | 14 | const Int32 whole_decimal_str_len = | 179 | 14 | (append_sign_manually ? 1 : 0) + integer_str_len + 1 + frac_str_len; | 180 | | | 181 | 14 | StringRef result = context->create_temp_string_val(whole_decimal_str_len); | 182 | | // Modify a string passed via stringref | 183 | 14 | char* result_data = const_cast<char*>(result.data); | 184 | | | 185 | 14 | if (append_sign_manually) { | 186 | 2 | memset(result_data, '-', 1); | 187 | 2 | } | 188 | | | 189 | 14 | memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len); | 190 | 14 | *(result_data + whole_decimal_str_len - 3) = '.'; | 191 | 14 | *(result_data + whole_decimal_str_len - 2) = '0' + std::abs(static_cast<int>(frac_value / 10)); | 192 | 14 | *(result_data + whole_decimal_str_len - 1) = '0' + std::abs(static_cast<int>(frac_value % 10)); | 193 | 14 | return result; | 194 | 14 | }; |
_ZN5doris11MoneyFormat15do_money_formatIlLm32EEENS_9StringRefEPNS_15FunctionContextEjT_S5_ Line | Count | Source | 137 | 2 | StringRef do_money_format(FunctionContext* context, UInt32 scale, T int_value, T frac_value) { | 138 | 2 | static_assert(std::is_integral<T>::value); | 139 | 2 | const bool is_negative = int_value < 0 || frac_value < 0; | 140 | | | 141 | | // do round to frac_part | 142 | | // magic number 2: since we need to round frac_part to 2 digits | 143 | 2 | if (scale > 2) { | 144 | 2 | DCHECK(scale <= 38); | 145 | | // do rounding, so we need to reserve 3 digits. | 146 | 2 | auto multiplier = common::exp10_i128(std::abs(static_cast<int>(scale - 3))); | 147 | | // do devide first to avoid overflow | 148 | | // after round frac_value will be positive by design. | 149 | 2 | frac_value = std::abs(static_cast<int>(frac_value / multiplier)) + 5; | 150 | 2 | frac_value /= 10; | 151 | 2 | } else if (scale < 2) { | 152 | 0 | DCHECK(frac_value < 100); | 153 | | // since scale <= 2, overflow is impossiable | 154 | 0 | frac_value = frac_value * common::exp10_i32(2 - scale); | 155 | 0 | } | 156 | | | 157 | 2 | if (frac_value == 100) { | 158 | 0 | if (is_negative) { | 159 | 0 | int_value -= 1; | 160 | 0 | } else { | 161 | 0 | int_value += 1; | 162 | 0 | } | 163 | 0 | frac_value = 0; | 164 | 0 | } | 165 | | | 166 | 2 | bool append_sign_manually = false; | 167 | 2 | if (is_negative && int_value == 0) { | 168 | | // when int_value is 0, result of SimpleItoaWithCommas will contains just zero | 169 | | // for Decimal like -0.1234, this will leads to problem, because negative sign is discarded. | 170 | | // this is why we introduce argument append_sing_manually. | 171 | 0 | append_sign_manually = true; | 172 | 0 | } | 173 | | | 174 | 2 | char local[N]; | 175 | 2 | char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local)); | 176 | 2 | const Int32 integer_str_len = N - (p - local); | 177 | 2 | const Int32 frac_str_len = 2; | 178 | 2 | const Int32 whole_decimal_str_len = | 179 | 2 | (append_sign_manually ? 1 : 0) + integer_str_len + 1 + frac_str_len; | 180 | | | 181 | 2 | StringRef result = context->create_temp_string_val(whole_decimal_str_len); | 182 | | // Modify a string passed via stringref | 183 | 2 | char* result_data = const_cast<char*>(result.data); | 184 | | | 185 | 2 | if (append_sign_manually) { | 186 | 0 | memset(result_data, '-', 1); | 187 | 0 | } | 188 | | | 189 | 2 | memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len); | 190 | 2 | *(result_data + whole_decimal_str_len - 3) = '.'; | 191 | 2 | *(result_data + whole_decimal_str_len - 2) = '0' + std::abs(static_cast<int>(frac_value / 10)); | 192 | 2 | *(result_data + whole_decimal_str_len - 1) = '0' + std::abs(static_cast<int>(frac_value % 10)); | 193 | 2 | return result; | 194 | 2 | }; |
_ZN5doris11MoneyFormat15do_money_formatIlLm56EEENS_9StringRefEPNS_15FunctionContextEjT_S5_ Line | Count | Source | 137 | 7 | StringRef do_money_format(FunctionContext* context, UInt32 scale, T int_value, T frac_value) { | 138 | 7 | static_assert(std::is_integral<T>::value); | 139 | 7 | const bool is_negative = int_value < 0 || frac_value < 0; | 140 | | | 141 | | // do round to frac_part | 142 | | // magic number 2: since we need to round frac_part to 2 digits | 143 | 7 | if (scale > 2) { | 144 | 7 | DCHECK(scale <= 38); | 145 | | // do rounding, so we need to reserve 3 digits. | 146 | 7 | auto multiplier = common::exp10_i128(std::abs(static_cast<int>(scale - 3))); | 147 | | // do devide first to avoid overflow | 148 | | // after round frac_value will be positive by design. | 149 | 7 | frac_value = std::abs(static_cast<int>(frac_value / multiplier)) + 5; | 150 | 7 | frac_value /= 10; | 151 | 7 | } else if (scale < 2) { | 152 | 0 | DCHECK(frac_value < 100); | 153 | | // since scale <= 2, overflow is impossiable | 154 | 0 | frac_value = frac_value * common::exp10_i32(2 - scale); | 155 | 0 | } | 156 | | | 157 | 7 | if (frac_value == 100) { | 158 | 0 | if (is_negative) { | 159 | 0 | int_value -= 1; | 160 | 0 | } else { | 161 | 0 | int_value += 1; | 162 | 0 | } | 163 | 0 | frac_value = 0; | 164 | 0 | } | 165 | | | 166 | 7 | bool append_sign_manually = false; | 167 | 7 | if (is_negative && int_value == 0) { | 168 | | // when int_value is 0, result of SimpleItoaWithCommas will contains just zero | 169 | | // for Decimal like -0.1234, this will leads to problem, because negative sign is discarded. | 170 | | // this is why we introduce argument append_sing_manually. | 171 | 0 | append_sign_manually = true; | 172 | 0 | } | 173 | | | 174 | 7 | char local[N]; | 175 | 7 | char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local)); | 176 | 7 | const Int32 integer_str_len = N - (p - local); | 177 | 7 | const Int32 frac_str_len = 2; | 178 | 7 | const Int32 whole_decimal_str_len = | 179 | 7 | (append_sign_manually ? 1 : 0) + integer_str_len + 1 + frac_str_len; | 180 | | | 181 | 7 | StringRef result = context->create_temp_string_val(whole_decimal_str_len); | 182 | | // Modify a string passed via stringref | 183 | 7 | char* result_data = const_cast<char*>(result.data); | 184 | | | 185 | 7 | if (append_sign_manually) { | 186 | 0 | memset(result_data, '-', 1); | 187 | 0 | } | 188 | | | 189 | 7 | memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len); | 190 | 7 | *(result_data + whole_decimal_str_len - 3) = '.'; | 191 | 7 | *(result_data + whole_decimal_str_len - 2) = '0' + std::abs(static_cast<int>(frac_value / 10)); | 192 | 7 | *(result_data + whole_decimal_str_len - 1) = '0' + std::abs(static_cast<int>(frac_value % 10)); | 193 | 7 | return result; | 194 | 7 | }; |
_ZN5doris11MoneyFormat15do_money_formatInLm112EEENS_9StringRefEPNS_15FunctionContextEjT_S5_ Line | Count | Source | 137 | 5 | StringRef do_money_format(FunctionContext* context, UInt32 scale, T int_value, T frac_value) { | 138 | 5 | static_assert(std::is_integral<T>::value); | 139 | 5 | const bool is_negative = int_value < 0 || frac_value < 0; | 140 | | | 141 | | // do round to frac_part | 142 | | // magic number 2: since we need to round frac_part to 2 digits | 143 | 5 | if (scale > 2) { | 144 | 2 | DCHECK(scale <= 38); | 145 | | // do rounding, so we need to reserve 3 digits. | 146 | 2 | auto multiplier = common::exp10_i128(std::abs(static_cast<int>(scale - 3))); | 147 | | // do devide first to avoid overflow | 148 | | // after round frac_value will be positive by design. | 149 | 2 | frac_value = std::abs(static_cast<int>(frac_value / multiplier)) + 5; | 150 | 2 | frac_value /= 10; | 151 | 3 | } else if (scale < 2) { | 152 | 3 | DCHECK(frac_value < 100); | 153 | | // since scale <= 2, overflow is impossiable | 154 | 3 | frac_value = frac_value * common::exp10_i32(2 - scale); | 155 | 3 | } | 156 | | | 157 | 5 | if (frac_value == 100) { | 158 | 0 | if (is_negative) { | 159 | 0 | int_value -= 1; | 160 | 0 | } else { | 161 | 0 | int_value += 1; | 162 | 0 | } | 163 | 0 | frac_value = 0; | 164 | 0 | } | 165 | | | 166 | 5 | bool append_sign_manually = false; | 167 | 5 | if (is_negative && int_value == 0) { | 168 | | // when int_value is 0, result of SimpleItoaWithCommas will contains just zero | 169 | | // for Decimal like -0.1234, this will leads to problem, because negative sign is discarded. | 170 | | // this is why we introduce argument append_sing_manually. | 171 | 0 | append_sign_manually = true; | 172 | 0 | } | 173 | | | 174 | 5 | char local[N]; | 175 | 5 | char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local)); | 176 | 5 | const Int32 integer_str_len = N - (p - local); | 177 | 5 | const Int32 frac_str_len = 2; | 178 | 5 | const Int32 whole_decimal_str_len = | 179 | 5 | (append_sign_manually ? 1 : 0) + integer_str_len + 1 + frac_str_len; | 180 | | | 181 | 5 | StringRef result = context->create_temp_string_val(whole_decimal_str_len); | 182 | | // Modify a string passed via stringref | 183 | 5 | char* result_data = const_cast<char*>(result.data); | 184 | | | 185 | 5 | if (append_sign_manually) { | 186 | 0 | memset(result_data, '-', 1); | 187 | 0 | } | 188 | | | 189 | 5 | memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len); | 190 | 5 | *(result_data + whole_decimal_str_len - 3) = '.'; | 191 | 5 | *(result_data + whole_decimal_str_len - 2) = '0' + std::abs(static_cast<int>(frac_value / 10)); | 192 | 5 | *(result_data + whole_decimal_str_len - 1) = '0' + std::abs(static_cast<int>(frac_value % 10)); | 193 | 5 | return result; | 194 | 5 | }; |
_ZN5doris11MoneyFormat15do_money_formatIlLm60EEENS_9StringRefEPNS_15FunctionContextEjT_S5_ Line | Count | Source | 137 | 3 | StringRef do_money_format(FunctionContext* context, UInt32 scale, T int_value, T frac_value) { | 138 | 3 | static_assert(std::is_integral<T>::value); | 139 | 3 | const bool is_negative = int_value < 0 || frac_value < 0; | 140 | | | 141 | | // do round to frac_part | 142 | | // magic number 2: since we need to round frac_part to 2 digits | 143 | 3 | if (scale > 2) { | 144 | 0 | DCHECK(scale <= 38); | 145 | | // do rounding, so we need to reserve 3 digits. | 146 | 0 | auto multiplier = common::exp10_i128(std::abs(static_cast<int>(scale - 3))); | 147 | | // do devide first to avoid overflow | 148 | | // after round frac_value will be positive by design. | 149 | 0 | frac_value = std::abs(static_cast<int>(frac_value / multiplier)) + 5; | 150 | 0 | frac_value /= 10; | 151 | 3 | } else if (scale < 2) { | 152 | 3 | DCHECK(frac_value < 100); | 153 | | // since scale <= 2, overflow is impossiable | 154 | 3 | frac_value = frac_value * common::exp10_i32(2 - scale); | 155 | 3 | } | 156 | | | 157 | 3 | if (frac_value == 100) { | 158 | 0 | if (is_negative) { | 159 | 0 | int_value -= 1; | 160 | 0 | } else { | 161 | 0 | int_value += 1; | 162 | 0 | } | 163 | 0 | frac_value = 0; | 164 | 0 | } | 165 | | | 166 | 3 | bool append_sign_manually = false; | 167 | 3 | if (is_negative && int_value == 0) { | 168 | | // when int_value is 0, result of SimpleItoaWithCommas will contains just zero | 169 | | // for Decimal like -0.1234, this will leads to problem, because negative sign is discarded. | 170 | | // this is why we introduce argument append_sing_manually. | 171 | 0 | append_sign_manually = true; | 172 | 0 | } | 173 | | | 174 | 3 | char local[N]; | 175 | 3 | char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local)); | 176 | 3 | const Int32 integer_str_len = N - (p - local); | 177 | 3 | const Int32 frac_str_len = 2; | 178 | 3 | const Int32 whole_decimal_str_len = | 179 | 3 | (append_sign_manually ? 1 : 0) + integer_str_len + 1 + frac_str_len; | 180 | | | 181 | 3 | StringRef result = context->create_temp_string_val(whole_decimal_str_len); | 182 | | // Modify a string passed via stringref | 183 | 3 | char* result_data = const_cast<char*>(result.data); | 184 | | | 185 | 3 | if (append_sign_manually) { | 186 | 0 | memset(result_data, '-', 1); | 187 | 0 | } | 188 | | | 189 | 3 | memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len); | 190 | 3 | *(result_data + whole_decimal_str_len - 3) = '.'; | 191 | 3 | *(result_data + whole_decimal_str_len - 2) = '0' + std::abs(static_cast<int>(frac_value / 10)); | 192 | 3 | *(result_data + whole_decimal_str_len - 1) = '0' + std::abs(static_cast<int>(frac_value % 10)); | 193 | 3 | return result; | 194 | 3 | }; |
|
195 | | |
196 | | // Note string value must be valid decimal string which contains two digits after the decimal point |
197 | 4 | static StringRef do_money_format(FunctionContext* context, const std::string& value) { |
198 | 4 | bool is_positive = (value[0] != '-'); |
199 | 4 | int32_t result_len = value.size() + (value.size() - (is_positive ? 4 : 5)) / 3; |
200 | 4 | StringRef result = context->create_temp_string_val(result_len); |
201 | | // Modify a string passed via stringref |
202 | 4 | char* result_data = const_cast<char*>(result.data); |
203 | 4 | if (!is_positive) { |
204 | 2 | *result_data = '-'; |
205 | 2 | } |
206 | 10 | for (int i = value.size() - 4, j = result_len - 4; i >= 0; i = i - 3) { |
207 | 9 | *(result_data + j) = *(value.data() + i); |
208 | 9 | if (i - 1 < 0) { |
209 | 2 | break; |
210 | 2 | } |
211 | 7 | *(result_data + j - 1) = *(value.data() + i - 1); |
212 | 7 | if (i - 2 < 0) { |
213 | 1 | break; |
214 | 1 | } |
215 | 6 | *(result_data + j - 2) = *(value.data() + i - 2); |
216 | 6 | if (j - 3 > 1 || (j - 3 == 1 && is_positive)) { |
217 | 4 | *(result_data + j - 3) = ','; |
218 | 4 | j -= 4; |
219 | 4 | } else { |
220 | 2 | j -= 3; |
221 | 2 | } |
222 | 6 | } |
223 | 4 | memcpy(result_data + result_len - 3, value.data() + value.size() - 3, 3); |
224 | 4 | return result; |
225 | 4 | }; Unexecuted instantiation: function_money_format_test.cpp:_ZN5doris11MoneyFormatL15do_money_formatEPNS_15FunctionContextERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE unity_20_cxx.cxx:_ZN5doris11MoneyFormatL15do_money_formatEPNS_15FunctionContextERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE Line | Count | Source | 197 | 4 | static StringRef do_money_format(FunctionContext* context, const std::string& value) { | 198 | 4 | bool is_positive = (value[0] != '-'); | 199 | 4 | int32_t result_len = value.size() + (value.size() - (is_positive ? 4 : 5)) / 3; | 200 | 4 | StringRef result = context->create_temp_string_val(result_len); | 201 | | // Modify a string passed via stringref | 202 | 4 | char* result_data = const_cast<char*>(result.data); | 203 | 4 | if (!is_positive) { | 204 | 2 | *result_data = '-'; | 205 | 2 | } | 206 | 10 | for (int i = value.size() - 4, j = result_len - 4; i >= 0; i = i - 3) { | 207 | 9 | *(result_data + j) = *(value.data() + i); | 208 | 9 | if (i - 1 < 0) { | 209 | 2 | break; | 210 | 2 | } | 211 | 7 | *(result_data + j - 1) = *(value.data() + i - 1); | 212 | 7 | if (i - 2 < 0) { | 213 | 1 | break; | 214 | 1 | } | 215 | 6 | *(result_data + j - 2) = *(value.data() + i - 2); | 216 | 6 | if (j - 3 > 1 || (j - 3 == 1 && is_positive)) { | 217 | 4 | *(result_data + j - 3) = ','; | 218 | 4 | j -= 4; | 219 | 4 | } else { | 220 | 2 | j -= 3; | 221 | 2 | } | 222 | 6 | } | 223 | 4 | memcpy(result_data + result_len - 3, value.data() + value.size() - 3, 3); | 224 | 4 | return result; | 225 | 4 | }; |
|
226 | | |
227 | | } // namespace MoneyFormat |
228 | | |
229 | | namespace FormatRound { |
230 | | |
231 | 0 | constexpr size_t MAX_FORMAT_LEN_DEC32() { |
232 | 0 | // Decimal(9, 0) |
233 | 0 | // Double the size to avoid some unexpected bug. |
234 | 0 | return 2 * (1 + 9 + (9 / 3) + 3); |
235 | 0 | } |
236 | | |
237 | 0 | constexpr size_t MAX_FORMAT_LEN_DEC64() { |
238 | 0 | // Decimal(18, 0) |
239 | 0 | // Double the size to avoid some unexpected bug. |
240 | 0 | return 2 * (1 + 18 + (18 / 3) + 3); |
241 | 0 | } |
242 | | |
243 | 0 | constexpr size_t MAX_FORMAT_LEN_DEC128V2() { |
244 | 0 | // DecimalV2 has at most 27 digits |
245 | 0 | // Double the size to avoid some unexpected bug. |
246 | 0 | return 2 * (1 + 27 + (27 / 3) + 3); |
247 | 0 | } |
248 | | |
249 | 0 | constexpr size_t MAX_FORMAT_LEN_DEC128V3() { |
250 | 0 | // Decimal(38, 0) |
251 | 0 | // Double the size to avoid some unexpected bug. |
252 | 0 | return 2 * (1 + 39 + (39 / 3) + 3); |
253 | 0 | } |
254 | | |
255 | 0 | constexpr size_t MAX_FORMAT_LEN_DEC256() { |
256 | 0 | // Decimal(76, 0) |
257 | 0 | // Double the size to match the other decimal buffers. |
258 | 0 | return 2 * (1 + 76 + (76 / 3) + 3); |
259 | 0 | } |
260 | | |
261 | 0 | constexpr size_t MAX_FORMAT_LEN_INT64() { |
262 | 0 | // INT_MIN = -9223372036854775807 |
263 | 0 | // Double the size to avoid some unexpected bug. |
264 | 0 | return 2 * (1 + 20 + (20 / 3) + 3); |
265 | 0 | } |
266 | | |
267 | 0 | constexpr size_t MAX_FORMAT_LEN_INT128() { |
268 | 0 | // INT128_MIN = -170141183460469231731687303715884105728 |
269 | 0 | return 2 * (1 + 39 + (39 / 3) + 3); |
270 | 0 | } |
271 | | |
272 | | template <typename T, size_t N> |
273 | | StringRef do_format_round(FunctionContext* context, UInt32 scale, T int_value, T frac_value, |
274 | 1.14k | Int32 decimal_places) { |
275 | 1.14k | static_assert(IsIntegralV<T>); |
276 | 1.14k | const bool is_negative = int_value < 0 || frac_value < 0; |
277 | 1.14k | frac_value = frac_value < 0 ? -frac_value : frac_value; |
278 | | |
279 | | // do round to frac_part based on decimal_places |
280 | 1.14k | if (static_cast<Int32>(scale) > decimal_places) { |
281 | 155 | DCHECK(scale <= std::numeric_limits<T>::digits10); |
282 | | // do rounding, so we need to reserve decimal_places + 1 digits |
283 | 155 | auto multiplier = decimal_scale_multiplier<T>(scale - (decimal_places + 1)); |
284 | | // do divide first to avoid overflow |
285 | 155 | frac_value = (frac_value / multiplier + 5) / 10; |
286 | 155 | scale = decimal_places; |
287 | | |
288 | 155 | if (frac_value == decimal_scale_multiplier<T>(scale)) { |
289 | 96 | if (is_negative) { |
290 | 48 | int_value -= 1; |
291 | 48 | } else { |
292 | 48 | int_value += 1; |
293 | 48 | } |
294 | 96 | frac_value = 0; |
295 | 96 | } |
296 | 155 | } |
297 | | |
298 | 1.14k | bool append_sign_manually = false; |
299 | 1.14k | if (is_negative && int_value == 0) { |
300 | 212 | append_sign_manually = true; |
301 | 212 | } |
302 | | |
303 | 1.14k | char local[N]; |
304 | 1.14k | char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local)); |
305 | 1.14k | const Int32 integer_str_len = N - (p - local); |
306 | 1.14k | const Int32 frac_str_len = decimal_places; |
307 | 1.14k | const Int32 whole_decimal_str_len = (append_sign_manually ? 1 : 0) + integer_str_len + |
308 | 1.14k | (decimal_places > 0 ? 1 : 0) + frac_str_len; |
309 | | |
310 | 1.14k | StringRef result = context->create_temp_string_val(whole_decimal_str_len); |
311 | | // Modify a string passed via stringref |
312 | 1.14k | char* result_data = const_cast<char*>(result.data); |
313 | | |
314 | 1.14k | if (append_sign_manually) { |
315 | 212 | memset(result_data, '-', 1); |
316 | 212 | } |
317 | | |
318 | 1.14k | memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len); |
319 | 1.14k | if (decimal_places > 0) { |
320 | 1.10k | *(result_data + whole_decimal_str_len - (frac_str_len + 1)) = '.'; |
321 | 1.10k | } |
322 | | |
323 | | // Pad on the right without scaling the value: decimal_places can be as large as 1024. |
324 | 1.14k | const Int32 trailing_zeros = decimal_places - scale; |
325 | 1.14k | char* frac_end = result_data + whole_decimal_str_len - trailing_zeros; |
326 | 1.14k | memset(frac_end, '0', trailing_zeros); |
327 | 9.66k | for (UInt32 i = 0; i < scale; ++i) { |
328 | 8.52k | *--frac_end = '0' + (frac_value % 10); |
329 | 8.52k | frac_value /= 10; |
330 | 8.52k | } |
331 | 1.14k | return result; |
332 | 1.14k | } _ZN5doris11FormatRound15do_format_roundIlLm60EEENS_9StringRefEPNS_15FunctionContextEjT_S5_i Line | Count | Source | 274 | 16 | Int32 decimal_places) { | 275 | 16 | static_assert(IsIntegralV<T>); | 276 | 16 | const bool is_negative = int_value < 0 || frac_value < 0; | 277 | 16 | frac_value = frac_value < 0 ? -frac_value : frac_value; | 278 | | | 279 | | // do round to frac_part based on decimal_places | 280 | 16 | if (static_cast<Int32>(scale) > decimal_places) { | 281 | 0 | DCHECK(scale <= std::numeric_limits<T>::digits10); | 282 | | // do rounding, so we need to reserve decimal_places + 1 digits | 283 | 0 | auto multiplier = decimal_scale_multiplier<T>(scale - (decimal_places + 1)); | 284 | | // do divide first to avoid overflow | 285 | 0 | frac_value = (frac_value / multiplier + 5) / 10; | 286 | 0 | scale = decimal_places; | 287 | |
| 288 | 0 | if (frac_value == decimal_scale_multiplier<T>(scale)) { | 289 | 0 | if (is_negative) { | 290 | 0 | int_value -= 1; | 291 | 0 | } else { | 292 | 0 | int_value += 1; | 293 | 0 | } | 294 | 0 | frac_value = 0; | 295 | 0 | } | 296 | 0 | } | 297 | | | 298 | 16 | bool append_sign_manually = false; | 299 | 16 | if (is_negative && int_value == 0) { | 300 | 0 | append_sign_manually = true; | 301 | 0 | } | 302 | | | 303 | 16 | char local[N]; | 304 | 16 | char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local)); | 305 | 16 | const Int32 integer_str_len = N - (p - local); | 306 | 16 | const Int32 frac_str_len = decimal_places; | 307 | 16 | const Int32 whole_decimal_str_len = (append_sign_manually ? 1 : 0) + integer_str_len + | 308 | 16 | (decimal_places > 0 ? 1 : 0) + frac_str_len; | 309 | | | 310 | 16 | StringRef result = context->create_temp_string_val(whole_decimal_str_len); | 311 | | // Modify a string passed via stringref | 312 | 16 | char* result_data = const_cast<char*>(result.data); | 313 | | | 314 | 16 | if (append_sign_manually) { | 315 | 0 | memset(result_data, '-', 1); | 316 | 0 | } | 317 | | | 318 | 16 | memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len); | 319 | 16 | if (decimal_places > 0) { | 320 | 10 | *(result_data + whole_decimal_str_len - (frac_str_len + 1)) = '.'; | 321 | 10 | } | 322 | | | 323 | | // Pad on the right without scaling the value: decimal_places can be as large as 1024. | 324 | 16 | const Int32 trailing_zeros = decimal_places - scale; | 325 | 16 | char* frac_end = result_data + whole_decimal_str_len - trailing_zeros; | 326 | 16 | memset(frac_end, '0', trailing_zeros); | 327 | 16 | for (UInt32 i = 0; i < scale; ++i) { | 328 | 0 | *--frac_end = '0' + (frac_value % 10); | 329 | 0 | frac_value /= 10; | 330 | 0 | } | 331 | 16 | return result; | 332 | 16 | } |
_ZN5doris11FormatRound15do_format_roundInLm112EEENS_9StringRefEPNS_15FunctionContextEjT_S5_i Line | Count | Source | 274 | 405 | Int32 decimal_places) { | 275 | 405 | static_assert(IsIntegralV<T>); | 276 | 405 | const bool is_negative = int_value < 0 || frac_value < 0; | 277 | 405 | frac_value = frac_value < 0 ? -frac_value : frac_value; | 278 | | | 279 | | // do round to frac_part based on decimal_places | 280 | 405 | if (static_cast<Int32>(scale) > decimal_places) { | 281 | 18 | DCHECK(scale <= std::numeric_limits<T>::digits10); | 282 | | // do rounding, so we need to reserve decimal_places + 1 digits | 283 | 18 | auto multiplier = decimal_scale_multiplier<T>(scale - (decimal_places + 1)); | 284 | | // do divide first to avoid overflow | 285 | 18 | frac_value = (frac_value / multiplier + 5) / 10; | 286 | 18 | scale = decimal_places; | 287 | | | 288 | 18 | if (frac_value == decimal_scale_multiplier<T>(scale)) { | 289 | 8 | if (is_negative) { | 290 | 4 | int_value -= 1; | 291 | 4 | } else { | 292 | 4 | int_value += 1; | 293 | 4 | } | 294 | 8 | frac_value = 0; | 295 | 8 | } | 296 | 18 | } | 297 | | | 298 | 405 | bool append_sign_manually = false; | 299 | 405 | if (is_negative && int_value == 0) { | 300 | 80 | append_sign_manually = true; | 301 | 80 | } | 302 | | | 303 | 405 | char local[N]; | 304 | 405 | char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local)); | 305 | 405 | const Int32 integer_str_len = N - (p - local); | 306 | 405 | const Int32 frac_str_len = decimal_places; | 307 | 405 | const Int32 whole_decimal_str_len = (append_sign_manually ? 1 : 0) + integer_str_len + | 308 | 405 | (decimal_places > 0 ? 1 : 0) + frac_str_len; | 309 | | | 310 | 405 | StringRef result = context->create_temp_string_val(whole_decimal_str_len); | 311 | | // Modify a string passed via stringref | 312 | 405 | char* result_data = const_cast<char*>(result.data); | 313 | | | 314 | 405 | if (append_sign_manually) { | 315 | 80 | memset(result_data, '-', 1); | 316 | 80 | } | 317 | | | 318 | 405 | memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len); | 319 | 405 | if (decimal_places > 0) { | 320 | 401 | *(result_data + whole_decimal_str_len - (frac_str_len + 1)) = '.'; | 321 | 401 | } | 322 | | | 323 | | // Pad on the right without scaling the value: decimal_places can be as large as 1024. | 324 | 405 | const Int32 trailing_zeros = decimal_places - scale; | 325 | 405 | char* frac_end = result_data + whole_decimal_str_len - trailing_zeros; | 326 | 405 | memset(frac_end, '0', trailing_zeros); | 327 | 2.10k | for (UInt32 i = 0; i < scale; ++i) { | 328 | 1.70k | *--frac_end = '0' + (frac_value % 10); | 329 | 1.70k | frac_value /= 10; | 330 | 1.70k | } | 331 | 405 | return result; | 332 | 405 | } |
_ZN5doris11FormatRound15do_format_roundInLm80EEENS_9StringRefEPNS_15FunctionContextEjT_S5_i Line | Count | Source | 274 | 3 | Int32 decimal_places) { | 275 | 3 | static_assert(IsIntegralV<T>); | 276 | 3 | const bool is_negative = int_value < 0 || frac_value < 0; | 277 | 3 | frac_value = frac_value < 0 ? -frac_value : frac_value; | 278 | | | 279 | | // do round to frac_part based on decimal_places | 280 | 3 | if (static_cast<Int32>(scale) > decimal_places) { | 281 | 3 | DCHECK(scale <= std::numeric_limits<T>::digits10); | 282 | | // do rounding, so we need to reserve decimal_places + 1 digits | 283 | 3 | auto multiplier = decimal_scale_multiplier<T>(scale - (decimal_places + 1)); | 284 | | // do divide first to avoid overflow | 285 | 3 | frac_value = (frac_value / multiplier + 5) / 10; | 286 | 3 | scale = decimal_places; | 287 | | | 288 | 3 | if (frac_value == decimal_scale_multiplier<T>(scale)) { | 289 | 0 | if (is_negative) { | 290 | 0 | int_value -= 1; | 291 | 0 | } else { | 292 | 0 | int_value += 1; | 293 | 0 | } | 294 | 0 | frac_value = 0; | 295 | 0 | } | 296 | 3 | } | 297 | | | 298 | 3 | bool append_sign_manually = false; | 299 | 3 | if (is_negative && int_value == 0) { | 300 | 0 | append_sign_manually = true; | 301 | 0 | } | 302 | | | 303 | 3 | char local[N]; | 304 | 3 | char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local)); | 305 | 3 | const Int32 integer_str_len = N - (p - local); | 306 | 3 | const Int32 frac_str_len = decimal_places; | 307 | 3 | const Int32 whole_decimal_str_len = (append_sign_manually ? 1 : 0) + integer_str_len + | 308 | 3 | (decimal_places > 0 ? 1 : 0) + frac_str_len; | 309 | | | 310 | 3 | StringRef result = context->create_temp_string_val(whole_decimal_str_len); | 311 | | // Modify a string passed via stringref | 312 | 3 | char* result_data = const_cast<char*>(result.data); | 313 | | | 314 | 3 | if (append_sign_manually) { | 315 | 0 | memset(result_data, '-', 1); | 316 | 0 | } | 317 | | | 318 | 3 | memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len); | 319 | 3 | if (decimal_places > 0) { | 320 | 3 | *(result_data + whole_decimal_str_len - (frac_str_len + 1)) = '.'; | 321 | 3 | } | 322 | | | 323 | | // Pad on the right without scaling the value: decimal_places can be as large as 1024. | 324 | 3 | const Int32 trailing_zeros = decimal_places - scale; | 325 | 3 | char* frac_end = result_data + whole_decimal_str_len - trailing_zeros; | 326 | 3 | memset(frac_end, '0', trailing_zeros); | 327 | 9 | for (UInt32 i = 0; i < scale; ++i) { | 328 | 6 | *--frac_end = '0' + (frac_value % 10); | 329 | 6 | frac_value /= 10; | 330 | 6 | } | 331 | 3 | return result; | 332 | 3 | } |
_ZN5doris11FormatRound15do_format_roundIlLm32EEENS_9StringRefEPNS_15FunctionContextEjT_S5_i Line | Count | Source | 274 | 182 | Int32 decimal_places) { | 275 | 182 | static_assert(IsIntegralV<T>); | 276 | 182 | const bool is_negative = int_value < 0 || frac_value < 0; | 277 | 182 | frac_value = frac_value < 0 ? -frac_value : frac_value; | 278 | | | 279 | | // do round to frac_part based on decimal_places | 280 | 182 | if (static_cast<Int32>(scale) > decimal_places) { | 281 | 1 | DCHECK(scale <= std::numeric_limits<T>::digits10); | 282 | | // do rounding, so we need to reserve decimal_places + 1 digits | 283 | 1 | auto multiplier = decimal_scale_multiplier<T>(scale - (decimal_places + 1)); | 284 | | // do divide first to avoid overflow | 285 | 1 | frac_value = (frac_value / multiplier + 5) / 10; | 286 | 1 | scale = decimal_places; | 287 | | | 288 | 1 | if (frac_value == decimal_scale_multiplier<T>(scale)) { | 289 | 0 | if (is_negative) { | 290 | 0 | int_value -= 1; | 291 | 0 | } else { | 292 | 0 | int_value += 1; | 293 | 0 | } | 294 | 0 | frac_value = 0; | 295 | 0 | } | 296 | 1 | } | 297 | | | 298 | 182 | bool append_sign_manually = false; | 299 | 182 | if (is_negative && int_value == 0) { | 300 | 36 | append_sign_manually = true; | 301 | 36 | } | 302 | | | 303 | 182 | char local[N]; | 304 | 182 | char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local)); | 305 | 182 | const Int32 integer_str_len = N - (p - local); | 306 | 182 | const Int32 frac_str_len = decimal_places; | 307 | 182 | const Int32 whole_decimal_str_len = (append_sign_manually ? 1 : 0) + integer_str_len + | 308 | 182 | (decimal_places > 0 ? 1 : 0) + frac_str_len; | 309 | | | 310 | 182 | StringRef result = context->create_temp_string_val(whole_decimal_str_len); | 311 | | // Modify a string passed via stringref | 312 | 182 | char* result_data = const_cast<char*>(result.data); | 313 | | | 314 | 182 | if (append_sign_manually) { | 315 | 36 | memset(result_data, '-', 1); | 316 | 36 | } | 317 | | | 318 | 182 | memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len); | 319 | 182 | if (decimal_places > 0) { | 320 | 181 | *(result_data + whole_decimal_str_len - (frac_str_len + 1)) = '.'; | 321 | 181 | } | 322 | | | 323 | | // Pad on the right without scaling the value: decimal_places can be as large as 1024. | 324 | 182 | const Int32 trailing_zeros = decimal_places - scale; | 325 | 182 | char* frac_end = result_data + whole_decimal_str_len - trailing_zeros; | 326 | 182 | memset(frac_end, '0', trailing_zeros); | 327 | 544 | for (UInt32 i = 0; i < scale; ++i) { | 328 | 362 | *--frac_end = '0' + (frac_value % 10); | 329 | 362 | frac_value /= 10; | 330 | 362 | } | 331 | 182 | return result; | 332 | 182 | } |
_ZN5doris11FormatRound15do_format_roundIlLm56EEENS_9StringRefEPNS_15FunctionContextEjT_S5_i Line | Count | Source | 274 | 233 | Int32 decimal_places) { | 275 | 233 | static_assert(IsIntegralV<T>); | 276 | 233 | const bool is_negative = int_value < 0 || frac_value < 0; | 277 | 233 | frac_value = frac_value < 0 ? -frac_value : frac_value; | 278 | | | 279 | | // do round to frac_part based on decimal_places | 280 | 233 | if (static_cast<Int32>(scale) > decimal_places) { | 281 | 48 | DCHECK(scale <= std::numeric_limits<T>::digits10); | 282 | | // do rounding, so we need to reserve decimal_places + 1 digits | 283 | 48 | auto multiplier = decimal_scale_multiplier<T>(scale - (decimal_places + 1)); | 284 | | // do divide first to avoid overflow | 285 | 48 | frac_value = (frac_value / multiplier + 5) / 10; | 286 | 48 | scale = decimal_places; | 287 | | | 288 | 48 | if (frac_value == decimal_scale_multiplier<T>(scale)) { | 289 | 16 | if (is_negative) { | 290 | 8 | int_value -= 1; | 291 | 8 | } else { | 292 | 8 | int_value += 1; | 293 | 8 | } | 294 | 16 | frac_value = 0; | 295 | 16 | } | 296 | 48 | } | 297 | | | 298 | 233 | bool append_sign_manually = false; | 299 | 233 | if (is_negative && int_value == 0) { | 300 | 40 | append_sign_manually = true; | 301 | 40 | } | 302 | | | 303 | 233 | char local[N]; | 304 | 233 | char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local)); | 305 | 233 | const Int32 integer_str_len = N - (p - local); | 306 | 233 | const Int32 frac_str_len = decimal_places; | 307 | 233 | const Int32 whole_decimal_str_len = (append_sign_manually ? 1 : 0) + integer_str_len + | 308 | 233 | (decimal_places > 0 ? 1 : 0) + frac_str_len; | 309 | | | 310 | 233 | StringRef result = context->create_temp_string_val(whole_decimal_str_len); | 311 | | // Modify a string passed via stringref | 312 | 233 | char* result_data = const_cast<char*>(result.data); | 313 | | | 314 | 233 | if (append_sign_manually) { | 315 | 40 | memset(result_data, '-', 1); | 316 | 40 | } | 317 | | | 318 | 233 | memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len); | 319 | 233 | if (decimal_places > 0) { | 320 | 220 | *(result_data + whole_decimal_str_len - (frac_str_len + 1)) = '.'; | 321 | 220 | } | 322 | | | 323 | | // Pad on the right without scaling the value: decimal_places can be as large as 1024. | 324 | 233 | const Int32 trailing_zeros = decimal_places - scale; | 325 | 233 | char* frac_end = result_data + whole_decimal_str_len - trailing_zeros; | 326 | 233 | memset(frac_end, '0', trailing_zeros); | 327 | 909 | for (UInt32 i = 0; i < scale; ++i) { | 328 | 676 | *--frac_end = '0' + (frac_value % 10); | 329 | 676 | frac_value /= 10; | 330 | 676 | } | 331 | 233 | return result; | 332 | 233 | } |
_ZN5doris11FormatRound15do_format_roundIN4wide7integerILm256EiEELm210EEENS_9StringRefEPNS_15FunctionContextEjT_S8_i Line | Count | Source | 274 | 306 | Int32 decimal_places) { | 275 | 306 | static_assert(IsIntegralV<T>); | 276 | 306 | const bool is_negative = int_value < 0 || frac_value < 0; | 277 | 306 | frac_value = frac_value < 0 ? -frac_value : frac_value; | 278 | | | 279 | | // do round to frac_part based on decimal_places | 280 | 306 | if (static_cast<Int32>(scale) > decimal_places) { | 281 | 85 | DCHECK(scale <= std::numeric_limits<T>::digits10); | 282 | | // do rounding, so we need to reserve decimal_places + 1 digits | 283 | 85 | auto multiplier = decimal_scale_multiplier<T>(scale - (decimal_places + 1)); | 284 | | // do divide first to avoid overflow | 285 | 85 | frac_value = (frac_value / multiplier + 5) / 10; | 286 | 85 | scale = decimal_places; | 287 | | | 288 | 85 | if (frac_value == decimal_scale_multiplier<T>(scale)) { | 289 | 72 | if (is_negative) { | 290 | 36 | int_value -= 1; | 291 | 36 | } else { | 292 | 36 | int_value += 1; | 293 | 36 | } | 294 | 72 | frac_value = 0; | 295 | 72 | } | 296 | 85 | } | 297 | | | 298 | 306 | bool append_sign_manually = false; | 299 | 306 | if (is_negative && int_value == 0) { | 300 | 56 | append_sign_manually = true; | 301 | 56 | } | 302 | | | 303 | 306 | char local[N]; | 304 | 306 | char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local)); | 305 | 306 | const Int32 integer_str_len = N - (p - local); | 306 | 306 | const Int32 frac_str_len = decimal_places; | 307 | 306 | const Int32 whole_decimal_str_len = (append_sign_manually ? 1 : 0) + integer_str_len + | 308 | 306 | (decimal_places > 0 ? 1 : 0) + frac_str_len; | 309 | | | 310 | 306 | StringRef result = context->create_temp_string_val(whole_decimal_str_len); | 311 | | // Modify a string passed via stringref | 312 | 306 | char* result_data = const_cast<char*>(result.data); | 313 | | | 314 | 306 | if (append_sign_manually) { | 315 | 56 | memset(result_data, '-', 1); | 316 | 56 | } | 317 | | | 318 | 306 | memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len); | 319 | 306 | if (decimal_places > 0) { | 320 | 289 | *(result_data + whole_decimal_str_len - (frac_str_len + 1)) = '.'; | 321 | 289 | } | 322 | | | 323 | | // Pad on the right without scaling the value: decimal_places can be as large as 1024. | 324 | 306 | const Int32 trailing_zeros = decimal_places - scale; | 325 | 306 | char* frac_end = result_data + whole_decimal_str_len - trailing_zeros; | 326 | 306 | memset(frac_end, '0', trailing_zeros); | 327 | 6.08k | for (UInt32 i = 0; i < scale; ++i) { | 328 | 5.77k | *--frac_end = '0' + (frac_value % 10); | 329 | 5.77k | frac_value /= 10; | 330 | 5.77k | } | 331 | 306 | return result; | 332 | 306 | } |
|
333 | | |
334 | | } // namespace FormatRound |
335 | | |
336 | | template <typename Impl> |
337 | | class FunctionMoneyFormat : public IFunction { |
338 | | public: |
339 | | static constexpr auto name = "money_format"; |
340 | 31 | static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); }_ZN5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE20EEEE6createEv Line | Count | Source | 340 | 4 | static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); } |
_ZN5doris19FunctionMoneyFormatINS_21MoneyFormatDoubleImplEE6createEv Line | Count | Source | 340 | 3 | static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); } |
_ZN5doris19FunctionMoneyFormatINS_20MoneyFormatInt64ImplEE6createEv Line | Count | Source | 340 | 3 | static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); } |
_ZN5doris19FunctionMoneyFormatINS_21MoneyFormatInt128ImplEE6createEv Line | Count | Source | 340 | 3 | static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); } |
_ZN5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE28EEEE6createEv Line | Count | Source | 340 | 4 | static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); } |
_ZN5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE29EEEE6createEv Line | Count | Source | 340 | 8 | static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); } |
_ZN5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE30EEEE6createEv Line | Count | Source | 340 | 4 | static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); } |
_ZN5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE35EEEE6createEv Line | Count | Source | 340 | 2 | static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); } |
|
341 | 8 | String get_name() const override { return name; }_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE20EEEE8get_nameB5cxx11Ev Line | Count | Source | 341 | 1 | String get_name() const override { return name; } |
_ZNK5doris19FunctionMoneyFormatINS_21MoneyFormatDoubleImplEE8get_nameB5cxx11Ev Line | Count | Source | 341 | 1 | String get_name() const override { return name; } |
_ZNK5doris19FunctionMoneyFormatINS_20MoneyFormatInt64ImplEE8get_nameB5cxx11Ev Line | Count | Source | 341 | 1 | String get_name() const override { return name; } |
_ZNK5doris19FunctionMoneyFormatINS_21MoneyFormatInt128ImplEE8get_nameB5cxx11Ev Line | Count | Source | 341 | 1 | String get_name() const override { return name; } |
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE28EEEE8get_nameB5cxx11Ev Line | Count | Source | 341 | 1 | String get_name() const override { return name; } |
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE29EEEE8get_nameB5cxx11Ev Line | Count | Source | 341 | 1 | String get_name() const override { return name; } |
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE30EEEE8get_nameB5cxx11Ev Line | Count | Source | 341 | 1 | String get_name() const override { return name; } |
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE35EEEE8get_nameB5cxx11Ev Line | Count | Source | 341 | 1 | String get_name() const override { return name; } |
|
342 | | |
343 | 14 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
344 | 14 | if (arguments.size() != 1) { |
345 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, |
346 | 0 | "Function {} requires exactly 1 argument", name); |
347 | 0 | } |
348 | | |
349 | 14 | return std::make_shared<DataTypeString>(); |
350 | 14 | } _ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE20EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE Line | Count | Source | 343 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 344 | 1 | if (arguments.size() != 1) { | 345 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 346 | 0 | "Function {} requires exactly 1 argument", name); | 347 | 0 | } | 348 | | | 349 | 1 | return std::make_shared<DataTypeString>(); | 350 | 1 | } |
_ZNK5doris19FunctionMoneyFormatINS_21MoneyFormatDoubleImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 343 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 344 | 1 | if (arguments.size() != 1) { | 345 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 346 | 0 | "Function {} requires exactly 1 argument", name); | 347 | 0 | } | 348 | | | 349 | 1 | return std::make_shared<DataTypeString>(); | 350 | 1 | } |
_ZNK5doris19FunctionMoneyFormatINS_20MoneyFormatInt64ImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 343 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 344 | 1 | if (arguments.size() != 1) { | 345 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 346 | 0 | "Function {} requires exactly 1 argument", name); | 347 | 0 | } | 348 | | | 349 | 1 | return std::make_shared<DataTypeString>(); | 350 | 1 | } |
_ZNK5doris19FunctionMoneyFormatINS_21MoneyFormatInt128ImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 343 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 344 | 1 | if (arguments.size() != 1) { | 345 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 346 | 0 | "Function {} requires exactly 1 argument", name); | 347 | 0 | } | 348 | | | 349 | 1 | return std::make_shared<DataTypeString>(); | 350 | 1 | } |
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE28EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE Line | Count | Source | 343 | 2 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 344 | 2 | if (arguments.size() != 1) { | 345 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 346 | 0 | "Function {} requires exactly 1 argument", name); | 347 | 0 | } | 348 | | | 349 | 2 | return std::make_shared<DataTypeString>(); | 350 | 2 | } |
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE29EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE Line | Count | Source | 343 | 6 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 344 | 6 | if (arguments.size() != 1) { | 345 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 346 | 0 | "Function {} requires exactly 1 argument", name); | 347 | 0 | } | 348 | | | 349 | 6 | return std::make_shared<DataTypeString>(); | 350 | 6 | } |
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE30EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE Line | Count | Source | 343 | 2 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 344 | 2 | if (arguments.size() != 1) { | 345 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 346 | 0 | "Function {} requires exactly 1 argument", name); | 347 | 0 | } | 348 | | | 349 | 2 | return std::make_shared<DataTypeString>(); | 350 | 2 | } |
Unexecuted instantiation: _ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE35EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE |
351 | 8 | DataTypes get_variadic_argument_types_impl() const override { |
352 | 8 | return Impl::get_variadic_argument_types(); |
353 | 8 | } _ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE20EEEE32get_variadic_argument_types_implEv Line | Count | Source | 351 | 1 | DataTypes get_variadic_argument_types_impl() const override { | 352 | 1 | return Impl::get_variadic_argument_types(); | 353 | 1 | } |
_ZNK5doris19FunctionMoneyFormatINS_21MoneyFormatDoubleImplEE32get_variadic_argument_types_implEv Line | Count | Source | 351 | 1 | DataTypes get_variadic_argument_types_impl() const override { | 352 | 1 | return Impl::get_variadic_argument_types(); | 353 | 1 | } |
_ZNK5doris19FunctionMoneyFormatINS_20MoneyFormatInt64ImplEE32get_variadic_argument_types_implEv Line | Count | Source | 351 | 1 | DataTypes get_variadic_argument_types_impl() const override { | 352 | 1 | return Impl::get_variadic_argument_types(); | 353 | 1 | } |
_ZNK5doris19FunctionMoneyFormatINS_21MoneyFormatInt128ImplEE32get_variadic_argument_types_implEv Line | Count | Source | 351 | 1 | DataTypes get_variadic_argument_types_impl() const override { | 352 | 1 | return Impl::get_variadic_argument_types(); | 353 | 1 | } |
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE28EEEE32get_variadic_argument_types_implEv Line | Count | Source | 351 | 1 | DataTypes get_variadic_argument_types_impl() const override { | 352 | 1 | return Impl::get_variadic_argument_types(); | 353 | 1 | } |
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE29EEEE32get_variadic_argument_types_implEv Line | Count | Source | 351 | 1 | DataTypes get_variadic_argument_types_impl() const override { | 352 | 1 | return Impl::get_variadic_argument_types(); | 353 | 1 | } |
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE30EEEE32get_variadic_argument_types_implEv Line | Count | Source | 351 | 1 | DataTypes get_variadic_argument_types_impl() const override { | 352 | 1 | return Impl::get_variadic_argument_types(); | 353 | 1 | } |
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE35EEEE32get_variadic_argument_types_implEv Line | Count | Source | 351 | 1 | DataTypes get_variadic_argument_types_impl() const override { | 352 | 1 | return Impl::get_variadic_argument_types(); | 353 | 1 | } |
|
354 | 14 | size_t get_number_of_arguments() const override { return 1; }_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE20EEEE23get_number_of_argumentsEv Line | Count | Source | 354 | 1 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris19FunctionMoneyFormatINS_21MoneyFormatDoubleImplEE23get_number_of_argumentsEv Line | Count | Source | 354 | 1 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris19FunctionMoneyFormatINS_20MoneyFormatInt64ImplEE23get_number_of_argumentsEv Line | Count | Source | 354 | 1 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris19FunctionMoneyFormatINS_21MoneyFormatInt128ImplEE23get_number_of_argumentsEv Line | Count | Source | 354 | 1 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE28EEEE23get_number_of_argumentsEv Line | Count | Source | 354 | 2 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE29EEEE23get_number_of_argumentsEv Line | Count | Source | 354 | 6 | size_t get_number_of_arguments() const override { return 1; } |
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE30EEEE23get_number_of_argumentsEv Line | Count | Source | 354 | 2 | size_t get_number_of_arguments() const override { return 1; } |
Unexecuted instantiation: _ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE35EEEE23get_number_of_argumentsEv |
355 | | |
356 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
357 | 14 | uint32_t result, size_t input_rows_count) const override { |
358 | 14 | auto res_column = ColumnString::create(); |
359 | 14 | ColumnPtr argument_column = block.get_by_position(arguments[0]).column; |
360 | | |
361 | 14 | auto result_column = res_column.get(); |
362 | | |
363 | 14 | Impl::execute(context, result_column, argument_column, input_rows_count); |
364 | | |
365 | 14 | block.replace_by_position(result, std::move(res_column)); |
366 | 14 | return Status::OK(); |
367 | 14 | } _ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE20EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 357 | 2 | uint32_t result, size_t input_rows_count) const override { | 358 | 2 | auto res_column = ColumnString::create(); | 359 | 2 | ColumnPtr argument_column = block.get_by_position(arguments[0]).column; | 360 | | | 361 | 2 | auto result_column = res_column.get(); | 362 | | | 363 | 2 | Impl::execute(context, result_column, argument_column, input_rows_count); | 364 | | | 365 | 2 | block.replace_by_position(result, std::move(res_column)); | 366 | 2 | return Status::OK(); | 367 | 2 | } |
_ZNK5doris19FunctionMoneyFormatINS_21MoneyFormatDoubleImplEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 357 | 1 | uint32_t result, size_t input_rows_count) const override { | 358 | 1 | auto res_column = ColumnString::create(); | 359 | 1 | ColumnPtr argument_column = block.get_by_position(arguments[0]).column; | 360 | | | 361 | 1 | auto result_column = res_column.get(); | 362 | | | 363 | 1 | Impl::execute(context, result_column, argument_column, input_rows_count); | 364 | | | 365 | 1 | block.replace_by_position(result, std::move(res_column)); | 366 | 1 | return Status::OK(); | 367 | 1 | } |
_ZNK5doris19FunctionMoneyFormatINS_20MoneyFormatInt64ImplEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 357 | 1 | uint32_t result, size_t input_rows_count) const override { | 358 | 1 | auto res_column = ColumnString::create(); | 359 | 1 | ColumnPtr argument_column = block.get_by_position(arguments[0]).column; | 360 | | | 361 | 1 | auto result_column = res_column.get(); | 362 | | | 363 | 1 | Impl::execute(context, result_column, argument_column, input_rows_count); | 364 | | | 365 | 1 | block.replace_by_position(result, std::move(res_column)); | 366 | 1 | return Status::OK(); | 367 | 1 | } |
_ZNK5doris19FunctionMoneyFormatINS_21MoneyFormatInt128ImplEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 357 | 1 | uint32_t result, size_t input_rows_count) const override { | 358 | 1 | auto res_column = ColumnString::create(); | 359 | 1 | ColumnPtr argument_column = block.get_by_position(arguments[0]).column; | 360 | | | 361 | 1 | auto result_column = res_column.get(); | 362 | | | 363 | 1 | Impl::execute(context, result_column, argument_column, input_rows_count); | 364 | | | 365 | 1 | block.replace_by_position(result, std::move(res_column)); | 366 | 1 | return Status::OK(); | 367 | 1 | } |
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE28EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 357 | 2 | uint32_t result, size_t input_rows_count) const override { | 358 | 2 | auto res_column = ColumnString::create(); | 359 | 2 | ColumnPtr argument_column = block.get_by_position(arguments[0]).column; | 360 | | | 361 | 2 | auto result_column = res_column.get(); | 362 | | | 363 | 2 | Impl::execute(context, result_column, argument_column, input_rows_count); | 364 | | | 365 | 2 | block.replace_by_position(result, std::move(res_column)); | 366 | 2 | return Status::OK(); | 367 | 2 | } |
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE29EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 357 | 5 | uint32_t result, size_t input_rows_count) const override { | 358 | 5 | auto res_column = ColumnString::create(); | 359 | 5 | ColumnPtr argument_column = block.get_by_position(arguments[0]).column; | 360 | | | 361 | 5 | auto result_column = res_column.get(); | 362 | | | 363 | 5 | Impl::execute(context, result_column, argument_column, input_rows_count); | 364 | | | 365 | 5 | block.replace_by_position(result, std::move(res_column)); | 366 | 5 | return Status::OK(); | 367 | 5 | } |
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE30EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 357 | 2 | uint32_t result, size_t input_rows_count) const override { | 358 | 2 | auto res_column = ColumnString::create(); | 359 | 2 | ColumnPtr argument_column = block.get_by_position(arguments[0]).column; | 360 | | | 361 | 2 | auto result_column = res_column.get(); | 362 | | | 363 | 2 | Impl::execute(context, result_column, argument_column, input_rows_count); | 364 | | | 365 | 2 | block.replace_by_position(result, std::move(res_column)); | 366 | 2 | return Status::OK(); | 367 | 2 | } |
Unexecuted instantiation: _ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE35EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm |
368 | | }; |
369 | | |
370 | | struct MoneyFormatDoubleImpl { |
371 | 1 | static DataTypes get_variadic_argument_types() { return {std::make_shared<DataTypeFloat64>()}; } |
372 | | |
373 | | static void execute(FunctionContext* context, ColumnString* result_column, |
374 | 1 | const ColumnPtr col_ptr, size_t input_rows_count) { |
375 | 1 | const auto* data_column = assert_cast<const ColumnFloat64*>(col_ptr.get()); |
376 | | // when scale is above 38, we will go here |
377 | 5 | for (size_t i = 0; i < input_rows_count; i++) { |
378 | | // round to 2 decimal places |
379 | 4 | double value = |
380 | 4 | MathFunctions::my_double_round(data_column->get_element(i), 2, false, false); |
381 | 4 | StringRef str = MoneyFormat::do_money_format(context, fmt::format("{:.2f}", value)); |
382 | 4 | result_column->insert_data(str.data, str.size); |
383 | 4 | } |
384 | 1 | } |
385 | | }; |
386 | | |
387 | | struct MoneyFormatInt64Impl { |
388 | 1 | static DataTypes get_variadic_argument_types() { return {std::make_shared<DataTypeInt64>()}; } |
389 | | |
390 | | static void execute(FunctionContext* context, ColumnString* result_column, |
391 | 1 | const ColumnPtr col_ptr, size_t input_rows_count) { |
392 | 1 | const auto* data_column = assert_cast<const ColumnInt64*>(col_ptr.get()); |
393 | 4 | for (size_t i = 0; i < input_rows_count; i++) { |
394 | 3 | Int64 value = data_column->get_element(i); |
395 | 3 | StringRef str = |
396 | 3 | MoneyFormat::do_money_format<Int64, MoneyFormat::MAX_FORMAT_LEN_INT64()>( |
397 | 3 | context, 0, value, 0); |
398 | 3 | result_column->insert_data(str.data, str.size); |
399 | 3 | } |
400 | 1 | } |
401 | | }; |
402 | | |
403 | | struct MoneyFormatInt128Impl { |
404 | 1 | static DataTypes get_variadic_argument_types() { return {std::make_shared<DataTypeInt128>()}; } |
405 | | |
406 | | static void execute(FunctionContext* context, ColumnString* result_column, |
407 | 1 | const ColumnPtr col_ptr, size_t input_rows_count) { |
408 | 1 | const auto* data_column = assert_cast<const ColumnInt128*>(col_ptr.get()); |
409 | | // SELECT money_format(170141183460469231731687303715884105728/*INT128_MAX + 1*/) will |
410 | | // get "170,141,183,460,469,231,731,687,303,715,884,105,727.00" in doris, |
411 | | // see https://github.com/apache/doris/blob/788abf2d7c3c7c2d57487a9608e889e7662d5fb2/be/src/vec/data_types/data_type_number_base.cpp#L124 |
412 | 4 | for (size_t i = 0; i < input_rows_count; i++) { |
413 | 3 | Int128 value = data_column->get_element(i); |
414 | 3 | StringRef str = |
415 | 3 | MoneyFormat::do_money_format<Int128, MoneyFormat::MAX_FORMAT_LEN_INT128()>( |
416 | 3 | context, 0, value, 0); |
417 | 3 | result_column->insert_data(str.data, str.size); |
418 | 3 | } |
419 | 1 | } |
420 | | }; |
421 | | |
422 | | template <PrimitiveType Type> |
423 | | struct MoneyFormatDecimalImpl { |
424 | 5 | static DataTypes get_variadic_argument_types() { |
425 | 5 | return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>()}; |
426 | 5 | } _ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE20EE27get_variadic_argument_typesEv Line | Count | Source | 424 | 1 | static DataTypes get_variadic_argument_types() { | 425 | 1 | return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>()}; | 426 | 1 | } |
_ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE28EE27get_variadic_argument_typesEv Line | Count | Source | 424 | 1 | static DataTypes get_variadic_argument_types() { | 425 | 1 | return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>()}; | 426 | 1 | } |
_ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE29EE27get_variadic_argument_typesEv Line | Count | Source | 424 | 1 | static DataTypes get_variadic_argument_types() { | 425 | 1 | return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>()}; | 426 | 1 | } |
_ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE30EE27get_variadic_argument_typesEv Line | Count | Source | 424 | 1 | static DataTypes get_variadic_argument_types() { | 425 | 1 | return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>()}; | 426 | 1 | } |
_ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE35EE27get_variadic_argument_typesEv Line | Count | Source | 424 | 1 | static DataTypes get_variadic_argument_types() { | 425 | 1 | return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>()}; | 426 | 1 | } |
|
427 | | |
428 | | static void execute(FunctionContext* context, ColumnString* result_column, ColumnPtr col_ptr, |
429 | 11 | size_t input_rows_count) { |
430 | 11 | if (auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) { |
431 | 16 | for (size_t i = 0; i < input_rows_count; i++) { |
432 | 14 | const auto& value = decimalv2_column->get_element(i); |
433 | | // unified_frac_value has 3 digits |
434 | 14 | auto unified_frac_value = value.frac_value() / 1000000; |
435 | 14 | StringRef str = |
436 | 14 | MoneyFormat::do_money_format<Int128, |
437 | 14 | MoneyFormat::MAX_FORMAT_LEN_DEC128V2()>( |
438 | 14 | context, 3, value.int_value(), unified_frac_value); |
439 | | |
440 | 14 | result_column->insert_data(str.data, str.size); |
441 | 14 | } |
442 | 9 | } else if (auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) { |
443 | 2 | const UInt32 scale = decimal32_column->get_scale(); |
444 | 4 | for (size_t i = 0; i < input_rows_count; i++) { |
445 | 2 | const Int32& frac_part = decimal32_column->get_fractional_part(i); |
446 | 2 | const Int32& whole_part = decimal32_column->get_intergral_part(i); |
447 | 2 | StringRef str = |
448 | 2 | MoneyFormat::do_money_format<Int64, MoneyFormat::MAX_FORMAT_LEN_DEC32()>( |
449 | 2 | context, scale, static_cast<Int64>(whole_part), |
450 | 2 | static_cast<Int64>(frac_part)); |
451 | | |
452 | 2 | result_column->insert_data(str.data, str.size); |
453 | 2 | } |
454 | 7 | } else if (auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) { |
455 | 5 | const UInt32 scale = decimal64_column->get_scale(); |
456 | 12 | for (size_t i = 0; i < input_rows_count; i++) { |
457 | 7 | const Int64& frac_part = decimal64_column->get_fractional_part(i); |
458 | 7 | const Int64& whole_part = decimal64_column->get_intergral_part(i); |
459 | | |
460 | 7 | StringRef str = |
461 | 7 | MoneyFormat::do_money_format<Int64, MoneyFormat::MAX_FORMAT_LEN_DEC64()>( |
462 | 7 | context, scale, whole_part, frac_part); |
463 | | |
464 | 7 | result_column->insert_data(str.data, str.size); |
465 | 7 | } |
466 | 5 | } else if (auto* decimal128_column = check_and_get_column<ColumnDecimal128V3>(*col_ptr)) { |
467 | 2 | const UInt32 scale = decimal128_column->get_scale(); |
468 | 4 | for (size_t i = 0; i < input_rows_count; i++) { |
469 | 2 | const Int128& frac_part = decimal128_column->get_fractional_part(i); |
470 | 2 | const Int128& whole_part = decimal128_column->get_intergral_part(i); |
471 | | |
472 | 2 | StringRef str = |
473 | 2 | MoneyFormat::do_money_format<Int128, |
474 | 2 | MoneyFormat::MAX_FORMAT_LEN_DEC128V3()>( |
475 | 2 | context, scale, whole_part, frac_part); |
476 | | |
477 | 2 | result_column->insert_data(str.data, str.size); |
478 | 2 | } |
479 | 2 | } else { |
480 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, |
481 | 0 | "Not supported input argument type {}", col_ptr->get_name()); |
482 | 0 | } |
483 | | // TODO: decimal256 |
484 | | /* else if (auto* decimal256_column = |
485 | | check_and_get_column<ColumnDecimal<Decimal256>>(*col_ptr)) { |
486 | | const UInt32 scale = decimal256_column->get_scale(); |
487 | | const auto multiplier = |
488 | | scale > 2 ? common::exp10_i32(scale - 2) : common::exp10_i32(2 - scale); |
489 | | for (size_t i = 0; i < input_rows_count; i++) { |
490 | | Decimal256 frac_part = decimal256_column->get_fractional_part(i); |
491 | | if (scale > 2) { |
492 | | int delta = ((frac_part % multiplier) << 1) > multiplier; |
493 | | frac_part = Decimal256(frac_part / multiplier + delta); |
494 | | } else if (scale < 2) { |
495 | | frac_part = Decimal256(frac_part * multiplier); |
496 | | } |
497 | | |
498 | | StringRef str = MoneyFormat::do_money_format<int64_t, 26>( |
499 | | context, decimal256_column->get_intergral_part(i), frac_part); |
500 | | |
501 | | result_column->insert_data(str.data, str.size); |
502 | | } |
503 | | }*/ |
504 | 11 | } _ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE20EE7executeEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EEm Line | Count | Source | 429 | 2 | size_t input_rows_count) { | 430 | 2 | if (auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) { | 431 | 16 | for (size_t i = 0; i < input_rows_count; i++) { | 432 | 14 | const auto& value = decimalv2_column->get_element(i); | 433 | | // unified_frac_value has 3 digits | 434 | 14 | auto unified_frac_value = value.frac_value() / 1000000; | 435 | 14 | StringRef str = | 436 | 14 | MoneyFormat::do_money_format<Int128, | 437 | 14 | MoneyFormat::MAX_FORMAT_LEN_DEC128V2()>( | 438 | 14 | context, 3, value.int_value(), unified_frac_value); | 439 | | | 440 | 14 | result_column->insert_data(str.data, str.size); | 441 | 14 | } | 442 | 2 | } else if (auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) { | 443 | 0 | const UInt32 scale = decimal32_column->get_scale(); | 444 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 445 | 0 | const Int32& frac_part = decimal32_column->get_fractional_part(i); | 446 | 0 | const Int32& whole_part = decimal32_column->get_intergral_part(i); | 447 | 0 | StringRef str = | 448 | 0 | MoneyFormat::do_money_format<Int64, MoneyFormat::MAX_FORMAT_LEN_DEC32()>( | 449 | 0 | context, scale, static_cast<Int64>(whole_part), | 450 | 0 | static_cast<Int64>(frac_part)); | 451 | |
| 452 | 0 | result_column->insert_data(str.data, str.size); | 453 | 0 | } | 454 | 0 | } else if (auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) { | 455 | 0 | const UInt32 scale = decimal64_column->get_scale(); | 456 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 457 | 0 | const Int64& frac_part = decimal64_column->get_fractional_part(i); | 458 | 0 | const Int64& whole_part = decimal64_column->get_intergral_part(i); | 459 | |
| 460 | 0 | StringRef str = | 461 | 0 | MoneyFormat::do_money_format<Int64, MoneyFormat::MAX_FORMAT_LEN_DEC64()>( | 462 | 0 | context, scale, whole_part, frac_part); | 463 | |
| 464 | 0 | result_column->insert_data(str.data, str.size); | 465 | 0 | } | 466 | 0 | } else if (auto* decimal128_column = check_and_get_column<ColumnDecimal128V3>(*col_ptr)) { | 467 | 0 | const UInt32 scale = decimal128_column->get_scale(); | 468 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 469 | 0 | const Int128& frac_part = decimal128_column->get_fractional_part(i); | 470 | 0 | const Int128& whole_part = decimal128_column->get_intergral_part(i); | 471 | |
| 472 | 0 | StringRef str = | 473 | 0 | MoneyFormat::do_money_format<Int128, | 474 | 0 | MoneyFormat::MAX_FORMAT_LEN_DEC128V3()>( | 475 | 0 | context, scale, whole_part, frac_part); | 476 | |
| 477 | 0 | result_column->insert_data(str.data, str.size); | 478 | 0 | } | 479 | 0 | } else { | 480 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 481 | 0 | "Not supported input argument type {}", col_ptr->get_name()); | 482 | 0 | } | 483 | | // TODO: decimal256 | 484 | | /* else if (auto* decimal256_column = | 485 | | check_and_get_column<ColumnDecimal<Decimal256>>(*col_ptr)) { | 486 | | const UInt32 scale = decimal256_column->get_scale(); | 487 | | const auto multiplier = | 488 | | scale > 2 ? common::exp10_i32(scale - 2) : common::exp10_i32(2 - scale); | 489 | | for (size_t i = 0; i < input_rows_count; i++) { | 490 | | Decimal256 frac_part = decimal256_column->get_fractional_part(i); | 491 | | if (scale > 2) { | 492 | | int delta = ((frac_part % multiplier) << 1) > multiplier; | 493 | | frac_part = Decimal256(frac_part / multiplier + delta); | 494 | | } else if (scale < 2) { | 495 | | frac_part = Decimal256(frac_part * multiplier); | 496 | | } | 497 | | | 498 | | StringRef str = MoneyFormat::do_money_format<int64_t, 26>( | 499 | | context, decimal256_column->get_intergral_part(i), frac_part); | 500 | | | 501 | | result_column->insert_data(str.data, str.size); | 502 | | } | 503 | | }*/ | 504 | 2 | } |
_ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE28EE7executeEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EEm Line | Count | Source | 429 | 2 | size_t input_rows_count) { | 430 | 2 | if (auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) { | 431 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 432 | 0 | const auto& value = decimalv2_column->get_element(i); | 433 | | // unified_frac_value has 3 digits | 434 | 0 | auto unified_frac_value = value.frac_value() / 1000000; | 435 | 0 | StringRef str = | 436 | 0 | MoneyFormat::do_money_format<Int128, | 437 | 0 | MoneyFormat::MAX_FORMAT_LEN_DEC128V2()>( | 438 | 0 | context, 3, value.int_value(), unified_frac_value); | 439 | |
| 440 | 0 | result_column->insert_data(str.data, str.size); | 441 | 0 | } | 442 | 2 | } else if (auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) { | 443 | 2 | const UInt32 scale = decimal32_column->get_scale(); | 444 | 4 | for (size_t i = 0; i < input_rows_count; i++) { | 445 | 2 | const Int32& frac_part = decimal32_column->get_fractional_part(i); | 446 | 2 | const Int32& whole_part = decimal32_column->get_intergral_part(i); | 447 | 2 | StringRef str = | 448 | 2 | MoneyFormat::do_money_format<Int64, MoneyFormat::MAX_FORMAT_LEN_DEC32()>( | 449 | 2 | context, scale, static_cast<Int64>(whole_part), | 450 | 2 | static_cast<Int64>(frac_part)); | 451 | | | 452 | 2 | result_column->insert_data(str.data, str.size); | 453 | 2 | } | 454 | 2 | } else if (auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) { | 455 | 0 | const UInt32 scale = decimal64_column->get_scale(); | 456 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 457 | 0 | const Int64& frac_part = decimal64_column->get_fractional_part(i); | 458 | 0 | const Int64& whole_part = decimal64_column->get_intergral_part(i); | 459 | |
| 460 | 0 | StringRef str = | 461 | 0 | MoneyFormat::do_money_format<Int64, MoneyFormat::MAX_FORMAT_LEN_DEC64()>( | 462 | 0 | context, scale, whole_part, frac_part); | 463 | |
| 464 | 0 | result_column->insert_data(str.data, str.size); | 465 | 0 | } | 466 | 0 | } else if (auto* decimal128_column = check_and_get_column<ColumnDecimal128V3>(*col_ptr)) { | 467 | 0 | const UInt32 scale = decimal128_column->get_scale(); | 468 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 469 | 0 | const Int128& frac_part = decimal128_column->get_fractional_part(i); | 470 | 0 | const Int128& whole_part = decimal128_column->get_intergral_part(i); | 471 | |
| 472 | 0 | StringRef str = | 473 | 0 | MoneyFormat::do_money_format<Int128, | 474 | 0 | MoneyFormat::MAX_FORMAT_LEN_DEC128V3()>( | 475 | 0 | context, scale, whole_part, frac_part); | 476 | |
| 477 | 0 | result_column->insert_data(str.data, str.size); | 478 | 0 | } | 479 | 0 | } else { | 480 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 481 | 0 | "Not supported input argument type {}", col_ptr->get_name()); | 482 | 0 | } | 483 | | // TODO: decimal256 | 484 | | /* else if (auto* decimal256_column = | 485 | | check_and_get_column<ColumnDecimal<Decimal256>>(*col_ptr)) { | 486 | | const UInt32 scale = decimal256_column->get_scale(); | 487 | | const auto multiplier = | 488 | | scale > 2 ? common::exp10_i32(scale - 2) : common::exp10_i32(2 - scale); | 489 | | for (size_t i = 0; i < input_rows_count; i++) { | 490 | | Decimal256 frac_part = decimal256_column->get_fractional_part(i); | 491 | | if (scale > 2) { | 492 | | int delta = ((frac_part % multiplier) << 1) > multiplier; | 493 | | frac_part = Decimal256(frac_part / multiplier + delta); | 494 | | } else if (scale < 2) { | 495 | | frac_part = Decimal256(frac_part * multiplier); | 496 | | } | 497 | | | 498 | | StringRef str = MoneyFormat::do_money_format<int64_t, 26>( | 499 | | context, decimal256_column->get_intergral_part(i), frac_part); | 500 | | | 501 | | result_column->insert_data(str.data, str.size); | 502 | | } | 503 | | }*/ | 504 | 2 | } |
_ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE29EE7executeEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EEm Line | Count | Source | 429 | 5 | size_t input_rows_count) { | 430 | 5 | if (auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) { | 431 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 432 | 0 | const auto& value = decimalv2_column->get_element(i); | 433 | | // unified_frac_value has 3 digits | 434 | 0 | auto unified_frac_value = value.frac_value() / 1000000; | 435 | 0 | StringRef str = | 436 | 0 | MoneyFormat::do_money_format<Int128, | 437 | 0 | MoneyFormat::MAX_FORMAT_LEN_DEC128V2()>( | 438 | 0 | context, 3, value.int_value(), unified_frac_value); | 439 | |
| 440 | 0 | result_column->insert_data(str.data, str.size); | 441 | 0 | } | 442 | 5 | } else if (auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) { | 443 | 0 | const UInt32 scale = decimal32_column->get_scale(); | 444 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 445 | 0 | const Int32& frac_part = decimal32_column->get_fractional_part(i); | 446 | 0 | const Int32& whole_part = decimal32_column->get_intergral_part(i); | 447 | 0 | StringRef str = | 448 | 0 | MoneyFormat::do_money_format<Int64, MoneyFormat::MAX_FORMAT_LEN_DEC32()>( | 449 | 0 | context, scale, static_cast<Int64>(whole_part), | 450 | 0 | static_cast<Int64>(frac_part)); | 451 | |
| 452 | 0 | result_column->insert_data(str.data, str.size); | 453 | 0 | } | 454 | 5 | } else if (auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) { | 455 | 5 | const UInt32 scale = decimal64_column->get_scale(); | 456 | 12 | for (size_t i = 0; i < input_rows_count; i++) { | 457 | 7 | const Int64& frac_part = decimal64_column->get_fractional_part(i); | 458 | 7 | const Int64& whole_part = decimal64_column->get_intergral_part(i); | 459 | | | 460 | 7 | StringRef str = | 461 | 7 | MoneyFormat::do_money_format<Int64, MoneyFormat::MAX_FORMAT_LEN_DEC64()>( | 462 | 7 | context, scale, whole_part, frac_part); | 463 | | | 464 | 7 | result_column->insert_data(str.data, str.size); | 465 | 7 | } | 466 | 5 | } else if (auto* decimal128_column = check_and_get_column<ColumnDecimal128V3>(*col_ptr)) { | 467 | 0 | const UInt32 scale = decimal128_column->get_scale(); | 468 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 469 | 0 | const Int128& frac_part = decimal128_column->get_fractional_part(i); | 470 | 0 | const Int128& whole_part = decimal128_column->get_intergral_part(i); | 471 | |
| 472 | 0 | StringRef str = | 473 | 0 | MoneyFormat::do_money_format<Int128, | 474 | 0 | MoneyFormat::MAX_FORMAT_LEN_DEC128V3()>( | 475 | 0 | context, scale, whole_part, frac_part); | 476 | |
| 477 | 0 | result_column->insert_data(str.data, str.size); | 478 | 0 | } | 479 | 0 | } else { | 480 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 481 | 0 | "Not supported input argument type {}", col_ptr->get_name()); | 482 | 0 | } | 483 | | // TODO: decimal256 | 484 | | /* else if (auto* decimal256_column = | 485 | | check_and_get_column<ColumnDecimal<Decimal256>>(*col_ptr)) { | 486 | | const UInt32 scale = decimal256_column->get_scale(); | 487 | | const auto multiplier = | 488 | | scale > 2 ? common::exp10_i32(scale - 2) : common::exp10_i32(2 - scale); | 489 | | for (size_t i = 0; i < input_rows_count; i++) { | 490 | | Decimal256 frac_part = decimal256_column->get_fractional_part(i); | 491 | | if (scale > 2) { | 492 | | int delta = ((frac_part % multiplier) << 1) > multiplier; | 493 | | frac_part = Decimal256(frac_part / multiplier + delta); | 494 | | } else if (scale < 2) { | 495 | | frac_part = Decimal256(frac_part * multiplier); | 496 | | } | 497 | | | 498 | | StringRef str = MoneyFormat::do_money_format<int64_t, 26>( | 499 | | context, decimal256_column->get_intergral_part(i), frac_part); | 500 | | | 501 | | result_column->insert_data(str.data, str.size); | 502 | | } | 503 | | }*/ | 504 | 5 | } |
_ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE30EE7executeEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EEm Line | Count | Source | 429 | 2 | size_t input_rows_count) { | 430 | 2 | if (auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) { | 431 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 432 | 0 | const auto& value = decimalv2_column->get_element(i); | 433 | | // unified_frac_value has 3 digits | 434 | 0 | auto unified_frac_value = value.frac_value() / 1000000; | 435 | 0 | StringRef str = | 436 | 0 | MoneyFormat::do_money_format<Int128, | 437 | 0 | MoneyFormat::MAX_FORMAT_LEN_DEC128V2()>( | 438 | 0 | context, 3, value.int_value(), unified_frac_value); | 439 | |
| 440 | 0 | result_column->insert_data(str.data, str.size); | 441 | 0 | } | 442 | 2 | } else if (auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) { | 443 | 0 | const UInt32 scale = decimal32_column->get_scale(); | 444 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 445 | 0 | const Int32& frac_part = decimal32_column->get_fractional_part(i); | 446 | 0 | const Int32& whole_part = decimal32_column->get_intergral_part(i); | 447 | 0 | StringRef str = | 448 | 0 | MoneyFormat::do_money_format<Int64, MoneyFormat::MAX_FORMAT_LEN_DEC32()>( | 449 | 0 | context, scale, static_cast<Int64>(whole_part), | 450 | 0 | static_cast<Int64>(frac_part)); | 451 | |
| 452 | 0 | result_column->insert_data(str.data, str.size); | 453 | 0 | } | 454 | 2 | } else if (auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) { | 455 | 0 | const UInt32 scale = decimal64_column->get_scale(); | 456 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 457 | 0 | const Int64& frac_part = decimal64_column->get_fractional_part(i); | 458 | 0 | const Int64& whole_part = decimal64_column->get_intergral_part(i); | 459 | |
| 460 | 0 | StringRef str = | 461 | 0 | MoneyFormat::do_money_format<Int64, MoneyFormat::MAX_FORMAT_LEN_DEC64()>( | 462 | 0 | context, scale, whole_part, frac_part); | 463 | |
| 464 | 0 | result_column->insert_data(str.data, str.size); | 465 | 0 | } | 466 | 2 | } else if (auto* decimal128_column = check_and_get_column<ColumnDecimal128V3>(*col_ptr)) { | 467 | 2 | const UInt32 scale = decimal128_column->get_scale(); | 468 | 4 | for (size_t i = 0; i < input_rows_count; i++) { | 469 | 2 | const Int128& frac_part = decimal128_column->get_fractional_part(i); | 470 | 2 | const Int128& whole_part = decimal128_column->get_intergral_part(i); | 471 | | | 472 | 2 | StringRef str = | 473 | 2 | MoneyFormat::do_money_format<Int128, | 474 | 2 | MoneyFormat::MAX_FORMAT_LEN_DEC128V3()>( | 475 | 2 | context, scale, whole_part, frac_part); | 476 | | | 477 | 2 | result_column->insert_data(str.data, str.size); | 478 | 2 | } | 479 | 2 | } else { | 480 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 481 | 0 | "Not supported input argument type {}", col_ptr->get_name()); | 482 | 0 | } | 483 | | // TODO: decimal256 | 484 | | /* else if (auto* decimal256_column = | 485 | | check_and_get_column<ColumnDecimal<Decimal256>>(*col_ptr)) { | 486 | | const UInt32 scale = decimal256_column->get_scale(); | 487 | | const auto multiplier = | 488 | | scale > 2 ? common::exp10_i32(scale - 2) : common::exp10_i32(2 - scale); | 489 | | for (size_t i = 0; i < input_rows_count; i++) { | 490 | | Decimal256 frac_part = decimal256_column->get_fractional_part(i); | 491 | | if (scale > 2) { | 492 | | int delta = ((frac_part % multiplier) << 1) > multiplier; | 493 | | frac_part = Decimal256(frac_part / multiplier + delta); | 494 | | } else if (scale < 2) { | 495 | | frac_part = Decimal256(frac_part * multiplier); | 496 | | } | 497 | | | 498 | | StringRef str = MoneyFormat::do_money_format<int64_t, 26>( | 499 | | context, decimal256_column->get_intergral_part(i), frac_part); | 500 | | | 501 | | result_column->insert_data(str.data, str.size); | 502 | | } | 503 | | }*/ | 504 | 2 | } |
Unexecuted instantiation: _ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE35EE7executeEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EEm |
505 | | }; |
506 | | |
507 | | template <typename Impl> |
508 | | class FunctionStringFormatRound : public IFunction { |
509 | | public: |
510 | | static constexpr auto name = "format_round"; |
511 | 901 | static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); }_ZN5doris25FunctionStringFormatRoundINS_21FormatRoundDoubleImplEE6createEv Line | Count | Source | 511 | 3 | static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); } |
_ZN5doris25FunctionStringFormatRoundINS_20FormatRoundInt64ImplEE6createEv Line | Count | Source | 511 | 10 | static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); } |
_ZN5doris25FunctionStringFormatRoundINS_21FormatRoundInt128ImplEE6createEv Line | Count | Source | 511 | 7 | static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); } |
_ZN5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE20EEEE6createEv Line | Count | Source | 511 | 3 | static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); } |
_ZN5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EEEE6createEv Line | Count | Source | 511 | 144 | static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); } |
_ZN5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EEEE6createEv Line | Count | Source | 511 | 186 | static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); } |
_ZN5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EEEE6createEv Line | Count | Source | 511 | 308 | static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); } |
_ZN5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EEEE6createEv Line | Count | Source | 511 | 240 | static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); } |
|
512 | 8 | String get_name() const override { return name; }_ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundDoubleImplEE8get_nameB5cxx11Ev Line | Count | Source | 512 | 1 | String get_name() const override { return name; } |
_ZNK5doris25FunctionStringFormatRoundINS_20FormatRoundInt64ImplEE8get_nameB5cxx11Ev Line | Count | Source | 512 | 1 | String get_name() const override { return name; } |
_ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundInt128ImplEE8get_nameB5cxx11Ev Line | Count | Source | 512 | 1 | String get_name() const override { return name; } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE20EEEE8get_nameB5cxx11Ev Line | Count | Source | 512 | 1 | String get_name() const override { return name; } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EEEE8get_nameB5cxx11Ev Line | Count | Source | 512 | 1 | String get_name() const override { return name; } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EEEE8get_nameB5cxx11Ev Line | Count | Source | 512 | 1 | String get_name() const override { return name; } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EEEE8get_nameB5cxx11Ev Line | Count | Source | 512 | 1 | String get_name() const override { return name; } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EEEE8get_nameB5cxx11Ev Line | Count | Source | 512 | 1 | String get_name() const override { return name; } |
|
513 | | |
514 | 885 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
515 | 885 | if (arguments.size() != 2) { |
516 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, |
517 | 0 | "Function {} requires exactly 2 argument", name); |
518 | 0 | } |
519 | 885 | return std::make_shared<DataTypeString>(); |
520 | 885 | } _ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundDoubleImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 514 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 515 | 1 | if (arguments.size() != 2) { | 516 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 517 | 0 | "Function {} requires exactly 2 argument", name); | 518 | 0 | } | 519 | 1 | return std::make_shared<DataTypeString>(); | 520 | 1 | } |
_ZNK5doris25FunctionStringFormatRoundINS_20FormatRoundInt64ImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 514 | 8 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 515 | 8 | if (arguments.size() != 2) { | 516 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 517 | 0 | "Function {} requires exactly 2 argument", name); | 518 | 0 | } | 519 | 8 | return std::make_shared<DataTypeString>(); | 520 | 8 | } |
_ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundInt128ImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE Line | Count | Source | 514 | 5 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 515 | 5 | if (arguments.size() != 2) { | 516 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 517 | 0 | "Function {} requires exactly 2 argument", name); | 518 | 0 | } | 519 | 5 | return std::make_shared<DataTypeString>(); | 520 | 5 | } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE20EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE Line | Count | Source | 514 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 515 | 1 | if (arguments.size() != 2) { | 516 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 517 | 0 | "Function {} requires exactly 2 argument", name); | 518 | 0 | } | 519 | 1 | return std::make_shared<DataTypeString>(); | 520 | 1 | } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE Line | Count | Source | 514 | 142 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 515 | 142 | if (arguments.size() != 2) { | 516 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 517 | 0 | "Function {} requires exactly 2 argument", name); | 518 | 0 | } | 519 | 142 | return std::make_shared<DataTypeString>(); | 520 | 142 | } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE Line | Count | Source | 514 | 184 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 515 | 184 | if (arguments.size() != 2) { | 516 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 517 | 0 | "Function {} requires exactly 2 argument", name); | 518 | 0 | } | 519 | 184 | return std::make_shared<DataTypeString>(); | 520 | 184 | } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE Line | Count | Source | 514 | 306 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 515 | 306 | if (arguments.size() != 2) { | 516 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 517 | 0 | "Function {} requires exactly 2 argument", name); | 518 | 0 | } | 519 | 306 | return std::make_shared<DataTypeString>(); | 520 | 306 | } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE Line | Count | Source | 514 | 238 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 515 | 238 | if (arguments.size() != 2) { | 516 | 0 | throw doris::Exception(ErrorCode::INVALID_ARGUMENT, | 517 | 0 | "Function {} requires exactly 2 argument", name); | 518 | 0 | } | 519 | 238 | return std::make_shared<DataTypeString>(); | 520 | 238 | } |
|
521 | 8 | DataTypes get_variadic_argument_types_impl() const override { |
522 | 8 | return Impl::get_variadic_argument_types(); |
523 | 8 | } _ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundDoubleImplEE32get_variadic_argument_types_implEv Line | Count | Source | 521 | 1 | DataTypes get_variadic_argument_types_impl() const override { | 522 | 1 | return Impl::get_variadic_argument_types(); | 523 | 1 | } |
_ZNK5doris25FunctionStringFormatRoundINS_20FormatRoundInt64ImplEE32get_variadic_argument_types_implEv Line | Count | Source | 521 | 1 | DataTypes get_variadic_argument_types_impl() const override { | 522 | 1 | return Impl::get_variadic_argument_types(); | 523 | 1 | } |
_ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundInt128ImplEE32get_variadic_argument_types_implEv Line | Count | Source | 521 | 1 | DataTypes get_variadic_argument_types_impl() const override { | 522 | 1 | return Impl::get_variadic_argument_types(); | 523 | 1 | } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE20EEEE32get_variadic_argument_types_implEv Line | Count | Source | 521 | 1 | DataTypes get_variadic_argument_types_impl() const override { | 522 | 1 | return Impl::get_variadic_argument_types(); | 523 | 1 | } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EEEE32get_variadic_argument_types_implEv Line | Count | Source | 521 | 1 | DataTypes get_variadic_argument_types_impl() const override { | 522 | 1 | return Impl::get_variadic_argument_types(); | 523 | 1 | } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EEEE32get_variadic_argument_types_implEv Line | Count | Source | 521 | 1 | DataTypes get_variadic_argument_types_impl() const override { | 522 | 1 | return Impl::get_variadic_argument_types(); | 523 | 1 | } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EEEE32get_variadic_argument_types_implEv Line | Count | Source | 521 | 1 | DataTypes get_variadic_argument_types_impl() const override { | 522 | 1 | return Impl::get_variadic_argument_types(); | 523 | 1 | } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EEEE32get_variadic_argument_types_implEv Line | Count | Source | 521 | 1 | DataTypes get_variadic_argument_types_impl() const override { | 522 | 1 | return Impl::get_variadic_argument_types(); | 523 | 1 | } |
|
524 | 885 | size_t get_number_of_arguments() const override { return 2; }_ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundDoubleImplEE23get_number_of_argumentsEv Line | Count | Source | 524 | 1 | size_t get_number_of_arguments() const override { return 2; } |
_ZNK5doris25FunctionStringFormatRoundINS_20FormatRoundInt64ImplEE23get_number_of_argumentsEv Line | Count | Source | 524 | 8 | size_t get_number_of_arguments() const override { return 2; } |
_ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundInt128ImplEE23get_number_of_argumentsEv Line | Count | Source | 524 | 5 | size_t get_number_of_arguments() const override { return 2; } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE20EEEE23get_number_of_argumentsEv Line | Count | Source | 524 | 1 | size_t get_number_of_arguments() const override { return 2; } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EEEE23get_number_of_argumentsEv Line | Count | Source | 524 | 142 | size_t get_number_of_arguments() const override { return 2; } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EEEE23get_number_of_argumentsEv Line | Count | Source | 524 | 184 | size_t get_number_of_arguments() const override { return 2; } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EEEE23get_number_of_argumentsEv Line | Count | Source | 524 | 306 | size_t get_number_of_arguments() const override { return 2; } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EEEE23get_number_of_argumentsEv Line | Count | Source | 524 | 238 | size_t get_number_of_arguments() const override { return 2; } |
|
525 | | |
526 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
527 | 852 | uint32_t result, size_t input_rows_count) const override { |
528 | 852 | auto res_column = ColumnString::create(); |
529 | 852 | ColumnPtr argument_column = |
530 | 852 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); |
531 | 852 | ColumnPtr argument_column_2; |
532 | 852 | bool is_const; |
533 | 852 | std::tie(argument_column_2, is_const) = |
534 | 852 | unpack_if_const(block.get_by_position(arguments[1]).column); |
535 | 852 | auto* result_column = res_column.get(); |
536 | | |
537 | 852 | if (is_const) { |
538 | 278 | RETURN_IF_ERROR(Impl::template execute<true>(context, result_column, argument_column, |
539 | 278 | argument_column_2, input_rows_count)); |
540 | 574 | } else { |
541 | 574 | RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column, |
542 | 574 | argument_column_2, input_rows_count)); |
543 | 574 | } |
544 | | |
545 | 852 | block.replace_by_position(result, std::move(res_column)); |
546 | 852 | return Status::OK(); |
547 | 852 | } _ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundDoubleImplEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 527 | 1 | uint32_t result, size_t input_rows_count) const override { | 528 | 1 | auto res_column = ColumnString::create(); | 529 | 1 | ColumnPtr argument_column = | 530 | 1 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); | 531 | 1 | ColumnPtr argument_column_2; | 532 | 1 | bool is_const; | 533 | 1 | std::tie(argument_column_2, is_const) = | 534 | 1 | unpack_if_const(block.get_by_position(arguments[1]).column); | 535 | 1 | auto* result_column = res_column.get(); | 536 | | | 537 | 1 | if (is_const) { | 538 | 0 | RETURN_IF_ERROR(Impl::template execute<true>(context, result_column, argument_column, | 539 | 0 | argument_column_2, input_rows_count)); | 540 | 1 | } else { | 541 | 1 | RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column, | 542 | 1 | argument_column_2, input_rows_count)); | 543 | 1 | } | 544 | | | 545 | 1 | block.replace_by_position(result, std::move(res_column)); | 546 | 1 | return Status::OK(); | 547 | 1 | } |
_ZNK5doris25FunctionStringFormatRoundINS_20FormatRoundInt64ImplEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 527 | 8 | uint32_t result, size_t input_rows_count) const override { | 528 | 8 | auto res_column = ColumnString::create(); | 529 | 8 | ColumnPtr argument_column = | 530 | 8 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); | 531 | 8 | ColumnPtr argument_column_2; | 532 | 8 | bool is_const; | 533 | 8 | std::tie(argument_column_2, is_const) = | 534 | 8 | unpack_if_const(block.get_by_position(arguments[1]).column); | 535 | 8 | auto* result_column = res_column.get(); | 536 | | | 537 | 8 | if (is_const) { | 538 | 2 | RETURN_IF_ERROR(Impl::template execute<true>(context, result_column, argument_column, | 539 | 2 | argument_column_2, input_rows_count)); | 540 | 6 | } else { | 541 | 6 | RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column, | 542 | 6 | argument_column_2, input_rows_count)); | 543 | 6 | } | 544 | | | 545 | 8 | block.replace_by_position(result, std::move(res_column)); | 546 | 8 | return Status::OK(); | 547 | 8 | } |
_ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundInt128ImplEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 527 | 5 | uint32_t result, size_t input_rows_count) const override { | 528 | 5 | auto res_column = ColumnString::create(); | 529 | 5 | ColumnPtr argument_column = | 530 | 5 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); | 531 | 5 | ColumnPtr argument_column_2; | 532 | 5 | bool is_const; | 533 | 5 | std::tie(argument_column_2, is_const) = | 534 | 5 | unpack_if_const(block.get_by_position(arguments[1]).column); | 535 | 5 | auto* result_column = res_column.get(); | 536 | | | 537 | 5 | if (is_const) { | 538 | 1 | RETURN_IF_ERROR(Impl::template execute<true>(context, result_column, argument_column, | 539 | 1 | argument_column_2, input_rows_count)); | 540 | 4 | } else { | 541 | 4 | RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column, | 542 | 4 | argument_column_2, input_rows_count)); | 543 | 4 | } | 544 | | | 545 | 5 | block.replace_by_position(result, std::move(res_column)); | 546 | 5 | return Status::OK(); | 547 | 5 | } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE20EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 527 | 1 | uint32_t result, size_t input_rows_count) const override { | 528 | 1 | auto res_column = ColumnString::create(); | 529 | 1 | ColumnPtr argument_column = | 530 | 1 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); | 531 | 1 | ColumnPtr argument_column_2; | 532 | 1 | bool is_const; | 533 | 1 | std::tie(argument_column_2, is_const) = | 534 | 1 | unpack_if_const(block.get_by_position(arguments[1]).column); | 535 | 1 | auto* result_column = res_column.get(); | 536 | | | 537 | 1 | if (is_const) { | 538 | 0 | RETURN_IF_ERROR(Impl::template execute<true>(context, result_column, argument_column, | 539 | 0 | argument_column_2, input_rows_count)); | 540 | 1 | } else { | 541 | 1 | RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column, | 542 | 1 | argument_column_2, input_rows_count)); | 543 | 1 | } | 544 | | | 545 | 1 | block.replace_by_position(result, std::move(res_column)); | 546 | 1 | return Status::OK(); | 547 | 1 | } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 527 | 136 | uint32_t result, size_t input_rows_count) const override { | 528 | 136 | auto res_column = ColumnString::create(); | 529 | 136 | ColumnPtr argument_column = | 530 | 136 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); | 531 | 136 | ColumnPtr argument_column_2; | 532 | 136 | bool is_const; | 533 | 136 | std::tie(argument_column_2, is_const) = | 534 | 136 | unpack_if_const(block.get_by_position(arguments[1]).column); | 535 | 136 | auto* result_column = res_column.get(); | 536 | | | 537 | 136 | if (is_const) { | 538 | 45 | RETURN_IF_ERROR(Impl::template execute<true>(context, result_column, argument_column, | 539 | 45 | argument_column_2, input_rows_count)); | 540 | 91 | } else { | 541 | 91 | RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column, | 542 | 91 | argument_column_2, input_rows_count)); | 543 | 91 | } | 544 | | | 545 | 136 | block.replace_by_position(result, std::move(res_column)); | 546 | 136 | return Status::OK(); | 547 | 136 | } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 527 | 175 | uint32_t result, size_t input_rows_count) const override { | 528 | 175 | auto res_column = ColumnString::create(); | 529 | 175 | ColumnPtr argument_column = | 530 | 175 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); | 531 | 175 | ColumnPtr argument_column_2; | 532 | 175 | bool is_const; | 533 | 175 | std::tie(argument_column_2, is_const) = | 534 | 175 | unpack_if_const(block.get_by_position(arguments[1]).column); | 535 | 175 | auto* result_column = res_column.get(); | 536 | | | 537 | 175 | if (is_const) { | 538 | 57 | RETURN_IF_ERROR(Impl::template execute<true>(context, result_column, argument_column, | 539 | 57 | argument_column_2, input_rows_count)); | 540 | 118 | } else { | 541 | 118 | RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column, | 542 | 118 | argument_column_2, input_rows_count)); | 543 | 118 | } | 544 | | | 545 | 175 | block.replace_by_position(result, std::move(res_column)); | 546 | 175 | return Status::OK(); | 547 | 175 | } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 527 | 294 | uint32_t result, size_t input_rows_count) const override { | 528 | 294 | auto res_column = ColumnString::create(); | 529 | 294 | ColumnPtr argument_column = | 530 | 294 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); | 531 | 294 | ColumnPtr argument_column_2; | 532 | 294 | bool is_const; | 533 | 294 | std::tie(argument_column_2, is_const) = | 534 | 294 | unpack_if_const(block.get_by_position(arguments[1]).column); | 535 | 294 | auto* result_column = res_column.get(); | 536 | | | 537 | 294 | if (is_const) { | 538 | 97 | RETURN_IF_ERROR(Impl::template execute<true>(context, result_column, argument_column, | 539 | 97 | argument_column_2, input_rows_count)); | 540 | 197 | } else { | 541 | 197 | RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column, | 542 | 197 | argument_column_2, input_rows_count)); | 543 | 197 | } | 544 | | | 545 | 294 | block.replace_by_position(result, std::move(res_column)); | 546 | 294 | return Status::OK(); | 547 | 294 | } |
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 527 | 232 | uint32_t result, size_t input_rows_count) const override { | 528 | 232 | auto res_column = ColumnString::create(); | 529 | 232 | ColumnPtr argument_column = | 530 | 232 | block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); | 531 | 232 | ColumnPtr argument_column_2; | 532 | 232 | bool is_const; | 533 | 232 | std::tie(argument_column_2, is_const) = | 534 | 232 | unpack_if_const(block.get_by_position(arguments[1]).column); | 535 | 232 | auto* result_column = res_column.get(); | 536 | | | 537 | 232 | if (is_const) { | 538 | 76 | RETURN_IF_ERROR(Impl::template execute<true>(context, result_column, argument_column, | 539 | 76 | argument_column_2, input_rows_count)); | 540 | 156 | } else { | 541 | 156 | RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column, | 542 | 156 | argument_column_2, input_rows_count)); | 543 | 156 | } | 544 | | | 545 | 232 | block.replace_by_position(result, std::move(res_column)); | 546 | 232 | return Status::OK(); | 547 | 232 | } |
|
548 | | }; |
549 | | |
550 | | struct FormatRoundDoubleImpl { |
551 | 1 | static DataTypes get_variadic_argument_types() { |
552 | 1 | return {std::make_shared<DataTypeFloat64>(), std::make_shared<DataTypeInt32>()}; |
553 | 1 | } |
554 | | |
555 | 4 | static std::string add_thousands_separator(const std::string& formatted_num) { |
556 | | // Find the position of the decimal point |
557 | 4 | size_t dot_pos = formatted_num.find('.'); |
558 | 4 | if (dot_pos == std::string::npos) { |
559 | 0 | dot_pos = formatted_num.size(); |
560 | 0 | } |
561 | | |
562 | | // Handle the integer part |
563 | 4 | int start = (formatted_num[0] == '-') ? 1 : 0; |
564 | 4 | int digit_count = dot_pos - start; |
565 | | |
566 | | // There is no need to add commas. |
567 | 4 | if (digit_count <= 3) { |
568 | 2 | return formatted_num; |
569 | 2 | } |
570 | | |
571 | 2 | std::string result; |
572 | | |
573 | 2 | if (start == 1) result += '-'; |
574 | | |
575 | | // Add the integer part (with comma) |
576 | 2 | int first_group = digit_count % 3; |
577 | 2 | if (first_group == 0) first_group = 3; |
578 | 2 | result.append(formatted_num, start, first_group); |
579 | | |
580 | 6 | for (size_t i = start + first_group; i < dot_pos; i += 3) { |
581 | 4 | result += ','; |
582 | 4 | result.append(formatted_num, i, 3); |
583 | 4 | } |
584 | | |
585 | | // Add the decimal part (keep as it is) |
586 | 2 | if (dot_pos != formatted_num.size()) { |
587 | 2 | result.append(formatted_num, dot_pos); |
588 | 2 | } |
589 | | |
590 | 2 | return result; |
591 | 4 | } |
592 | | |
593 | | template <bool is_const> |
594 | | static Status execute(FunctionContext* context, ColumnString* result_column, |
595 | | const ColumnPtr col_ptr, ColumnPtr decimal_places_col_ptr, |
596 | 1 | size_t input_rows_count) { |
597 | 1 | const auto& arg_column_data_2 = |
598 | 1 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); |
599 | 1 | const auto* data_column = assert_cast<const ColumnFloat64*>(col_ptr.get()); |
600 | | // when scale is above 38, we will go here |
601 | 5 | for (size_t i = 0; i < input_rows_count; i++) { |
602 | 4 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; |
603 | 4 | if (decimal_places < 0 || decimal_places > 1024) { |
604 | 0 | return Status::InvalidArgument( |
605 | 0 | "The second argument is {}, it should be in range [0, 1024].", |
606 | 0 | decimal_places); |
607 | 0 | } |
608 | | // round to `decimal_places` decimal places |
609 | 4 | double value = MathFunctions::my_double_round(data_column->get_element(i), |
610 | 4 | decimal_places, false, false); |
611 | 4 | std::string formatted_value = fmt::format("{:.{}f}", value, decimal_places); |
612 | 4 | if (std::isfinite(value)) { |
613 | 4 | result_column->insert_value(add_thousands_separator(formatted_value)); |
614 | 4 | } else { |
615 | | // if value is not finite, we just insert the original formatted value |
616 | | // e.g. "inf", "-inf", "nan" |
617 | 0 | result_column->insert_value(formatted_value); |
618 | 0 | } |
619 | 4 | } |
620 | 1 | return Status::OK(); |
621 | 1 | } Unexecuted instantiation: _ZN5doris21FormatRoundDoubleImpl7executeILb1EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EESC_m _ZN5doris21FormatRoundDoubleImpl7executeILb0EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EESC_m Line | Count | Source | 596 | 1 | size_t input_rows_count) { | 597 | 1 | const auto& arg_column_data_2 = | 598 | 1 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); | 599 | 1 | const auto* data_column = assert_cast<const ColumnFloat64*>(col_ptr.get()); | 600 | | // when scale is above 38, we will go here | 601 | 5 | for (size_t i = 0; i < input_rows_count; i++) { | 602 | 4 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 603 | 4 | if (decimal_places < 0 || decimal_places > 1024) { | 604 | 0 | return Status::InvalidArgument( | 605 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 606 | 0 | decimal_places); | 607 | 0 | } | 608 | | // round to `decimal_places` decimal places | 609 | 4 | double value = MathFunctions::my_double_round(data_column->get_element(i), | 610 | 4 | decimal_places, false, false); | 611 | 4 | std::string formatted_value = fmt::format("{:.{}f}", value, decimal_places); | 612 | 4 | if (std::isfinite(value)) { | 613 | 4 | result_column->insert_value(add_thousands_separator(formatted_value)); | 614 | 4 | } else { | 615 | | // if value is not finite, we just insert the original formatted value | 616 | | // e.g. "inf", "-inf", "nan" | 617 | 0 | result_column->insert_value(formatted_value); | 618 | 0 | } | 619 | 4 | } | 620 | 1 | return Status::OK(); | 621 | 1 | } |
|
622 | | }; |
623 | | |
624 | | struct FormatRoundInt64Impl { |
625 | 1 | static DataTypes get_variadic_argument_types() { |
626 | 1 | return {std::make_shared<DataTypeInt64>(), std::make_shared<DataTypeInt32>()}; |
627 | 1 | } |
628 | | |
629 | | template <bool is_const> |
630 | | static Status execute(FunctionContext* context, ColumnString* result_column, |
631 | | const ColumnPtr col_ptr, ColumnPtr decimal_places_col_ptr, |
632 | 8 | size_t input_rows_count) { |
633 | 8 | const auto* data_column = assert_cast<const ColumnInt64*>(col_ptr.get()); |
634 | 8 | const auto& arg_column_data_2 = |
635 | 8 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); |
636 | 24 | for (size_t i = 0; i < input_rows_count; i++) { |
637 | 16 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; |
638 | 16 | if (decimal_places < 0 || decimal_places > 1024) { |
639 | 0 | return Status::InvalidArgument( |
640 | 0 | "The second argument is {}, it should be in range [0, 1024].", |
641 | 0 | decimal_places); |
642 | 0 | } |
643 | 16 | Int64 value = data_column->get_element(i); |
644 | 16 | StringRef str = |
645 | 16 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_INT64()>( |
646 | 16 | context, 0, value, 0, decimal_places); |
647 | 16 | result_column->insert_data(str.data, str.size); |
648 | 16 | } |
649 | 8 | return Status::OK(); |
650 | 8 | } _ZN5doris20FormatRoundInt64Impl7executeILb1EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EESC_m Line | Count | Source | 632 | 2 | size_t input_rows_count) { | 633 | 2 | const auto* data_column = assert_cast<const ColumnInt64*>(col_ptr.get()); | 634 | 2 | const auto& arg_column_data_2 = | 635 | 2 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); | 636 | 4 | for (size_t i = 0; i < input_rows_count; i++) { | 637 | 2 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 638 | 2 | if (decimal_places < 0 || decimal_places > 1024) { | 639 | 0 | return Status::InvalidArgument( | 640 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 641 | 0 | decimal_places); | 642 | 0 | } | 643 | 2 | Int64 value = data_column->get_element(i); | 644 | 2 | StringRef str = | 645 | 2 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_INT64()>( | 646 | 2 | context, 0, value, 0, decimal_places); | 647 | 2 | result_column->insert_data(str.data, str.size); | 648 | 2 | } | 649 | 2 | return Status::OK(); | 650 | 2 | } |
_ZN5doris20FormatRoundInt64Impl7executeILb0EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EESC_m Line | Count | Source | 632 | 6 | size_t input_rows_count) { | 633 | 6 | const auto* data_column = assert_cast<const ColumnInt64*>(col_ptr.get()); | 634 | 6 | const auto& arg_column_data_2 = | 635 | 6 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); | 636 | 20 | for (size_t i = 0; i < input_rows_count; i++) { | 637 | 14 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 638 | 14 | if (decimal_places < 0 || decimal_places > 1024) { | 639 | 0 | return Status::InvalidArgument( | 640 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 641 | 0 | decimal_places); | 642 | 0 | } | 643 | 14 | Int64 value = data_column->get_element(i); | 644 | 14 | StringRef str = | 645 | 14 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_INT64()>( | 646 | 14 | context, 0, value, 0, decimal_places); | 647 | 14 | result_column->insert_data(str.data, str.size); | 648 | 14 | } | 649 | 6 | return Status::OK(); | 650 | 6 | } |
|
651 | | }; |
652 | | |
653 | | struct FormatRoundInt128Impl { |
654 | 1 | static DataTypes get_variadic_argument_types() { |
655 | 1 | return {std::make_shared<DataTypeInt128>(), std::make_shared<DataTypeInt32>()}; |
656 | 1 | } |
657 | | |
658 | | template <bool is_const> |
659 | | static Status execute(FunctionContext* context, ColumnString* result_column, |
660 | | const ColumnPtr col_ptr, ColumnPtr decimal_places_col_ptr, |
661 | 5 | size_t input_rows_count) { |
662 | 5 | const auto* data_column = assert_cast<const ColumnInt128*>(col_ptr.get()); |
663 | 5 | const auto& arg_column_data_2 = |
664 | 5 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); |
665 | | // SELECT money_format(170141183460469231731687303715884105728/*INT128_MAX + 1*/) will |
666 | | // get "170,141,183,460,469,231,731,687,303,715,884,105,727.00" in doris, |
667 | | // see https://github.com/apache/doris/blob/788abf2d7c3c7c2d57487a9608e889e7662d5fb2/be/src/vec/data_types/data_type_number_base.cpp#L124 |
668 | 18 | for (size_t i = 0; i < input_rows_count; i++) { |
669 | 13 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; |
670 | 13 | if (decimal_places < 0 || decimal_places > 1024) { |
671 | 0 | return Status::InvalidArgument( |
672 | 0 | "The second argument is {}, it should be in range [0, 1024].", |
673 | 0 | decimal_places); |
674 | 0 | } |
675 | 13 | Int128 value = data_column->get_element(i); |
676 | 13 | StringRef str = |
677 | 13 | FormatRound::do_format_round<Int128, FormatRound::MAX_FORMAT_LEN_INT128()>( |
678 | 13 | context, 0, value, 0, decimal_places); |
679 | 13 | result_column->insert_data(str.data, str.size); |
680 | 13 | } |
681 | 5 | return Status::OK(); |
682 | 5 | } _ZN5doris21FormatRoundInt128Impl7executeILb1EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EESC_m Line | Count | Source | 661 | 1 | size_t input_rows_count) { | 662 | 1 | const auto* data_column = assert_cast<const ColumnInt128*>(col_ptr.get()); | 663 | 1 | const auto& arg_column_data_2 = | 664 | 1 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); | 665 | | // SELECT money_format(170141183460469231731687303715884105728/*INT128_MAX + 1*/) will | 666 | | // get "170,141,183,460,469,231,731,687,303,715,884,105,727.00" in doris, | 667 | | // see https://github.com/apache/doris/blob/788abf2d7c3c7c2d57487a9608e889e7662d5fb2/be/src/vec/data_types/data_type_number_base.cpp#L124 | 668 | 2 | for (size_t i = 0; i < input_rows_count; i++) { | 669 | 1 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 670 | 1 | if (decimal_places < 0 || decimal_places > 1024) { | 671 | 0 | return Status::InvalidArgument( | 672 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 673 | 0 | decimal_places); | 674 | 0 | } | 675 | 1 | Int128 value = data_column->get_element(i); | 676 | 1 | StringRef str = | 677 | 1 | FormatRound::do_format_round<Int128, FormatRound::MAX_FORMAT_LEN_INT128()>( | 678 | 1 | context, 0, value, 0, decimal_places); | 679 | 1 | result_column->insert_data(str.data, str.size); | 680 | 1 | } | 681 | 1 | return Status::OK(); | 682 | 1 | } |
_ZN5doris21FormatRoundInt128Impl7executeILb0EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EESC_m Line | Count | Source | 661 | 4 | size_t input_rows_count) { | 662 | 4 | const auto* data_column = assert_cast<const ColumnInt128*>(col_ptr.get()); | 663 | 4 | const auto& arg_column_data_2 = | 664 | 4 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); | 665 | | // SELECT money_format(170141183460469231731687303715884105728/*INT128_MAX + 1*/) will | 666 | | // get "170,141,183,460,469,231,731,687,303,715,884,105,727.00" in doris, | 667 | | // see https://github.com/apache/doris/blob/788abf2d7c3c7c2d57487a9608e889e7662d5fb2/be/src/vec/data_types/data_type_number_base.cpp#L124 | 668 | 16 | for (size_t i = 0; i < input_rows_count; i++) { | 669 | 12 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 670 | 12 | if (decimal_places < 0 || decimal_places > 1024) { | 671 | 0 | return Status::InvalidArgument( | 672 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 673 | 0 | decimal_places); | 674 | 0 | } | 675 | 12 | Int128 value = data_column->get_element(i); | 676 | 12 | StringRef str = | 677 | 12 | FormatRound::do_format_round<Int128, FormatRound::MAX_FORMAT_LEN_INT128()>( | 678 | 12 | context, 0, value, 0, decimal_places); | 679 | 12 | result_column->insert_data(str.data, str.size); | 680 | 12 | } | 681 | 4 | return Status::OK(); | 682 | 4 | } |
|
683 | | }; |
684 | | |
685 | | template <PrimitiveType Type> |
686 | | struct FormatRoundDecimalImpl { |
687 | 5 | static DataTypes get_variadic_argument_types() { |
688 | 5 | return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>(), |
689 | 5 | std::make_shared<DataTypeInt32>()}; |
690 | 5 | } _ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE20EE27get_variadic_argument_typesEv Line | Count | Source | 687 | 1 | static DataTypes get_variadic_argument_types() { | 688 | 1 | return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>(), | 689 | 1 | std::make_shared<DataTypeInt32>()}; | 690 | 1 | } |
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EE27get_variadic_argument_typesEv Line | Count | Source | 687 | 1 | static DataTypes get_variadic_argument_types() { | 688 | 1 | return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>(), | 689 | 1 | std::make_shared<DataTypeInt32>()}; | 690 | 1 | } |
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EE27get_variadic_argument_typesEv Line | Count | Source | 687 | 1 | static DataTypes get_variadic_argument_types() { | 688 | 1 | return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>(), | 689 | 1 | std::make_shared<DataTypeInt32>()}; | 690 | 1 | } |
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EE27get_variadic_argument_typesEv Line | Count | Source | 687 | 1 | static DataTypes get_variadic_argument_types() { | 688 | 1 | return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>(), | 689 | 1 | std::make_shared<DataTypeInt32>()}; | 690 | 1 | } |
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EE27get_variadic_argument_typesEv Line | Count | Source | 687 | 1 | static DataTypes get_variadic_argument_types() { | 688 | 1 | return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>(), | 689 | 1 | std::make_shared<DataTypeInt32>()}; | 690 | 1 | } |
|
691 | | |
692 | | template <bool is_const> |
693 | | static Status execute(FunctionContext* context, ColumnString* result_column, ColumnPtr col_ptr, |
694 | 838 | ColumnPtr decimal_places_col_ptr, size_t input_rows_count) { |
695 | 838 | const auto& arg_column_data_2 = |
696 | 838 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); |
697 | 838 | if (const auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) { |
698 | 4 | for (size_t i = 0; i < input_rows_count; i++) { |
699 | 3 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; |
700 | 3 | if (decimal_places < 0 || decimal_places > 1024) { |
701 | 0 | return Status::InvalidArgument( |
702 | 0 | "The second argument is {}, it should be in range [0, 1024].", |
703 | 0 | decimal_places); |
704 | 0 | } |
705 | 3 | const auto& value = decimalv2_column->get_element(i); |
706 | | // unified_frac_value has 3 digits |
707 | 3 | auto unified_frac_value = value.frac_value() / 1000000; |
708 | 3 | StringRef str = |
709 | 3 | FormatRound::do_format_round<Int128, |
710 | 3 | FormatRound::MAX_FORMAT_LEN_DEC128V2()>( |
711 | 3 | context, 3, value.int_value(), unified_frac_value, decimal_places); |
712 | | |
713 | 3 | result_column->insert_data(str.data, str.size); |
714 | 3 | } |
715 | 837 | } else if (const auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) { |
716 | 136 | const UInt32 scale = decimal32_column->get_scale(); |
717 | 318 | for (size_t i = 0; i < input_rows_count; i++) { |
718 | 182 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; |
719 | 182 | if (decimal_places < 0 || decimal_places > 1024) { |
720 | 0 | return Status::InvalidArgument( |
721 | 0 | "The second argument is {}, it should be in range [0, 1024].", |
722 | 0 | decimal_places); |
723 | 0 | } |
724 | 182 | const Int32& frac_part = decimal32_column->get_fractional_part(i); |
725 | 182 | const Int32& whole_part = decimal32_column->get_intergral_part(i); |
726 | 182 | StringRef str = |
727 | 182 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC32()>( |
728 | 182 | context, scale, static_cast<Int64>(whole_part), |
729 | 182 | static_cast<Int64>(frac_part), decimal_places); |
730 | | |
731 | 182 | result_column->insert_data(str.data, str.size); |
732 | 182 | } |
733 | 701 | } else if (const auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) { |
734 | 175 | const UInt32 scale = decimal64_column->get_scale(); |
735 | 408 | for (size_t i = 0; i < input_rows_count; i++) { |
736 | 233 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; |
737 | 233 | if (decimal_places < 0 || decimal_places > 1024) { |
738 | 0 | return Status::InvalidArgument( |
739 | 0 | "The second argument is {}, it should be in range [0, 1024].", |
740 | 0 | decimal_places); |
741 | 0 | } |
742 | 233 | const Int64& frac_part = decimal64_column->get_fractional_part(i); |
743 | 233 | const Int64& whole_part = decimal64_column->get_intergral_part(i); |
744 | | |
745 | 233 | StringRef str = |
746 | 233 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC64()>( |
747 | 233 | context, scale, whole_part, frac_part, decimal_places); |
748 | | |
749 | 233 | result_column->insert_data(str.data, str.size); |
750 | 233 | } |
751 | 526 | } else if (const auto* decimal128_column = |
752 | 526 | check_and_get_column<ColumnDecimal128V3>(*col_ptr)) { |
753 | 294 | const UInt32 scale = decimal128_column->get_scale(); |
754 | 686 | for (size_t i = 0; i < input_rows_count; i++) { |
755 | 392 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; |
756 | 392 | if (decimal_places < 0 || decimal_places > 1024) { |
757 | 0 | return Status::InvalidArgument( |
758 | 0 | "The second argument is {}, it should be in range [0, 1024].", |
759 | 0 | decimal_places); |
760 | 0 | } |
761 | 392 | const Int128& frac_part = decimal128_column->get_fractional_part(i); |
762 | 392 | const Int128& whole_part = decimal128_column->get_intergral_part(i); |
763 | | |
764 | 392 | StringRef str = |
765 | 392 | FormatRound::do_format_round<Int128, |
766 | 392 | FormatRound::MAX_FORMAT_LEN_DEC128V3()>( |
767 | 392 | context, scale, whole_part, frac_part, decimal_places); |
768 | | |
769 | 392 | result_column->insert_data(str.data, str.size); |
770 | 392 | } |
771 | 294 | } else if (const auto* decimal256_column = |
772 | 232 | check_and_get_column<ColumnDecimal256>(*col_ptr)) { |
773 | 232 | const UInt32 scale = decimal256_column->get_scale(); |
774 | 538 | for (size_t i = 0; i < input_rows_count; i++) { |
775 | 306 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; |
776 | 306 | if (decimal_places < 0 || decimal_places > 1024) { |
777 | 0 | return Status::InvalidArgument( |
778 | 0 | "The second argument is {}, it should be in range [0, 1024].", |
779 | 0 | decimal_places); |
780 | 0 | } |
781 | 306 | const auto frac_part = decimal256_column->get_fractional_part(i); |
782 | 306 | const auto whole_part = decimal256_column->get_intergral_part(i); |
783 | 306 | StringRef str = FormatRound::do_format_round<wide::Int256, |
784 | 306 | FormatRound::MAX_FORMAT_LEN_DEC256()>( |
785 | 306 | context, scale, whole_part, frac_part, decimal_places); |
786 | | |
787 | 306 | result_column->insert_data(str.data, str.size); |
788 | 306 | } |
789 | 232 | } else { |
790 | 0 | return Status::InternalError("Not supported input argument type {}", |
791 | 0 | col_ptr->get_name()); |
792 | 0 | } |
793 | 838 | return Status::OK(); |
794 | 838 | } Unexecuted instantiation: _ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE20EE7executeILb1EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m _ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE20EE7executeILb0EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m Line | Count | Source | 694 | 1 | ColumnPtr decimal_places_col_ptr, size_t input_rows_count) { | 695 | 1 | const auto& arg_column_data_2 = | 696 | 1 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); | 697 | 1 | if (const auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) { | 698 | 4 | for (size_t i = 0; i < input_rows_count; i++) { | 699 | 3 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 700 | 3 | if (decimal_places < 0 || decimal_places > 1024) { | 701 | 0 | return Status::InvalidArgument( | 702 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 703 | 0 | decimal_places); | 704 | 0 | } | 705 | 3 | const auto& value = decimalv2_column->get_element(i); | 706 | | // unified_frac_value has 3 digits | 707 | 3 | auto unified_frac_value = value.frac_value() / 1000000; | 708 | 3 | StringRef str = | 709 | 3 | FormatRound::do_format_round<Int128, | 710 | 3 | FormatRound::MAX_FORMAT_LEN_DEC128V2()>( | 711 | 3 | context, 3, value.int_value(), unified_frac_value, decimal_places); | 712 | | | 713 | 3 | result_column->insert_data(str.data, str.size); | 714 | 3 | } | 715 | 1 | } else if (const auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) { | 716 | 0 | const UInt32 scale = decimal32_column->get_scale(); | 717 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 718 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 719 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 720 | 0 | return Status::InvalidArgument( | 721 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 722 | 0 | decimal_places); | 723 | 0 | } | 724 | 0 | const Int32& frac_part = decimal32_column->get_fractional_part(i); | 725 | 0 | const Int32& whole_part = decimal32_column->get_intergral_part(i); | 726 | 0 | StringRef str = | 727 | 0 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC32()>( | 728 | 0 | context, scale, static_cast<Int64>(whole_part), | 729 | 0 | static_cast<Int64>(frac_part), decimal_places); | 730 | |
| 731 | 0 | result_column->insert_data(str.data, str.size); | 732 | 0 | } | 733 | 0 | } else if (const auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) { | 734 | 0 | const UInt32 scale = decimal64_column->get_scale(); | 735 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 736 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 737 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 738 | 0 | return Status::InvalidArgument( | 739 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 740 | 0 | decimal_places); | 741 | 0 | } | 742 | 0 | const Int64& frac_part = decimal64_column->get_fractional_part(i); | 743 | 0 | const Int64& whole_part = decimal64_column->get_intergral_part(i); | 744 | |
| 745 | 0 | StringRef str = | 746 | 0 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC64()>( | 747 | 0 | context, scale, whole_part, frac_part, decimal_places); | 748 | |
| 749 | 0 | result_column->insert_data(str.data, str.size); | 750 | 0 | } | 751 | 0 | } else if (const auto* decimal128_column = | 752 | 0 | check_and_get_column<ColumnDecimal128V3>(*col_ptr)) { | 753 | 0 | const UInt32 scale = decimal128_column->get_scale(); | 754 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 755 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 756 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 757 | 0 | return Status::InvalidArgument( | 758 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 759 | 0 | decimal_places); | 760 | 0 | } | 761 | 0 | const Int128& frac_part = decimal128_column->get_fractional_part(i); | 762 | 0 | const Int128& whole_part = decimal128_column->get_intergral_part(i); | 763 | |
| 764 | 0 | StringRef str = | 765 | 0 | FormatRound::do_format_round<Int128, | 766 | 0 | FormatRound::MAX_FORMAT_LEN_DEC128V3()>( | 767 | 0 | context, scale, whole_part, frac_part, decimal_places); | 768 | |
| 769 | 0 | result_column->insert_data(str.data, str.size); | 770 | 0 | } | 771 | 0 | } else if (const auto* decimal256_column = | 772 | 0 | check_and_get_column<ColumnDecimal256>(*col_ptr)) { | 773 | 0 | const UInt32 scale = decimal256_column->get_scale(); | 774 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 775 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 776 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 777 | 0 | return Status::InvalidArgument( | 778 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 779 | 0 | decimal_places); | 780 | 0 | } | 781 | 0 | const auto frac_part = decimal256_column->get_fractional_part(i); | 782 | 0 | const auto whole_part = decimal256_column->get_intergral_part(i); | 783 | 0 | StringRef str = FormatRound::do_format_round<wide::Int256, | 784 | 0 | FormatRound::MAX_FORMAT_LEN_DEC256()>( | 785 | 0 | context, scale, whole_part, frac_part, decimal_places); | 786 | |
| 787 | 0 | result_column->insert_data(str.data, str.size); | 788 | 0 | } | 789 | 0 | } else { | 790 | 0 | return Status::InternalError("Not supported input argument type {}", | 791 | 0 | col_ptr->get_name()); | 792 | 0 | } | 793 | 1 | return Status::OK(); | 794 | 1 | } |
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EE7executeILb1EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m Line | Count | Source | 694 | 45 | ColumnPtr decimal_places_col_ptr, size_t input_rows_count) { | 695 | 45 | const auto& arg_column_data_2 = | 696 | 45 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); | 697 | 45 | if (const auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) { | 698 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 699 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 700 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 701 | 0 | return Status::InvalidArgument( | 702 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 703 | 0 | decimal_places); | 704 | 0 | } | 705 | 0 | const auto& value = decimalv2_column->get_element(i); | 706 | | // unified_frac_value has 3 digits | 707 | 0 | auto unified_frac_value = value.frac_value() / 1000000; | 708 | 0 | StringRef str = | 709 | 0 | FormatRound::do_format_round<Int128, | 710 | 0 | FormatRound::MAX_FORMAT_LEN_DEC128V2()>( | 711 | 0 | context, 3, value.int_value(), unified_frac_value, decimal_places); | 712 | |
| 713 | 0 | result_column->insert_data(str.data, str.size); | 714 | 0 | } | 715 | 45 | } else if (const auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) { | 716 | 45 | const UInt32 scale = decimal32_column->get_scale(); | 717 | 90 | for (size_t i = 0; i < input_rows_count; i++) { | 718 | 45 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 719 | 45 | if (decimal_places < 0 || decimal_places > 1024) { | 720 | 0 | return Status::InvalidArgument( | 721 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 722 | 0 | decimal_places); | 723 | 0 | } | 724 | 45 | const Int32& frac_part = decimal32_column->get_fractional_part(i); | 725 | 45 | const Int32& whole_part = decimal32_column->get_intergral_part(i); | 726 | 45 | StringRef str = | 727 | 45 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC32()>( | 728 | 45 | context, scale, static_cast<Int64>(whole_part), | 729 | 45 | static_cast<Int64>(frac_part), decimal_places); | 730 | | | 731 | 45 | result_column->insert_data(str.data, str.size); | 732 | 45 | } | 733 | 45 | } else if (const auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) { | 734 | 0 | const UInt32 scale = decimal64_column->get_scale(); | 735 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 736 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 737 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 738 | 0 | return Status::InvalidArgument( | 739 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 740 | 0 | decimal_places); | 741 | 0 | } | 742 | 0 | const Int64& frac_part = decimal64_column->get_fractional_part(i); | 743 | 0 | const Int64& whole_part = decimal64_column->get_intergral_part(i); | 744 | |
| 745 | 0 | StringRef str = | 746 | 0 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC64()>( | 747 | 0 | context, scale, whole_part, frac_part, decimal_places); | 748 | |
| 749 | 0 | result_column->insert_data(str.data, str.size); | 750 | 0 | } | 751 | 0 | } else if (const auto* decimal128_column = | 752 | 0 | check_and_get_column<ColumnDecimal128V3>(*col_ptr)) { | 753 | 0 | const UInt32 scale = decimal128_column->get_scale(); | 754 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 755 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 756 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 757 | 0 | return Status::InvalidArgument( | 758 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 759 | 0 | decimal_places); | 760 | 0 | } | 761 | 0 | const Int128& frac_part = decimal128_column->get_fractional_part(i); | 762 | 0 | const Int128& whole_part = decimal128_column->get_intergral_part(i); | 763 | |
| 764 | 0 | StringRef str = | 765 | 0 | FormatRound::do_format_round<Int128, | 766 | 0 | FormatRound::MAX_FORMAT_LEN_DEC128V3()>( | 767 | 0 | context, scale, whole_part, frac_part, decimal_places); | 768 | |
| 769 | 0 | result_column->insert_data(str.data, str.size); | 770 | 0 | } | 771 | 0 | } else if (const auto* decimal256_column = | 772 | 0 | check_and_get_column<ColumnDecimal256>(*col_ptr)) { | 773 | 0 | const UInt32 scale = decimal256_column->get_scale(); | 774 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 775 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 776 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 777 | 0 | return Status::InvalidArgument( | 778 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 779 | 0 | decimal_places); | 780 | 0 | } | 781 | 0 | const auto frac_part = decimal256_column->get_fractional_part(i); | 782 | 0 | const auto whole_part = decimal256_column->get_intergral_part(i); | 783 | 0 | StringRef str = FormatRound::do_format_round<wide::Int256, | 784 | 0 | FormatRound::MAX_FORMAT_LEN_DEC256()>( | 785 | 0 | context, scale, whole_part, frac_part, decimal_places); | 786 | |
| 787 | 0 | result_column->insert_data(str.data, str.size); | 788 | 0 | } | 789 | 0 | } else { | 790 | 0 | return Status::InternalError("Not supported input argument type {}", | 791 | 0 | col_ptr->get_name()); | 792 | 0 | } | 793 | 45 | return Status::OK(); | 794 | 45 | } |
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EE7executeILb0EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m Line | Count | Source | 694 | 91 | ColumnPtr decimal_places_col_ptr, size_t input_rows_count) { | 695 | 91 | const auto& arg_column_data_2 = | 696 | 91 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); | 697 | 91 | if (const auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) { | 698 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 699 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 700 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 701 | 0 | return Status::InvalidArgument( | 702 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 703 | 0 | decimal_places); | 704 | 0 | } | 705 | 0 | const auto& value = decimalv2_column->get_element(i); | 706 | | // unified_frac_value has 3 digits | 707 | 0 | auto unified_frac_value = value.frac_value() / 1000000; | 708 | 0 | StringRef str = | 709 | 0 | FormatRound::do_format_round<Int128, | 710 | 0 | FormatRound::MAX_FORMAT_LEN_DEC128V2()>( | 711 | 0 | context, 3, value.int_value(), unified_frac_value, decimal_places); | 712 | |
| 713 | 0 | result_column->insert_data(str.data, str.size); | 714 | 0 | } | 715 | 91 | } else if (const auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) { | 716 | 91 | const UInt32 scale = decimal32_column->get_scale(); | 717 | 228 | for (size_t i = 0; i < input_rows_count; i++) { | 718 | 137 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 719 | 137 | if (decimal_places < 0 || decimal_places > 1024) { | 720 | 0 | return Status::InvalidArgument( | 721 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 722 | 0 | decimal_places); | 723 | 0 | } | 724 | 137 | const Int32& frac_part = decimal32_column->get_fractional_part(i); | 725 | 137 | const Int32& whole_part = decimal32_column->get_intergral_part(i); | 726 | 137 | StringRef str = | 727 | 137 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC32()>( | 728 | 137 | context, scale, static_cast<Int64>(whole_part), | 729 | 137 | static_cast<Int64>(frac_part), decimal_places); | 730 | | | 731 | 137 | result_column->insert_data(str.data, str.size); | 732 | 137 | } | 733 | 91 | } else if (const auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) { | 734 | 0 | const UInt32 scale = decimal64_column->get_scale(); | 735 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 736 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 737 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 738 | 0 | return Status::InvalidArgument( | 739 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 740 | 0 | decimal_places); | 741 | 0 | } | 742 | 0 | const Int64& frac_part = decimal64_column->get_fractional_part(i); | 743 | 0 | const Int64& whole_part = decimal64_column->get_intergral_part(i); | 744 | |
| 745 | 0 | StringRef str = | 746 | 0 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC64()>( | 747 | 0 | context, scale, whole_part, frac_part, decimal_places); | 748 | |
| 749 | 0 | result_column->insert_data(str.data, str.size); | 750 | 0 | } | 751 | 0 | } else if (const auto* decimal128_column = | 752 | 0 | check_and_get_column<ColumnDecimal128V3>(*col_ptr)) { | 753 | 0 | const UInt32 scale = decimal128_column->get_scale(); | 754 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 755 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 756 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 757 | 0 | return Status::InvalidArgument( | 758 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 759 | 0 | decimal_places); | 760 | 0 | } | 761 | 0 | const Int128& frac_part = decimal128_column->get_fractional_part(i); | 762 | 0 | const Int128& whole_part = decimal128_column->get_intergral_part(i); | 763 | |
| 764 | 0 | StringRef str = | 765 | 0 | FormatRound::do_format_round<Int128, | 766 | 0 | FormatRound::MAX_FORMAT_LEN_DEC128V3()>( | 767 | 0 | context, scale, whole_part, frac_part, decimal_places); | 768 | |
| 769 | 0 | result_column->insert_data(str.data, str.size); | 770 | 0 | } | 771 | 0 | } else if (const auto* decimal256_column = | 772 | 0 | check_and_get_column<ColumnDecimal256>(*col_ptr)) { | 773 | 0 | const UInt32 scale = decimal256_column->get_scale(); | 774 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 775 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 776 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 777 | 0 | return Status::InvalidArgument( | 778 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 779 | 0 | decimal_places); | 780 | 0 | } | 781 | 0 | const auto frac_part = decimal256_column->get_fractional_part(i); | 782 | 0 | const auto whole_part = decimal256_column->get_intergral_part(i); | 783 | 0 | StringRef str = FormatRound::do_format_round<wide::Int256, | 784 | 0 | FormatRound::MAX_FORMAT_LEN_DEC256()>( | 785 | 0 | context, scale, whole_part, frac_part, decimal_places); | 786 | |
| 787 | 0 | result_column->insert_data(str.data, str.size); | 788 | 0 | } | 789 | 0 | } else { | 790 | 0 | return Status::InternalError("Not supported input argument type {}", | 791 | 0 | col_ptr->get_name()); | 792 | 0 | } | 793 | 91 | return Status::OK(); | 794 | 91 | } |
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EE7executeILb1EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m Line | Count | Source | 694 | 57 | ColumnPtr decimal_places_col_ptr, size_t input_rows_count) { | 695 | 57 | const auto& arg_column_data_2 = | 696 | 57 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); | 697 | 57 | if (const auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) { | 698 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 699 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 700 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 701 | 0 | return Status::InvalidArgument( | 702 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 703 | 0 | decimal_places); | 704 | 0 | } | 705 | 0 | const auto& value = decimalv2_column->get_element(i); | 706 | | // unified_frac_value has 3 digits | 707 | 0 | auto unified_frac_value = value.frac_value() / 1000000; | 708 | 0 | StringRef str = | 709 | 0 | FormatRound::do_format_round<Int128, | 710 | 0 | FormatRound::MAX_FORMAT_LEN_DEC128V2()>( | 711 | 0 | context, 3, value.int_value(), unified_frac_value, decimal_places); | 712 | |
| 713 | 0 | result_column->insert_data(str.data, str.size); | 714 | 0 | } | 715 | 57 | } else if (const auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) { | 716 | 0 | const UInt32 scale = decimal32_column->get_scale(); | 717 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 718 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 719 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 720 | 0 | return Status::InvalidArgument( | 721 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 722 | 0 | decimal_places); | 723 | 0 | } | 724 | 0 | const Int32& frac_part = decimal32_column->get_fractional_part(i); | 725 | 0 | const Int32& whole_part = decimal32_column->get_intergral_part(i); | 726 | 0 | StringRef str = | 727 | 0 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC32()>( | 728 | 0 | context, scale, static_cast<Int64>(whole_part), | 729 | 0 | static_cast<Int64>(frac_part), decimal_places); | 730 | |
| 731 | 0 | result_column->insert_data(str.data, str.size); | 732 | 0 | } | 733 | 57 | } else if (const auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) { | 734 | 57 | const UInt32 scale = decimal64_column->get_scale(); | 735 | 114 | for (size_t i = 0; i < input_rows_count; i++) { | 736 | 57 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 737 | 57 | if (decimal_places < 0 || decimal_places > 1024) { | 738 | 0 | return Status::InvalidArgument( | 739 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 740 | 0 | decimal_places); | 741 | 0 | } | 742 | 57 | const Int64& frac_part = decimal64_column->get_fractional_part(i); | 743 | 57 | const Int64& whole_part = decimal64_column->get_intergral_part(i); | 744 | | | 745 | 57 | StringRef str = | 746 | 57 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC64()>( | 747 | 57 | context, scale, whole_part, frac_part, decimal_places); | 748 | | | 749 | 57 | result_column->insert_data(str.data, str.size); | 750 | 57 | } | 751 | 57 | } else if (const auto* decimal128_column = | 752 | 0 | check_and_get_column<ColumnDecimal128V3>(*col_ptr)) { | 753 | 0 | const UInt32 scale = decimal128_column->get_scale(); | 754 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 755 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 756 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 757 | 0 | return Status::InvalidArgument( | 758 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 759 | 0 | decimal_places); | 760 | 0 | } | 761 | 0 | const Int128& frac_part = decimal128_column->get_fractional_part(i); | 762 | 0 | const Int128& whole_part = decimal128_column->get_intergral_part(i); | 763 | |
| 764 | 0 | StringRef str = | 765 | 0 | FormatRound::do_format_round<Int128, | 766 | 0 | FormatRound::MAX_FORMAT_LEN_DEC128V3()>( | 767 | 0 | context, scale, whole_part, frac_part, decimal_places); | 768 | |
| 769 | 0 | result_column->insert_data(str.data, str.size); | 770 | 0 | } | 771 | 0 | } else if (const auto* decimal256_column = | 772 | 0 | check_and_get_column<ColumnDecimal256>(*col_ptr)) { | 773 | 0 | const UInt32 scale = decimal256_column->get_scale(); | 774 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 775 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 776 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 777 | 0 | return Status::InvalidArgument( | 778 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 779 | 0 | decimal_places); | 780 | 0 | } | 781 | 0 | const auto frac_part = decimal256_column->get_fractional_part(i); | 782 | 0 | const auto whole_part = decimal256_column->get_intergral_part(i); | 783 | 0 | StringRef str = FormatRound::do_format_round<wide::Int256, | 784 | 0 | FormatRound::MAX_FORMAT_LEN_DEC256()>( | 785 | 0 | context, scale, whole_part, frac_part, decimal_places); | 786 | |
| 787 | 0 | result_column->insert_data(str.data, str.size); | 788 | 0 | } | 789 | 0 | } else { | 790 | 0 | return Status::InternalError("Not supported input argument type {}", | 791 | 0 | col_ptr->get_name()); | 792 | 0 | } | 793 | 57 | return Status::OK(); | 794 | 57 | } |
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EE7executeILb0EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m Line | Count | Source | 694 | 118 | ColumnPtr decimal_places_col_ptr, size_t input_rows_count) { | 695 | 118 | const auto& arg_column_data_2 = | 696 | 118 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); | 697 | 118 | if (const auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) { | 698 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 699 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 700 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 701 | 0 | return Status::InvalidArgument( | 702 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 703 | 0 | decimal_places); | 704 | 0 | } | 705 | 0 | const auto& value = decimalv2_column->get_element(i); | 706 | | // unified_frac_value has 3 digits | 707 | 0 | auto unified_frac_value = value.frac_value() / 1000000; | 708 | 0 | StringRef str = | 709 | 0 | FormatRound::do_format_round<Int128, | 710 | 0 | FormatRound::MAX_FORMAT_LEN_DEC128V2()>( | 711 | 0 | context, 3, value.int_value(), unified_frac_value, decimal_places); | 712 | |
| 713 | 0 | result_column->insert_data(str.data, str.size); | 714 | 0 | } | 715 | 118 | } else if (const auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) { | 716 | 0 | const UInt32 scale = decimal32_column->get_scale(); | 717 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 718 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 719 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 720 | 0 | return Status::InvalidArgument( | 721 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 722 | 0 | decimal_places); | 723 | 0 | } | 724 | 0 | const Int32& frac_part = decimal32_column->get_fractional_part(i); | 725 | 0 | const Int32& whole_part = decimal32_column->get_intergral_part(i); | 726 | 0 | StringRef str = | 727 | 0 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC32()>( | 728 | 0 | context, scale, static_cast<Int64>(whole_part), | 729 | 0 | static_cast<Int64>(frac_part), decimal_places); | 730 | |
| 731 | 0 | result_column->insert_data(str.data, str.size); | 732 | 0 | } | 733 | 118 | } else if (const auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) { | 734 | 118 | const UInt32 scale = decimal64_column->get_scale(); | 735 | 294 | for (size_t i = 0; i < input_rows_count; i++) { | 736 | 176 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 737 | 176 | if (decimal_places < 0 || decimal_places > 1024) { | 738 | 0 | return Status::InvalidArgument( | 739 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 740 | 0 | decimal_places); | 741 | 0 | } | 742 | 176 | const Int64& frac_part = decimal64_column->get_fractional_part(i); | 743 | 176 | const Int64& whole_part = decimal64_column->get_intergral_part(i); | 744 | | | 745 | 176 | StringRef str = | 746 | 176 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC64()>( | 747 | 176 | context, scale, whole_part, frac_part, decimal_places); | 748 | | | 749 | 176 | result_column->insert_data(str.data, str.size); | 750 | 176 | } | 751 | 118 | } else if (const auto* decimal128_column = | 752 | 0 | check_and_get_column<ColumnDecimal128V3>(*col_ptr)) { | 753 | 0 | const UInt32 scale = decimal128_column->get_scale(); | 754 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 755 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 756 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 757 | 0 | return Status::InvalidArgument( | 758 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 759 | 0 | decimal_places); | 760 | 0 | } | 761 | 0 | const Int128& frac_part = decimal128_column->get_fractional_part(i); | 762 | 0 | const Int128& whole_part = decimal128_column->get_intergral_part(i); | 763 | |
| 764 | 0 | StringRef str = | 765 | 0 | FormatRound::do_format_round<Int128, | 766 | 0 | FormatRound::MAX_FORMAT_LEN_DEC128V3()>( | 767 | 0 | context, scale, whole_part, frac_part, decimal_places); | 768 | |
| 769 | 0 | result_column->insert_data(str.data, str.size); | 770 | 0 | } | 771 | 0 | } else if (const auto* decimal256_column = | 772 | 0 | check_and_get_column<ColumnDecimal256>(*col_ptr)) { | 773 | 0 | const UInt32 scale = decimal256_column->get_scale(); | 774 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 775 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 776 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 777 | 0 | return Status::InvalidArgument( | 778 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 779 | 0 | decimal_places); | 780 | 0 | } | 781 | 0 | const auto frac_part = decimal256_column->get_fractional_part(i); | 782 | 0 | const auto whole_part = decimal256_column->get_intergral_part(i); | 783 | 0 | StringRef str = FormatRound::do_format_round<wide::Int256, | 784 | 0 | FormatRound::MAX_FORMAT_LEN_DEC256()>( | 785 | 0 | context, scale, whole_part, frac_part, decimal_places); | 786 | |
| 787 | 0 | result_column->insert_data(str.data, str.size); | 788 | 0 | } | 789 | 0 | } else { | 790 | 0 | return Status::InternalError("Not supported input argument type {}", | 791 | 0 | col_ptr->get_name()); | 792 | 0 | } | 793 | 118 | return Status::OK(); | 794 | 118 | } |
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EE7executeILb1EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m Line | Count | Source | 694 | 97 | ColumnPtr decimal_places_col_ptr, size_t input_rows_count) { | 695 | 97 | const auto& arg_column_data_2 = | 696 | 97 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); | 697 | 97 | if (const auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) { | 698 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 699 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 700 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 701 | 0 | return Status::InvalidArgument( | 702 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 703 | 0 | decimal_places); | 704 | 0 | } | 705 | 0 | const auto& value = decimalv2_column->get_element(i); | 706 | | // unified_frac_value has 3 digits | 707 | 0 | auto unified_frac_value = value.frac_value() / 1000000; | 708 | 0 | StringRef str = | 709 | 0 | FormatRound::do_format_round<Int128, | 710 | 0 | FormatRound::MAX_FORMAT_LEN_DEC128V2()>( | 711 | 0 | context, 3, value.int_value(), unified_frac_value, decimal_places); | 712 | |
| 713 | 0 | result_column->insert_data(str.data, str.size); | 714 | 0 | } | 715 | 97 | } else if (const auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) { | 716 | 0 | const UInt32 scale = decimal32_column->get_scale(); | 717 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 718 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 719 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 720 | 0 | return Status::InvalidArgument( | 721 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 722 | 0 | decimal_places); | 723 | 0 | } | 724 | 0 | const Int32& frac_part = decimal32_column->get_fractional_part(i); | 725 | 0 | const Int32& whole_part = decimal32_column->get_intergral_part(i); | 726 | 0 | StringRef str = | 727 | 0 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC32()>( | 728 | 0 | context, scale, static_cast<Int64>(whole_part), | 729 | 0 | static_cast<Int64>(frac_part), decimal_places); | 730 | |
| 731 | 0 | result_column->insert_data(str.data, str.size); | 732 | 0 | } | 733 | 97 | } else if (const auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) { | 734 | 0 | const UInt32 scale = decimal64_column->get_scale(); | 735 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 736 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 737 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 738 | 0 | return Status::InvalidArgument( | 739 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 740 | 0 | decimal_places); | 741 | 0 | } | 742 | 0 | const Int64& frac_part = decimal64_column->get_fractional_part(i); | 743 | 0 | const Int64& whole_part = decimal64_column->get_intergral_part(i); | 744 | |
| 745 | 0 | StringRef str = | 746 | 0 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC64()>( | 747 | 0 | context, scale, whole_part, frac_part, decimal_places); | 748 | |
| 749 | 0 | result_column->insert_data(str.data, str.size); | 750 | 0 | } | 751 | 97 | } else if (const auto* decimal128_column = | 752 | 97 | check_and_get_column<ColumnDecimal128V3>(*col_ptr)) { | 753 | 97 | const UInt32 scale = decimal128_column->get_scale(); | 754 | 194 | for (size_t i = 0; i < input_rows_count; i++) { | 755 | 97 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 756 | 97 | if (decimal_places < 0 || decimal_places > 1024) { | 757 | 0 | return Status::InvalidArgument( | 758 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 759 | 0 | decimal_places); | 760 | 0 | } | 761 | 97 | const Int128& frac_part = decimal128_column->get_fractional_part(i); | 762 | 97 | const Int128& whole_part = decimal128_column->get_intergral_part(i); | 763 | | | 764 | 97 | StringRef str = | 765 | 97 | FormatRound::do_format_round<Int128, | 766 | 97 | FormatRound::MAX_FORMAT_LEN_DEC128V3()>( | 767 | 97 | context, scale, whole_part, frac_part, decimal_places); | 768 | | | 769 | 97 | result_column->insert_data(str.data, str.size); | 770 | 97 | } | 771 | 97 | } else if (const auto* decimal256_column = | 772 | 0 | check_and_get_column<ColumnDecimal256>(*col_ptr)) { | 773 | 0 | const UInt32 scale = decimal256_column->get_scale(); | 774 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 775 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 776 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 777 | 0 | return Status::InvalidArgument( | 778 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 779 | 0 | decimal_places); | 780 | 0 | } | 781 | 0 | const auto frac_part = decimal256_column->get_fractional_part(i); | 782 | 0 | const auto whole_part = decimal256_column->get_intergral_part(i); | 783 | 0 | StringRef str = FormatRound::do_format_round<wide::Int256, | 784 | 0 | FormatRound::MAX_FORMAT_LEN_DEC256()>( | 785 | 0 | context, scale, whole_part, frac_part, decimal_places); | 786 | |
| 787 | 0 | result_column->insert_data(str.data, str.size); | 788 | 0 | } | 789 | 0 | } else { | 790 | 0 | return Status::InternalError("Not supported input argument type {}", | 791 | 0 | col_ptr->get_name()); | 792 | 0 | } | 793 | 97 | return Status::OK(); | 794 | 97 | } |
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EE7executeILb0EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m Line | Count | Source | 694 | 197 | ColumnPtr decimal_places_col_ptr, size_t input_rows_count) { | 695 | 197 | const auto& arg_column_data_2 = | 696 | 197 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); | 697 | 197 | if (const auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) { | 698 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 699 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 700 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 701 | 0 | return Status::InvalidArgument( | 702 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 703 | 0 | decimal_places); | 704 | 0 | } | 705 | 0 | const auto& value = decimalv2_column->get_element(i); | 706 | | // unified_frac_value has 3 digits | 707 | 0 | auto unified_frac_value = value.frac_value() / 1000000; | 708 | 0 | StringRef str = | 709 | 0 | FormatRound::do_format_round<Int128, | 710 | 0 | FormatRound::MAX_FORMAT_LEN_DEC128V2()>( | 711 | 0 | context, 3, value.int_value(), unified_frac_value, decimal_places); | 712 | |
| 713 | 0 | result_column->insert_data(str.data, str.size); | 714 | 0 | } | 715 | 197 | } else if (const auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) { | 716 | 0 | const UInt32 scale = decimal32_column->get_scale(); | 717 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 718 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 719 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 720 | 0 | return Status::InvalidArgument( | 721 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 722 | 0 | decimal_places); | 723 | 0 | } | 724 | 0 | const Int32& frac_part = decimal32_column->get_fractional_part(i); | 725 | 0 | const Int32& whole_part = decimal32_column->get_intergral_part(i); | 726 | 0 | StringRef str = | 727 | 0 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC32()>( | 728 | 0 | context, scale, static_cast<Int64>(whole_part), | 729 | 0 | static_cast<Int64>(frac_part), decimal_places); | 730 | |
| 731 | 0 | result_column->insert_data(str.data, str.size); | 732 | 0 | } | 733 | 197 | } else if (const auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) { | 734 | 0 | const UInt32 scale = decimal64_column->get_scale(); | 735 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 736 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 737 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 738 | 0 | return Status::InvalidArgument( | 739 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 740 | 0 | decimal_places); | 741 | 0 | } | 742 | 0 | const Int64& frac_part = decimal64_column->get_fractional_part(i); | 743 | 0 | const Int64& whole_part = decimal64_column->get_intergral_part(i); | 744 | |
| 745 | 0 | StringRef str = | 746 | 0 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC64()>( | 747 | 0 | context, scale, whole_part, frac_part, decimal_places); | 748 | |
| 749 | 0 | result_column->insert_data(str.data, str.size); | 750 | 0 | } | 751 | 197 | } else if (const auto* decimal128_column = | 752 | 197 | check_and_get_column<ColumnDecimal128V3>(*col_ptr)) { | 753 | 197 | const UInt32 scale = decimal128_column->get_scale(); | 754 | 492 | for (size_t i = 0; i < input_rows_count; i++) { | 755 | 295 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 756 | 295 | if (decimal_places < 0 || decimal_places > 1024) { | 757 | 0 | return Status::InvalidArgument( | 758 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 759 | 0 | decimal_places); | 760 | 0 | } | 761 | 295 | const Int128& frac_part = decimal128_column->get_fractional_part(i); | 762 | 295 | const Int128& whole_part = decimal128_column->get_intergral_part(i); | 763 | | | 764 | 295 | StringRef str = | 765 | 295 | FormatRound::do_format_round<Int128, | 766 | 295 | FormatRound::MAX_FORMAT_LEN_DEC128V3()>( | 767 | 295 | context, scale, whole_part, frac_part, decimal_places); | 768 | | | 769 | 295 | result_column->insert_data(str.data, str.size); | 770 | 295 | } | 771 | 197 | } else if (const auto* decimal256_column = | 772 | 0 | check_and_get_column<ColumnDecimal256>(*col_ptr)) { | 773 | 0 | const UInt32 scale = decimal256_column->get_scale(); | 774 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 775 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 776 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 777 | 0 | return Status::InvalidArgument( | 778 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 779 | 0 | decimal_places); | 780 | 0 | } | 781 | 0 | const auto frac_part = decimal256_column->get_fractional_part(i); | 782 | 0 | const auto whole_part = decimal256_column->get_intergral_part(i); | 783 | 0 | StringRef str = FormatRound::do_format_round<wide::Int256, | 784 | 0 | FormatRound::MAX_FORMAT_LEN_DEC256()>( | 785 | 0 | context, scale, whole_part, frac_part, decimal_places); | 786 | |
| 787 | 0 | result_column->insert_data(str.data, str.size); | 788 | 0 | } | 789 | 0 | } else { | 790 | 0 | return Status::InternalError("Not supported input argument type {}", | 791 | 0 | col_ptr->get_name()); | 792 | 0 | } | 793 | 197 | return Status::OK(); | 794 | 197 | } |
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EE7executeILb1EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m Line | Count | Source | 694 | 76 | ColumnPtr decimal_places_col_ptr, size_t input_rows_count) { | 695 | 76 | const auto& arg_column_data_2 = | 696 | 76 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); | 697 | 76 | if (const auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) { | 698 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 699 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 700 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 701 | 0 | return Status::InvalidArgument( | 702 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 703 | 0 | decimal_places); | 704 | 0 | } | 705 | 0 | const auto& value = decimalv2_column->get_element(i); | 706 | | // unified_frac_value has 3 digits | 707 | 0 | auto unified_frac_value = value.frac_value() / 1000000; | 708 | 0 | StringRef str = | 709 | 0 | FormatRound::do_format_round<Int128, | 710 | 0 | FormatRound::MAX_FORMAT_LEN_DEC128V2()>( | 711 | 0 | context, 3, value.int_value(), unified_frac_value, decimal_places); | 712 | |
| 713 | 0 | result_column->insert_data(str.data, str.size); | 714 | 0 | } | 715 | 76 | } else if (const auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) { | 716 | 0 | const UInt32 scale = decimal32_column->get_scale(); | 717 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 718 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 719 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 720 | 0 | return Status::InvalidArgument( | 721 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 722 | 0 | decimal_places); | 723 | 0 | } | 724 | 0 | const Int32& frac_part = decimal32_column->get_fractional_part(i); | 725 | 0 | const Int32& whole_part = decimal32_column->get_intergral_part(i); | 726 | 0 | StringRef str = | 727 | 0 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC32()>( | 728 | 0 | context, scale, static_cast<Int64>(whole_part), | 729 | 0 | static_cast<Int64>(frac_part), decimal_places); | 730 | |
| 731 | 0 | result_column->insert_data(str.data, str.size); | 732 | 0 | } | 733 | 76 | } else if (const auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) { | 734 | 0 | const UInt32 scale = decimal64_column->get_scale(); | 735 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 736 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 737 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 738 | 0 | return Status::InvalidArgument( | 739 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 740 | 0 | decimal_places); | 741 | 0 | } | 742 | 0 | const Int64& frac_part = decimal64_column->get_fractional_part(i); | 743 | 0 | const Int64& whole_part = decimal64_column->get_intergral_part(i); | 744 | |
| 745 | 0 | StringRef str = | 746 | 0 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC64()>( | 747 | 0 | context, scale, whole_part, frac_part, decimal_places); | 748 | |
| 749 | 0 | result_column->insert_data(str.data, str.size); | 750 | 0 | } | 751 | 76 | } else if (const auto* decimal128_column = | 752 | 76 | check_and_get_column<ColumnDecimal128V3>(*col_ptr)) { | 753 | 0 | const UInt32 scale = decimal128_column->get_scale(); | 754 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 755 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 756 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 757 | 0 | return Status::InvalidArgument( | 758 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 759 | 0 | decimal_places); | 760 | 0 | } | 761 | 0 | const Int128& frac_part = decimal128_column->get_fractional_part(i); | 762 | 0 | const Int128& whole_part = decimal128_column->get_intergral_part(i); | 763 | |
| 764 | 0 | StringRef str = | 765 | 0 | FormatRound::do_format_round<Int128, | 766 | 0 | FormatRound::MAX_FORMAT_LEN_DEC128V3()>( | 767 | 0 | context, scale, whole_part, frac_part, decimal_places); | 768 | |
| 769 | 0 | result_column->insert_data(str.data, str.size); | 770 | 0 | } | 771 | 76 | } else if (const auto* decimal256_column = | 772 | 76 | check_and_get_column<ColumnDecimal256>(*col_ptr)) { | 773 | 76 | const UInt32 scale = decimal256_column->get_scale(); | 774 | 152 | for (size_t i = 0; i < input_rows_count; i++) { | 775 | 76 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 776 | 76 | if (decimal_places < 0 || decimal_places > 1024) { | 777 | 0 | return Status::InvalidArgument( | 778 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 779 | 0 | decimal_places); | 780 | 0 | } | 781 | 76 | const auto frac_part = decimal256_column->get_fractional_part(i); | 782 | 76 | const auto whole_part = decimal256_column->get_intergral_part(i); | 783 | 76 | StringRef str = FormatRound::do_format_round<wide::Int256, | 784 | 76 | FormatRound::MAX_FORMAT_LEN_DEC256()>( | 785 | 76 | context, scale, whole_part, frac_part, decimal_places); | 786 | | | 787 | 76 | result_column->insert_data(str.data, str.size); | 788 | 76 | } | 789 | 76 | } else { | 790 | 0 | return Status::InternalError("Not supported input argument type {}", | 791 | 0 | col_ptr->get_name()); | 792 | 0 | } | 793 | 76 | return Status::OK(); | 794 | 76 | } |
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EE7executeILb0EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m Line | Count | Source | 694 | 156 | ColumnPtr decimal_places_col_ptr, size_t input_rows_count) { | 695 | 156 | const auto& arg_column_data_2 = | 696 | 156 | assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data(); | 697 | 156 | if (const auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) { | 698 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 699 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 700 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 701 | 0 | return Status::InvalidArgument( | 702 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 703 | 0 | decimal_places); | 704 | 0 | } | 705 | 0 | const auto& value = decimalv2_column->get_element(i); | 706 | | // unified_frac_value has 3 digits | 707 | 0 | auto unified_frac_value = value.frac_value() / 1000000; | 708 | 0 | StringRef str = | 709 | 0 | FormatRound::do_format_round<Int128, | 710 | 0 | FormatRound::MAX_FORMAT_LEN_DEC128V2()>( | 711 | 0 | context, 3, value.int_value(), unified_frac_value, decimal_places); | 712 | |
| 713 | 0 | result_column->insert_data(str.data, str.size); | 714 | 0 | } | 715 | 156 | } else if (const auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) { | 716 | 0 | const UInt32 scale = decimal32_column->get_scale(); | 717 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 718 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 719 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 720 | 0 | return Status::InvalidArgument( | 721 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 722 | 0 | decimal_places); | 723 | 0 | } | 724 | 0 | const Int32& frac_part = decimal32_column->get_fractional_part(i); | 725 | 0 | const Int32& whole_part = decimal32_column->get_intergral_part(i); | 726 | 0 | StringRef str = | 727 | 0 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC32()>( | 728 | 0 | context, scale, static_cast<Int64>(whole_part), | 729 | 0 | static_cast<Int64>(frac_part), decimal_places); | 730 | |
| 731 | 0 | result_column->insert_data(str.data, str.size); | 732 | 0 | } | 733 | 156 | } else if (const auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) { | 734 | 0 | const UInt32 scale = decimal64_column->get_scale(); | 735 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 736 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 737 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 738 | 0 | return Status::InvalidArgument( | 739 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 740 | 0 | decimal_places); | 741 | 0 | } | 742 | 0 | const Int64& frac_part = decimal64_column->get_fractional_part(i); | 743 | 0 | const Int64& whole_part = decimal64_column->get_intergral_part(i); | 744 | |
| 745 | 0 | StringRef str = | 746 | 0 | FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC64()>( | 747 | 0 | context, scale, whole_part, frac_part, decimal_places); | 748 | |
| 749 | 0 | result_column->insert_data(str.data, str.size); | 750 | 0 | } | 751 | 156 | } else if (const auto* decimal128_column = | 752 | 156 | check_and_get_column<ColumnDecimal128V3>(*col_ptr)) { | 753 | 0 | const UInt32 scale = decimal128_column->get_scale(); | 754 | 0 | for (size_t i = 0; i < input_rows_count; i++) { | 755 | 0 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 756 | 0 | if (decimal_places < 0 || decimal_places > 1024) { | 757 | 0 | return Status::InvalidArgument( | 758 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 759 | 0 | decimal_places); | 760 | 0 | } | 761 | 0 | const Int128& frac_part = decimal128_column->get_fractional_part(i); | 762 | 0 | const Int128& whole_part = decimal128_column->get_intergral_part(i); | 763 | |
| 764 | 0 | StringRef str = | 765 | 0 | FormatRound::do_format_round<Int128, | 766 | 0 | FormatRound::MAX_FORMAT_LEN_DEC128V3()>( | 767 | 0 | context, scale, whole_part, frac_part, decimal_places); | 768 | |
| 769 | 0 | result_column->insert_data(str.data, str.size); | 770 | 0 | } | 771 | 156 | } else if (const auto* decimal256_column = | 772 | 156 | check_and_get_column<ColumnDecimal256>(*col_ptr)) { | 773 | 156 | const UInt32 scale = decimal256_column->get_scale(); | 774 | 386 | for (size_t i = 0; i < input_rows_count; i++) { | 775 | 230 | int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)]; | 776 | 230 | if (decimal_places < 0 || decimal_places > 1024) { | 777 | 0 | return Status::InvalidArgument( | 778 | 0 | "The second argument is {}, it should be in range [0, 1024].", | 779 | 0 | decimal_places); | 780 | 0 | } | 781 | 230 | const auto frac_part = decimal256_column->get_fractional_part(i); | 782 | 230 | const auto whole_part = decimal256_column->get_intergral_part(i); | 783 | 230 | StringRef str = FormatRound::do_format_round<wide::Int256, | 784 | 230 | FormatRound::MAX_FORMAT_LEN_DEC256()>( | 785 | 230 | context, scale, whole_part, frac_part, decimal_places); | 786 | | | 787 | 230 | result_column->insert_data(str.data, str.size); | 788 | 230 | } | 789 | 156 | } else { | 790 | 0 | return Status::InternalError("Not supported input argument type {}", | 791 | 0 | col_ptr->get_name()); | 792 | 0 | } | 793 | 156 | return Status::OK(); | 794 | 156 | } |
|
795 | | }; |
796 | | |
797 | | #include "common/compile_check_avoid_end.h" |
798 | | } // namespace doris |