Coverage Report

Created: 2026-09-28 17:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
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
2.35k
char* SimpleItoaWithCommas(T i, char* buffer, int32_t buffer_size) {
67
2.35k
    char* p = buffer + buffer_size;
68
    // Need to use unsigned T instead of T to correctly handle
69
2.35k
    MakeUnsignedT<T> n = i;
70
2.35k
    if (i < 0) {
71
536
        n = 0 - n;
72
536
    }
73
2.35k
    *--p = '0' + n % 10; // this case deals with the number "0"
74
2.35k
    n /= 10;
75
3.37k
    while (n) {
76
1.14k
        *--p = '0' + n % 10;
77
1.14k
        n /= 10;
78
1.14k
        if (n == 0) {
79
74
            break;
80
74
        }
81
82
1.06k
        *--p = '0' + n % 10;
83
1.06k
        n /= 10;
84
1.06k
        if (n == 0) {
85
48
            break;
86
48
        }
87
88
1.02k
        *--p = ',';
89
1.02k
        *--p = '0' + n % 10;
90
1.02k
        n /= 10;
91
        // For this unrolling, we check if n == 0 in the main while loop
92
1.02k
    }
93
2.35k
    if (i < 0) {
94
536
        *--p = '-';
95
536
    }
96
2.35k
    return p;
97
2.35k
}
_ZN5doris20SimpleItoaWithCommasInEEPcT_S1_i
Line
Count
Source
66
854
char* SimpleItoaWithCommas(T i, char* buffer, int32_t buffer_size) {
67
854
    char* p = buffer + buffer_size;
68
    // Need to use unsigned T instead of T to correctly handle
69
854
    MakeUnsignedT<T> n = i;
70
854
    if (i < 0) {
71
172
        n = 0 - n;
72
172
    }
73
854
    *--p = '0' + n % 10; // this case deals with the number "0"
74
854
    n /= 10;
75
952
    while (n) {
76
136
        *--p = '0' + n % 10;
77
136
        n /= 10;
78
136
        if (n == 0) {
79
16
            break;
80
16
        }
81
82
120
        *--p = '0' + n % 10;
83
120
        n /= 10;
84
120
        if (n == 0) {
85
22
            break;
86
22
        }
87
88
98
        *--p = ',';
89
98
        *--p = '0' + n % 10;
90
98
        n /= 10;
91
        // For this unrolling, we check if n == 0 in the main while loop
92
98
    }
93
854
    if (i < 0) {
94
172
        *--p = '-';
95
172
    }
96
854
    return p;
97
854
}
_ZN5doris20SimpleItoaWithCommasIlEEPcT_S1_i
Line
Count
Source
66
886
char* SimpleItoaWithCommas(T i, char* buffer, int32_t buffer_size) {
67
886
    char* p = buffer + buffer_size;
68
    // Need to use unsigned T instead of T to correctly handle
69
886
    MakeUnsignedT<T> n = i;
70
886
    if (i < 0) {
71
212
        n = 0 - n;
72
212
    }
73
886
    *--p = '0' + n % 10; // this case deals with the number "0"
74
886
    n /= 10;
75
1.02k
    while (n) {
76
206
        *--p = '0' + n % 10;
77
206
        n /= 10;
78
206
        if (n == 0) {
79
58
            break;
80
58
        }
81
82
148
        *--p = '0' + n % 10;
83
148
        n /= 10;
84
148
        if (n == 0) {
85
10
            break;
86
10
        }
87
88
138
        *--p = ',';
89
138
        *--p = '0' + n % 10;
90
138
        n /= 10;
91
        // For this unrolling, we check if n == 0 in the main while loop
92
138
    }
93
886
    if (i < 0) {
94
212
        *--p = '-';
95
212
    }
96
886
    return p;
97
886
}
_ZN5doris20SimpleItoaWithCommasIN4wide7integerILm256EiEEEEPcT_S4_i
Line
Count
Source
66
612
char* SimpleItoaWithCommas(T i, char* buffer, int32_t buffer_size) {
67
612
    char* p = buffer + buffer_size;
68
    // Need to use unsigned T instead of T to correctly handle
69
612
    MakeUnsignedT<T> n = i;
70
612
    if (i < 0) {
71
152
        n = 0 - n;
72
152
    }
73
612
    *--p = '0' + n % 10; // this case deals with the number "0"
74
612
    n /= 10;
75
1.39k
    while (n) {
76
800
        *--p = '0' + n % 10;
77
800
        n /= 10;
78
800
        if (n == 0) {
79
0
            break;
80
0
        }
81
82
800
        *--p = '0' + n % 10;
83
800
        n /= 10;
84
800
        if (n == 0) {
85
16
            break;
86
16
        }
87
88
784
        *--p = ',';
89
784
        *--p = '0' + n % 10;
90
784
        n /= 10;
91
        // For this unrolling, we check if n == 0 in the main while loop
92
784
    }
93
612
    if (i < 0) {
94
152
        *--p = '-';
95
152
    }
96
612
    return p;
97
612
}
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
62
StringRef do_money_format(FunctionContext* context, UInt32 scale, T int_value, T frac_value) {
138
62
    static_assert(std::is_integral<T>::value);
139
62
    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
62
    if (scale > 2) {
144
50
        DCHECK(scale <= 38);
145
        // do rounding, so we need to reserve 3 digits.
146
50
        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
50
        frac_value = std::abs(static_cast<int>(frac_value / multiplier)) + 5;
150
50
        frac_value /= 10;
151
50
    } else if (scale < 2) {
152
12
        DCHECK(frac_value < 100);
153
        // since scale <= 2, overflow is impossiable
154
12
        frac_value = frac_value * common::exp10_i32(2 - scale);
155
12
    }
156
157
62
    if (frac_value == 100) {
158
6
        if (is_negative) {
159
4
            int_value -= 1;
160
4
        } else {
161
2
            int_value += 1;
162
2
        }
163
6
        frac_value = 0;
164
6
    }
165
166
62
    bool append_sign_manually = false;
167
62
    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
4
        append_sign_manually = true;
172
4
    }
173
174
62
    char local[N];
175
62
    char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local));
176
62
    const Int32 integer_str_len = N - (p - local);
177
62
    const Int32 frac_str_len = 2;
178
62
    const Int32 whole_decimal_str_len =
179
62
            (append_sign_manually ? 1 : 0) + integer_str_len + 1 + frac_str_len;
180
181
62
    StringRef result = context->create_temp_string_val(whole_decimal_str_len);
182
    // Modify a string passed via stringref
183
62
    char* result_data = const_cast<char*>(result.data);
184
185
62
    if (append_sign_manually) {
186
4
        memset(result_data, '-', 1);
187
4
    }
188
189
62
    memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len);
190
62
    *(result_data + whole_decimal_str_len - 3) = '.';
191
62
    *(result_data + whole_decimal_str_len - 2) = '0' + std::abs(static_cast<int>(frac_value / 10));
192
62
    *(result_data + whole_decimal_str_len - 1) = '0' + std::abs(static_cast<int>(frac_value % 10));
193
62
    return result;
194
62
};
_ZN5doris11MoneyFormat15do_money_formatInLm80EEENS_9StringRefEPNS_15FunctionContextEjT_S5_
Line
Count
Source
137
28
StringRef do_money_format(FunctionContext* context, UInt32 scale, T int_value, T frac_value) {
138
28
    static_assert(std::is_integral<T>::value);
139
28
    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
28
    if (scale > 2) {
144
28
        DCHECK(scale <= 38);
145
        // do rounding, so we need to reserve 3 digits.
146
28
        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
28
        frac_value = std::abs(static_cast<int>(frac_value / multiplier)) + 5;
150
28
        frac_value /= 10;
151
28
    } 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
28
    if (frac_value == 100) {
158
6
        if (is_negative) {
159
4
            int_value -= 1;
160
4
        } else {
161
2
            int_value += 1;
162
2
        }
163
6
        frac_value = 0;
164
6
    }
165
166
28
    bool append_sign_manually = false;
167
28
    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
4
        append_sign_manually = true;
172
4
    }
173
174
28
    char local[N];
175
28
    char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local));
176
28
    const Int32 integer_str_len = N - (p - local);
177
28
    const Int32 frac_str_len = 2;
178
28
    const Int32 whole_decimal_str_len =
179
28
            (append_sign_manually ? 1 : 0) + integer_str_len + 1 + frac_str_len;
180
181
28
    StringRef result = context->create_temp_string_val(whole_decimal_str_len);
182
    // Modify a string passed via stringref
183
28
    char* result_data = const_cast<char*>(result.data);
184
185
28
    if (append_sign_manually) {
186
4
        memset(result_data, '-', 1);
187
4
    }
188
189
28
    memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len);
190
28
    *(result_data + whole_decimal_str_len - 3) = '.';
191
28
    *(result_data + whole_decimal_str_len - 2) = '0' + std::abs(static_cast<int>(frac_value / 10));
192
28
    *(result_data + whole_decimal_str_len - 1) = '0' + std::abs(static_cast<int>(frac_value % 10));
193
28
    return result;
194
28
};
_ZN5doris11MoneyFormat15do_money_formatIlLm32EEENS_9StringRefEPNS_15FunctionContextEjT_S5_
Line
Count
Source
137
4
StringRef do_money_format(FunctionContext* context, UInt32 scale, T int_value, T frac_value) {
138
4
    static_assert(std::is_integral<T>::value);
139
4
    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
4
    if (scale > 2) {
144
4
        DCHECK(scale <= 38);
145
        // do rounding, so we need to reserve 3 digits.
146
4
        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
4
        frac_value = std::abs(static_cast<int>(frac_value / multiplier)) + 5;
150
4
        frac_value /= 10;
151
4
    } 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
4
    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
4
    bool append_sign_manually = false;
167
4
    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
4
    char local[N];
175
4
    char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local));
176
4
    const Int32 integer_str_len = N - (p - local);
177
4
    const Int32 frac_str_len = 2;
178
4
    const Int32 whole_decimal_str_len =
179
4
            (append_sign_manually ? 1 : 0) + integer_str_len + 1 + frac_str_len;
180
181
4
    StringRef result = context->create_temp_string_val(whole_decimal_str_len);
182
    // Modify a string passed via stringref
183
4
    char* result_data = const_cast<char*>(result.data);
184
185
4
    if (append_sign_manually) {
186
0
        memset(result_data, '-', 1);
187
0
    }
188
189
4
    memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len);
190
4
    *(result_data + whole_decimal_str_len - 3) = '.';
191
4
    *(result_data + whole_decimal_str_len - 2) = '0' + std::abs(static_cast<int>(frac_value / 10));
192
4
    *(result_data + whole_decimal_str_len - 1) = '0' + std::abs(static_cast<int>(frac_value % 10));
193
4
    return result;
194
4
};
_ZN5doris11MoneyFormat15do_money_formatIlLm56EEENS_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
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
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
0
        append_sign_manually = true;
172
0
    }
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
0
        memset(result_data, '-', 1);
187
0
    }
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_formatInLm112EEENS_9StringRefEPNS_15FunctionContextEjT_S5_
Line
Count
Source
137
10
StringRef do_money_format(FunctionContext* context, UInt32 scale, T int_value, T frac_value) {
138
10
    static_assert(std::is_integral<T>::value);
139
10
    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
10
    if (scale > 2) {
144
4
        DCHECK(scale <= 38);
145
        // do rounding, so we need to reserve 3 digits.
146
4
        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
4
        frac_value = std::abs(static_cast<int>(frac_value / multiplier)) + 5;
150
4
        frac_value /= 10;
151
6
    } 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
10
    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
10
    bool append_sign_manually = false;
167
10
    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
10
    char local[N];
175
10
    char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local));
176
10
    const Int32 integer_str_len = N - (p - local);
177
10
    const Int32 frac_str_len = 2;
178
10
    const Int32 whole_decimal_str_len =
179
10
            (append_sign_manually ? 1 : 0) + integer_str_len + 1 + frac_str_len;
180
181
10
    StringRef result = context->create_temp_string_val(whole_decimal_str_len);
182
    // Modify a string passed via stringref
183
10
    char* result_data = const_cast<char*>(result.data);
184
185
10
    if (append_sign_manually) {
186
0
        memset(result_data, '-', 1);
187
0
    }
188
189
10
    memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len);
190
10
    *(result_data + whole_decimal_str_len - 3) = '.';
191
10
    *(result_data + whole_decimal_str_len - 2) = '0' + std::abs(static_cast<int>(frac_value / 10));
192
10
    *(result_data + whole_decimal_str_len - 1) = '0' + std::abs(static_cast<int>(frac_value % 10));
193
10
    return result;
194
10
};
_ZN5doris11MoneyFormat15do_money_formatIlLm60EEENS_9StringRefEPNS_15FunctionContextEjT_S5_
Line
Count
Source
137
6
StringRef do_money_format(FunctionContext* context, UInt32 scale, T int_value, T frac_value) {
138
6
    static_assert(std::is_integral<T>::value);
139
6
    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
6
    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
6
    } 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
6
    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
6
    bool append_sign_manually = false;
167
6
    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
6
    char local[N];
175
6
    char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local));
176
6
    const Int32 integer_str_len = N - (p - local);
177
6
    const Int32 frac_str_len = 2;
178
6
    const Int32 whole_decimal_str_len =
179
6
            (append_sign_manually ? 1 : 0) + integer_str_len + 1 + frac_str_len;
180
181
6
    StringRef result = context->create_temp_string_val(whole_decimal_str_len);
182
    // Modify a string passed via stringref
183
6
    char* result_data = const_cast<char*>(result.data);
184
185
6
    if (append_sign_manually) {
186
0
        memset(result_data, '-', 1);
187
0
    }
188
189
6
    memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len);
190
6
    *(result_data + whole_decimal_str_len - 3) = '.';
191
6
    *(result_data + whole_decimal_str_len - 2) = '0' + std::abs(static_cast<int>(frac_value / 10));
192
6
    *(result_data + whole_decimal_str_len - 1) = '0' + std::abs(static_cast<int>(frac_value % 10));
193
6
    return result;
194
6
};
195
196
// Note string value must be valid decimal string which contains two digits after the decimal point
197
8
static StringRef do_money_format(FunctionContext* context, const std::string& value) {
198
8
    bool is_positive = (value[0] != '-');
199
8
    int32_t result_len = value.size() + (value.size() - (is_positive ? 4 : 5)) / 3;
200
8
    StringRef result = context->create_temp_string_val(result_len);
201
    // Modify a string passed via stringref
202
8
    char* result_data = const_cast<char*>(result.data);
203
8
    if (!is_positive) {
204
4
        *result_data = '-';
205
4
    }
206
20
    for (int i = value.size() - 4, j = result_len - 4; i >= 0; i = i - 3) {
207
18
        *(result_data + j) = *(value.data() + i);
208
18
        if (i - 1 < 0) {
209
4
            break;
210
4
        }
211
14
        *(result_data + j - 1) = *(value.data() + i - 1);
212
14
        if (i - 2 < 0) {
213
2
            break;
214
2
        }
215
12
        *(result_data + j - 2) = *(value.data() + i - 2);
216
12
        if (j - 3 > 1 || (j - 3 == 1 && is_positive)) {
217
8
            *(result_data + j - 3) = ',';
218
8
            j -= 4;
219
8
        } else {
220
4
            j -= 3;
221
4
        }
222
12
    }
223
8
    memcpy(result_data + result_len - 3, value.data() + value.size() - 3, 3);
224
8
    return result;
225
8
};
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
8
static StringRef do_money_format(FunctionContext* context, const std::string& value) {
198
8
    bool is_positive = (value[0] != '-');
199
8
    int32_t result_len = value.size() + (value.size() - (is_positive ? 4 : 5)) / 3;
200
8
    StringRef result = context->create_temp_string_val(result_len);
201
    // Modify a string passed via stringref
202
8
    char* result_data = const_cast<char*>(result.data);
203
8
    if (!is_positive) {
204
4
        *result_data = '-';
205
4
    }
206
20
    for (int i = value.size() - 4, j = result_len - 4; i >= 0; i = i - 3) {
207
18
        *(result_data + j) = *(value.data() + i);
208
18
        if (i - 1 < 0) {
209
4
            break;
210
4
        }
211
14
        *(result_data + j - 1) = *(value.data() + i - 1);
212
14
        if (i - 2 < 0) {
213
2
            break;
214
2
        }
215
12
        *(result_data + j - 2) = *(value.data() + i - 2);
216
12
        if (j - 3 > 1 || (j - 3 == 1 && is_positive)) {
217
8
            *(result_data + j - 3) = ',';
218
8
            j -= 4;
219
8
        } else {
220
4
            j -= 3;
221
4
        }
222
12
    }
223
8
    memcpy(result_data + result_len - 3, value.data() + value.size() - 3, 3);
224
8
    return result;
225
8
};
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
2.29k
                          Int32 decimal_places) {
275
2.29k
    static_assert(IsIntegralV<T>);
276
2.29k
    const bool is_negative = int_value < 0 || frac_value < 0;
277
2.29k
    frac_value = frac_value < 0 ? -frac_value : frac_value;
278
279
    // do round to frac_part based on decimal_places
280
2.29k
    if (static_cast<Int32>(scale) > decimal_places) {
281
310
        DCHECK(scale <= std::numeric_limits<T>::digits10);
282
        // do rounding, so we need to reserve decimal_places + 1 digits
283
310
        auto multiplier = decimal_scale_multiplier<T>(scale - (decimal_places + 1));
284
        // do divide first to avoid overflow
285
310
        frac_value = (frac_value / multiplier + 5) / 10;
286
310
        scale = decimal_places;
287
288
310
        if (frac_value == decimal_scale_multiplier<T>(scale)) {
289
192
            if (is_negative) {
290
96
                int_value -= 1;
291
96
            } else {
292
96
                int_value += 1;
293
96
            }
294
192
            frac_value = 0;
295
192
        }
296
310
    }
297
298
2.29k
    bool append_sign_manually = false;
299
2.29k
    if (is_negative && int_value == 0) {
300
424
        append_sign_manually = true;
301
424
    }
302
303
2.29k
    char local[N];
304
2.29k
    char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local));
305
2.29k
    const Int32 integer_str_len = N - (p - local);
306
2.29k
    const Int32 frac_str_len = decimal_places;
307
2.29k
    const Int32 whole_decimal_str_len = (append_sign_manually ? 1 : 0) + integer_str_len +
308
2.29k
                                        (decimal_places > 0 ? 1 : 0) + frac_str_len;
309
310
2.29k
    StringRef result = context->create_temp_string_val(whole_decimal_str_len);
311
    // Modify a string passed via stringref
312
2.29k
    char* result_data = const_cast<char*>(result.data);
313
314
2.29k
    if (append_sign_manually) {
315
424
        memset(result_data, '-', 1);
316
424
    }
317
318
2.29k
    memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len);
319
2.29k
    if (decimal_places > 0) {
320
2.20k
        *(result_data + whole_decimal_str_len - (frac_str_len + 1)) = '.';
321
2.20k
    }
322
323
    // Pad on the right without scaling the value: decimal_places can be as large as 1024.
324
2.29k
    const Int32 trailing_zeros = decimal_places - scale;
325
2.29k
    char* frac_end = result_data + whole_decimal_str_len - trailing_zeros;
326
2.29k
    memset(frac_end, '0', trailing_zeros);
327
19.3k
    for (UInt32 i = 0; i < scale; ++i) {
328
17.0k
        *--frac_end = '0' + (frac_value % 10);
329
17.0k
        frac_value /= 10;
330
17.0k
    }
331
2.29k
    return result;
332
2.29k
}
_ZN5doris11FormatRound15do_format_roundIlLm60EEENS_9StringRefEPNS_15FunctionContextEjT_S5_i
Line
Count
Source
274
32
                          Int32 decimal_places) {
275
32
    static_assert(IsIntegralV<T>);
276
32
    const bool is_negative = int_value < 0 || frac_value < 0;
277
32
    frac_value = frac_value < 0 ? -frac_value : frac_value;
278
279
    // do round to frac_part based on decimal_places
280
32
    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
32
    bool append_sign_manually = false;
299
32
    if (is_negative && int_value == 0) {
300
0
        append_sign_manually = true;
301
0
    }
302
303
32
    char local[N];
304
32
    char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local));
305
32
    const Int32 integer_str_len = N - (p - local);
306
32
    const Int32 frac_str_len = decimal_places;
307
32
    const Int32 whole_decimal_str_len = (append_sign_manually ? 1 : 0) + integer_str_len +
308
32
                                        (decimal_places > 0 ? 1 : 0) + frac_str_len;
309
310
32
    StringRef result = context->create_temp_string_val(whole_decimal_str_len);
311
    // Modify a string passed via stringref
312
32
    char* result_data = const_cast<char*>(result.data);
313
314
32
    if (append_sign_manually) {
315
0
        memset(result_data, '-', 1);
316
0
    }
317
318
32
    memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len);
319
32
    if (decimal_places > 0) {
320
20
        *(result_data + whole_decimal_str_len - (frac_str_len + 1)) = '.';
321
20
    }
322
323
    // Pad on the right without scaling the value: decimal_places can be as large as 1024.
324
32
    const Int32 trailing_zeros = decimal_places - scale;
325
32
    char* frac_end = result_data + whole_decimal_str_len - trailing_zeros;
326
32
    memset(frac_end, '0', trailing_zeros);
327
32
    for (UInt32 i = 0; i < scale; ++i) {
328
0
        *--frac_end = '0' + (frac_value % 10);
329
0
        frac_value /= 10;
330
0
    }
331
32
    return result;
332
32
}
_ZN5doris11FormatRound15do_format_roundInLm112EEENS_9StringRefEPNS_15FunctionContextEjT_S5_i
Line
Count
Source
274
810
                          Int32 decimal_places) {
275
810
    static_assert(IsIntegralV<T>);
276
810
    const bool is_negative = int_value < 0 || frac_value < 0;
277
810
    frac_value = frac_value < 0 ? -frac_value : frac_value;
278
279
    // do round to frac_part based on decimal_places
280
810
    if (static_cast<Int32>(scale) > decimal_places) {
281
36
        DCHECK(scale <= std::numeric_limits<T>::digits10);
282
        // do rounding, so we need to reserve decimal_places + 1 digits
283
36
        auto multiplier = decimal_scale_multiplier<T>(scale - (decimal_places + 1));
284
        // do divide first to avoid overflow
285
36
        frac_value = (frac_value / multiplier + 5) / 10;
286
36
        scale = decimal_places;
287
288
36
        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
36
    }
297
298
810
    bool append_sign_manually = false;
299
810
    if (is_negative && int_value == 0) {
300
160
        append_sign_manually = true;
301
160
    }
302
303
810
    char local[N];
304
810
    char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local));
305
810
    const Int32 integer_str_len = N - (p - local);
306
810
    const Int32 frac_str_len = decimal_places;
307
810
    const Int32 whole_decimal_str_len = (append_sign_manually ? 1 : 0) + integer_str_len +
308
810
                                        (decimal_places > 0 ? 1 : 0) + frac_str_len;
309
310
810
    StringRef result = context->create_temp_string_val(whole_decimal_str_len);
311
    // Modify a string passed via stringref
312
810
    char* result_data = const_cast<char*>(result.data);
313
314
810
    if (append_sign_manually) {
315
160
        memset(result_data, '-', 1);
316
160
    }
317
318
810
    memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len);
319
810
    if (decimal_places > 0) {
320
802
        *(result_data + whole_decimal_str_len - (frac_str_len + 1)) = '.';
321
802
    }
322
323
    // Pad on the right without scaling the value: decimal_places can be as large as 1024.
324
810
    const Int32 trailing_zeros = decimal_places - scale;
325
810
    char* frac_end = result_data + whole_decimal_str_len - trailing_zeros;
326
810
    memset(frac_end, '0', trailing_zeros);
327
4.21k
    for (UInt32 i = 0; i < scale; ++i) {
328
3.40k
        *--frac_end = '0' + (frac_value % 10);
329
3.40k
        frac_value /= 10;
330
3.40k
    }
331
810
    return result;
332
810
}
_ZN5doris11FormatRound15do_format_roundInLm80EEENS_9StringRefEPNS_15FunctionContextEjT_S5_i
Line
Count
Source
274
6
                          Int32 decimal_places) {
275
6
    static_assert(IsIntegralV<T>);
276
6
    const bool is_negative = int_value < 0 || frac_value < 0;
277
6
    frac_value = frac_value < 0 ? -frac_value : frac_value;
278
279
    // do round to frac_part based on decimal_places
280
6
    if (static_cast<Int32>(scale) > decimal_places) {
281
6
        DCHECK(scale <= std::numeric_limits<T>::digits10);
282
        // do rounding, so we need to reserve decimal_places + 1 digits
283
6
        auto multiplier = decimal_scale_multiplier<T>(scale - (decimal_places + 1));
284
        // do divide first to avoid overflow
285
6
        frac_value = (frac_value / multiplier + 5) / 10;
286
6
        scale = decimal_places;
287
288
6
        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
6
    }
297
298
6
    bool append_sign_manually = false;
299
6
    if (is_negative && int_value == 0) {
300
0
        append_sign_manually = true;
301
0
    }
302
303
6
    char local[N];
304
6
    char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local));
305
6
    const Int32 integer_str_len = N - (p - local);
306
6
    const Int32 frac_str_len = decimal_places;
307
6
    const Int32 whole_decimal_str_len = (append_sign_manually ? 1 : 0) + integer_str_len +
308
6
                                        (decimal_places > 0 ? 1 : 0) + frac_str_len;
309
310
6
    StringRef result = context->create_temp_string_val(whole_decimal_str_len);
311
    // Modify a string passed via stringref
312
6
    char* result_data = const_cast<char*>(result.data);
313
314
6
    if (append_sign_manually) {
315
0
        memset(result_data, '-', 1);
316
0
    }
317
318
6
    memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len);
319
6
    if (decimal_places > 0) {
320
6
        *(result_data + whole_decimal_str_len - (frac_str_len + 1)) = '.';
321
6
    }
322
323
    // Pad on the right without scaling the value: decimal_places can be as large as 1024.
324
6
    const Int32 trailing_zeros = decimal_places - scale;
325
6
    char* frac_end = result_data + whole_decimal_str_len - trailing_zeros;
326
6
    memset(frac_end, '0', trailing_zeros);
327
18
    for (UInt32 i = 0; i < scale; ++i) {
328
12
        *--frac_end = '0' + (frac_value % 10);
329
12
        frac_value /= 10;
330
12
    }
331
6
    return result;
332
6
}
_ZN5doris11FormatRound15do_format_roundIlLm32EEENS_9StringRefEPNS_15FunctionContextEjT_S5_i
Line
Count
Source
274
364
                          Int32 decimal_places) {
275
364
    static_assert(IsIntegralV<T>);
276
364
    const bool is_negative = int_value < 0 || frac_value < 0;
277
364
    frac_value = frac_value < 0 ? -frac_value : frac_value;
278
279
    // do round to frac_part based on decimal_places
280
364
    if (static_cast<Int32>(scale) > decimal_places) {
281
2
        DCHECK(scale <= std::numeric_limits<T>::digits10);
282
        // do rounding, so we need to reserve decimal_places + 1 digits
283
2
        auto multiplier = decimal_scale_multiplier<T>(scale - (decimal_places + 1));
284
        // do divide first to avoid overflow
285
2
        frac_value = (frac_value / multiplier + 5) / 10;
286
2
        scale = decimal_places;
287
288
2
        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
2
    }
297
298
364
    bool append_sign_manually = false;
299
364
    if (is_negative && int_value == 0) {
300
72
        append_sign_manually = true;
301
72
    }
302
303
364
    char local[N];
304
364
    char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local));
305
364
    const Int32 integer_str_len = N - (p - local);
306
364
    const Int32 frac_str_len = decimal_places;
307
364
    const Int32 whole_decimal_str_len = (append_sign_manually ? 1 : 0) + integer_str_len +
308
364
                                        (decimal_places > 0 ? 1 : 0) + frac_str_len;
309
310
364
    StringRef result = context->create_temp_string_val(whole_decimal_str_len);
311
    // Modify a string passed via stringref
312
364
    char* result_data = const_cast<char*>(result.data);
313
314
364
    if (append_sign_manually) {
315
72
        memset(result_data, '-', 1);
316
72
    }
317
318
364
    memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len);
319
364
    if (decimal_places > 0) {
320
362
        *(result_data + whole_decimal_str_len - (frac_str_len + 1)) = '.';
321
362
    }
322
323
    // Pad on the right without scaling the value: decimal_places can be as large as 1024.
324
364
    const Int32 trailing_zeros = decimal_places - scale;
325
364
    char* frac_end = result_data + whole_decimal_str_len - trailing_zeros;
326
364
    memset(frac_end, '0', trailing_zeros);
327
1.08k
    for (UInt32 i = 0; i < scale; ++i) {
328
724
        *--frac_end = '0' + (frac_value % 10);
329
724
        frac_value /= 10;
330
724
    }
331
364
    return result;
332
364
}
_ZN5doris11FormatRound15do_format_roundIlLm56EEENS_9StringRefEPNS_15FunctionContextEjT_S5_i
Line
Count
Source
274
466
                          Int32 decimal_places) {
275
466
    static_assert(IsIntegralV<T>);
276
466
    const bool is_negative = int_value < 0 || frac_value < 0;
277
466
    frac_value = frac_value < 0 ? -frac_value : frac_value;
278
279
    // do round to frac_part based on decimal_places
280
466
    if (static_cast<Int32>(scale) > decimal_places) {
281
96
        DCHECK(scale <= std::numeric_limits<T>::digits10);
282
        // do rounding, so we need to reserve decimal_places + 1 digits
283
96
        auto multiplier = decimal_scale_multiplier<T>(scale - (decimal_places + 1));
284
        // do divide first to avoid overflow
285
96
        frac_value = (frac_value / multiplier + 5) / 10;
286
96
        scale = decimal_places;
287
288
96
        if (frac_value == decimal_scale_multiplier<T>(scale)) {
289
32
            if (is_negative) {
290
16
                int_value -= 1;
291
16
            } else {
292
16
                int_value += 1;
293
16
            }
294
32
            frac_value = 0;
295
32
        }
296
96
    }
297
298
466
    bool append_sign_manually = false;
299
466
    if (is_negative && int_value == 0) {
300
80
        append_sign_manually = true;
301
80
    }
302
303
466
    char local[N];
304
466
    char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local));
305
466
    const Int32 integer_str_len = N - (p - local);
306
466
    const Int32 frac_str_len = decimal_places;
307
466
    const Int32 whole_decimal_str_len = (append_sign_manually ? 1 : 0) + integer_str_len +
308
466
                                        (decimal_places > 0 ? 1 : 0) + frac_str_len;
309
310
466
    StringRef result = context->create_temp_string_val(whole_decimal_str_len);
311
    // Modify a string passed via stringref
312
466
    char* result_data = const_cast<char*>(result.data);
313
314
466
    if (append_sign_manually) {
315
80
        memset(result_data, '-', 1);
316
80
    }
317
318
466
    memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len);
319
466
    if (decimal_places > 0) {
320
440
        *(result_data + whole_decimal_str_len - (frac_str_len + 1)) = '.';
321
440
    }
322
323
    // Pad on the right without scaling the value: decimal_places can be as large as 1024.
324
466
    const Int32 trailing_zeros = decimal_places - scale;
325
466
    char* frac_end = result_data + whole_decimal_str_len - trailing_zeros;
326
466
    memset(frac_end, '0', trailing_zeros);
327
1.81k
    for (UInt32 i = 0; i < scale; ++i) {
328
1.35k
        *--frac_end = '0' + (frac_value % 10);
329
1.35k
        frac_value /= 10;
330
1.35k
    }
331
466
    return result;
332
466
}
_ZN5doris11FormatRound15do_format_roundIN4wide7integerILm256EiEELm210EEENS_9StringRefEPNS_15FunctionContextEjT_S8_i
Line
Count
Source
274
612
                          Int32 decimal_places) {
275
612
    static_assert(IsIntegralV<T>);
276
612
    const bool is_negative = int_value < 0 || frac_value < 0;
277
612
    frac_value = frac_value < 0 ? -frac_value : frac_value;
278
279
    // do round to frac_part based on decimal_places
280
612
    if (static_cast<Int32>(scale) > decimal_places) {
281
170
        DCHECK(scale <= std::numeric_limits<T>::digits10);
282
        // do rounding, so we need to reserve decimal_places + 1 digits
283
170
        auto multiplier = decimal_scale_multiplier<T>(scale - (decimal_places + 1));
284
        // do divide first to avoid overflow
285
170
        frac_value = (frac_value / multiplier + 5) / 10;
286
170
        scale = decimal_places;
287
288
170
        if (frac_value == decimal_scale_multiplier<T>(scale)) {
289
144
            if (is_negative) {
290
72
                int_value -= 1;
291
72
            } else {
292
72
                int_value += 1;
293
72
            }
294
144
            frac_value = 0;
295
144
        }
296
170
    }
297
298
612
    bool append_sign_manually = false;
299
612
    if (is_negative && int_value == 0) {
300
112
        append_sign_manually = true;
301
112
    }
302
303
612
    char local[N];
304
612
    char* p = SimpleItoaWithCommas<T>(int_value, local, sizeof(local));
305
612
    const Int32 integer_str_len = N - (p - local);
306
612
    const Int32 frac_str_len = decimal_places;
307
612
    const Int32 whole_decimal_str_len = (append_sign_manually ? 1 : 0) + integer_str_len +
308
612
                                        (decimal_places > 0 ? 1 : 0) + frac_str_len;
309
310
612
    StringRef result = context->create_temp_string_val(whole_decimal_str_len);
311
    // Modify a string passed via stringref
312
612
    char* result_data = const_cast<char*>(result.data);
313
314
612
    if (append_sign_manually) {
315
112
        memset(result_data, '-', 1);
316
112
    }
317
318
612
    memcpy(result_data + (append_sign_manually ? 1 : 0), p, integer_str_len);
319
612
    if (decimal_places > 0) {
320
578
        *(result_data + whole_decimal_str_len - (frac_str_len + 1)) = '.';
321
578
    }
322
323
    // Pad on the right without scaling the value: decimal_places can be as large as 1024.
324
612
    const Int32 trailing_zeros = decimal_places - scale;
325
612
    char* frac_end = result_data + whole_decimal_str_len - trailing_zeros;
326
612
    memset(frac_end, '0', trailing_zeros);
327
12.1k
    for (UInt32 i = 0; i < scale; ++i) {
328
11.5k
        *--frac_end = '0' + (frac_value % 10);
329
11.5k
        frac_value /= 10;
330
11.5k
    }
331
612
    return result;
332
612
}
333
334
} // namespace FormatRound
335
336
template <typename Impl>
337
class FunctionMoneyFormat : public IFunction {
338
public:
339
    static constexpr auto name = "money_format";
340
62
    static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); }
_ZN5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE20EEEE6createEv
Line
Count
Source
340
8
    static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); }
_ZN5doris19FunctionMoneyFormatINS_21MoneyFormatDoubleImplEE6createEv
Line
Count
Source
340
6
    static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); }
_ZN5doris19FunctionMoneyFormatINS_20MoneyFormatInt64ImplEE6createEv
Line
Count
Source
340
6
    static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); }
_ZN5doris19FunctionMoneyFormatINS_21MoneyFormatInt128ImplEE6createEv
Line
Count
Source
340
6
    static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); }
_ZN5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE28EEEE6createEv
Line
Count
Source
340
8
    static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); }
_ZN5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE29EEEE6createEv
Line
Count
Source
340
16
    static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); }
_ZN5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE30EEEE6createEv
Line
Count
Source
340
8
    static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); }
_ZN5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE35EEEE6createEv
Line
Count
Source
340
4
    static FunctionPtr create() { return std::make_shared<FunctionMoneyFormat>(); }
341
16
    String get_name() const override { return name; }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE20EEEE8get_nameB5cxx11Ev
Line
Count
Source
341
2
    String get_name() const override { return name; }
_ZNK5doris19FunctionMoneyFormatINS_21MoneyFormatDoubleImplEE8get_nameB5cxx11Ev
Line
Count
Source
341
2
    String get_name() const override { return name; }
_ZNK5doris19FunctionMoneyFormatINS_20MoneyFormatInt64ImplEE8get_nameB5cxx11Ev
Line
Count
Source
341
2
    String get_name() const override { return name; }
_ZNK5doris19FunctionMoneyFormatINS_21MoneyFormatInt128ImplEE8get_nameB5cxx11Ev
Line
Count
Source
341
2
    String get_name() const override { return name; }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE28EEEE8get_nameB5cxx11Ev
Line
Count
Source
341
2
    String get_name() const override { return name; }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE29EEEE8get_nameB5cxx11Ev
Line
Count
Source
341
2
    String get_name() const override { return name; }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE30EEEE8get_nameB5cxx11Ev
Line
Count
Source
341
2
    String get_name() const override { return name; }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE35EEEE8get_nameB5cxx11Ev
Line
Count
Source
341
2
    String get_name() const override { return name; }
342
343
28
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
344
28
        if (arguments.size() != 1) {
345
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
346
0
                                   "Function {} requires exactly 1 argument", name);
347
0
        }
348
349
28
        return std::make_shared<DataTypeString>();
350
28
    }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE20EEEE20get_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_21MoneyFormatDoubleImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_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_20MoneyFormatInt64ImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_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_21MoneyFormatInt128ImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_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_13PrimitiveTypeE28EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE
Line
Count
Source
343
4
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
344
4
        if (arguments.size() != 1) {
345
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
346
0
                                   "Function {} requires exactly 1 argument", name);
347
0
        }
348
349
4
        return std::make_shared<DataTypeString>();
350
4
    }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE29EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE
Line
Count
Source
343
12
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
344
12
        if (arguments.size() != 1) {
345
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
346
0
                                   "Function {} requires exactly 1 argument", name);
347
0
        }
348
349
12
        return std::make_shared<DataTypeString>();
350
12
    }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE30EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE
Line
Count
Source
343
4
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
344
4
        if (arguments.size() != 1) {
345
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
346
0
                                   "Function {} requires exactly 1 argument", name);
347
0
        }
348
349
4
        return std::make_shared<DataTypeString>();
350
4
    }
Unexecuted instantiation: _ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE35EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE
351
16
    DataTypes get_variadic_argument_types_impl() const override {
352
16
        return Impl::get_variadic_argument_types();
353
16
    }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE20EEEE32get_variadic_argument_types_implEv
Line
Count
Source
351
2
    DataTypes get_variadic_argument_types_impl() const override {
352
2
        return Impl::get_variadic_argument_types();
353
2
    }
_ZNK5doris19FunctionMoneyFormatINS_21MoneyFormatDoubleImplEE32get_variadic_argument_types_implEv
Line
Count
Source
351
2
    DataTypes get_variadic_argument_types_impl() const override {
352
2
        return Impl::get_variadic_argument_types();
353
2
    }
_ZNK5doris19FunctionMoneyFormatINS_20MoneyFormatInt64ImplEE32get_variadic_argument_types_implEv
Line
Count
Source
351
2
    DataTypes get_variadic_argument_types_impl() const override {
352
2
        return Impl::get_variadic_argument_types();
353
2
    }
_ZNK5doris19FunctionMoneyFormatINS_21MoneyFormatInt128ImplEE32get_variadic_argument_types_implEv
Line
Count
Source
351
2
    DataTypes get_variadic_argument_types_impl() const override {
352
2
        return Impl::get_variadic_argument_types();
353
2
    }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE28EEEE32get_variadic_argument_types_implEv
Line
Count
Source
351
2
    DataTypes get_variadic_argument_types_impl() const override {
352
2
        return Impl::get_variadic_argument_types();
353
2
    }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE29EEEE32get_variadic_argument_types_implEv
Line
Count
Source
351
2
    DataTypes get_variadic_argument_types_impl() const override {
352
2
        return Impl::get_variadic_argument_types();
353
2
    }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE30EEEE32get_variadic_argument_types_implEv
Line
Count
Source
351
2
    DataTypes get_variadic_argument_types_impl() const override {
352
2
        return Impl::get_variadic_argument_types();
353
2
    }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE35EEEE32get_variadic_argument_types_implEv
Line
Count
Source
351
2
    DataTypes get_variadic_argument_types_impl() const override {
352
2
        return Impl::get_variadic_argument_types();
353
2
    }
354
28
    size_t get_number_of_arguments() const override { return 1; }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE20EEEE23get_number_of_argumentsEv
Line
Count
Source
354
2
    size_t get_number_of_arguments() const override { return 1; }
_ZNK5doris19FunctionMoneyFormatINS_21MoneyFormatDoubleImplEE23get_number_of_argumentsEv
Line
Count
Source
354
2
    size_t get_number_of_arguments() const override { return 1; }
_ZNK5doris19FunctionMoneyFormatINS_20MoneyFormatInt64ImplEE23get_number_of_argumentsEv
Line
Count
Source
354
2
    size_t get_number_of_arguments() const override { return 1; }
_ZNK5doris19FunctionMoneyFormatINS_21MoneyFormatInt128ImplEE23get_number_of_argumentsEv
Line
Count
Source
354
2
    size_t get_number_of_arguments() const override { return 1; }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE28EEEE23get_number_of_argumentsEv
Line
Count
Source
354
4
    size_t get_number_of_arguments() const override { return 1; }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE29EEEE23get_number_of_argumentsEv
Line
Count
Source
354
12
    size_t get_number_of_arguments() const override { return 1; }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE30EEEE23get_number_of_argumentsEv
Line
Count
Source
354
4
    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
28
                        uint32_t result, size_t input_rows_count) const override {
358
28
        auto res_column = ColumnString::create();
359
28
        ColumnPtr argument_column = block.get_by_position(arguments[0]).column;
360
361
28
        auto result_column = res_column.get();
362
363
28
        Impl::execute(context, result_column, argument_column, input_rows_count);
364
365
28
        block.replace_by_position(result, std::move(res_column));
366
28
        return Status::OK();
367
28
    }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE20EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
357
4
                        uint32_t result, size_t input_rows_count) const override {
358
4
        auto res_column = ColumnString::create();
359
4
        ColumnPtr argument_column = block.get_by_position(arguments[0]).column;
360
361
4
        auto result_column = res_column.get();
362
363
4
        Impl::execute(context, result_column, argument_column, input_rows_count);
364
365
4
        block.replace_by_position(result, std::move(res_column));
366
4
        return Status::OK();
367
4
    }
_ZNK5doris19FunctionMoneyFormatINS_21MoneyFormatDoubleImplEE12execute_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_20MoneyFormatInt64ImplEE12execute_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_21MoneyFormatInt128ImplEE12execute_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_13PrimitiveTypeE28EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
357
4
                        uint32_t result, size_t input_rows_count) const override {
358
4
        auto res_column = ColumnString::create();
359
4
        ColumnPtr argument_column = block.get_by_position(arguments[0]).column;
360
361
4
        auto result_column = res_column.get();
362
363
4
        Impl::execute(context, result_column, argument_column, input_rows_count);
364
365
4
        block.replace_by_position(result, std::move(res_column));
366
4
        return Status::OK();
367
4
    }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE29EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
357
10
                        uint32_t result, size_t input_rows_count) const override {
358
10
        auto res_column = ColumnString::create();
359
10
        ColumnPtr argument_column = block.get_by_position(arguments[0]).column;
360
361
10
        auto result_column = res_column.get();
362
363
10
        Impl::execute(context, result_column, argument_column, input_rows_count);
364
365
10
        block.replace_by_position(result, std::move(res_column));
366
10
        return Status::OK();
367
10
    }
_ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE30EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
357
4
                        uint32_t result, size_t input_rows_count) const override {
358
4
        auto res_column = ColumnString::create();
359
4
        ColumnPtr argument_column = block.get_by_position(arguments[0]).column;
360
361
4
        auto result_column = res_column.get();
362
363
4
        Impl::execute(context, result_column, argument_column, input_rows_count);
364
365
4
        block.replace_by_position(result, std::move(res_column));
366
4
        return Status::OK();
367
4
    }
Unexecuted instantiation: _ZNK5doris19FunctionMoneyFormatINS_22MoneyFormatDecimalImplILNS_13PrimitiveTypeE35EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
368
};
369
370
struct MoneyFormatDoubleImpl {
371
2
    static DataTypes get_variadic_argument_types() { return {std::make_shared<DataTypeFloat64>()}; }
372
373
    static void execute(FunctionContext* context, ColumnString* result_column,
374
2
                        const ColumnPtr col_ptr, size_t input_rows_count) {
375
2
        const auto* data_column = assert_cast<const ColumnFloat64*>(col_ptr.get());
376
        // when scale is above 38, we will go here
377
10
        for (size_t i = 0; i < input_rows_count; i++) {
378
            // round to 2 decimal places
379
8
            double value =
380
8
                    MathFunctions::my_double_round(data_column->get_element(i), 2, false, false);
381
8
            StringRef str = MoneyFormat::do_money_format(context, fmt::format("{:.2f}", value));
382
8
            result_column->insert_data(str.data, str.size);
383
8
        }
384
2
    }
385
};
386
387
struct MoneyFormatInt64Impl {
388
2
    static DataTypes get_variadic_argument_types() { return {std::make_shared<DataTypeInt64>()}; }
389
390
    static void execute(FunctionContext* context, ColumnString* result_column,
391
2
                        const ColumnPtr col_ptr, size_t input_rows_count) {
392
2
        const auto* data_column = assert_cast<const ColumnInt64*>(col_ptr.get());
393
8
        for (size_t i = 0; i < input_rows_count; i++) {
394
6
            Int64 value = data_column->get_element(i);
395
6
            StringRef str =
396
6
                    MoneyFormat::do_money_format<Int64, MoneyFormat::MAX_FORMAT_LEN_INT64()>(
397
6
                            context, 0, value, 0);
398
6
            result_column->insert_data(str.data, str.size);
399
6
        }
400
2
    }
401
};
402
403
struct MoneyFormatInt128Impl {
404
2
    static DataTypes get_variadic_argument_types() { return {std::make_shared<DataTypeInt128>()}; }
405
406
    static void execute(FunctionContext* context, ColumnString* result_column,
407
2
                        const ColumnPtr col_ptr, size_t input_rows_count) {
408
2
        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
8
        for (size_t i = 0; i < input_rows_count; i++) {
413
6
            Int128 value = data_column->get_element(i);
414
6
            StringRef str =
415
6
                    MoneyFormat::do_money_format<Int128, MoneyFormat::MAX_FORMAT_LEN_INT128()>(
416
6
                            context, 0, value, 0);
417
6
            result_column->insert_data(str.data, str.size);
418
6
        }
419
2
    }
420
};
421
422
template <PrimitiveType Type>
423
struct MoneyFormatDecimalImpl {
424
10
    static DataTypes get_variadic_argument_types() {
425
10
        return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>()};
426
10
    }
_ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE20EE27get_variadic_argument_typesEv
Line
Count
Source
424
2
    static DataTypes get_variadic_argument_types() {
425
2
        return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>()};
426
2
    }
_ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE28EE27get_variadic_argument_typesEv
Line
Count
Source
424
2
    static DataTypes get_variadic_argument_types() {
425
2
        return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>()};
426
2
    }
_ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE29EE27get_variadic_argument_typesEv
Line
Count
Source
424
2
    static DataTypes get_variadic_argument_types() {
425
2
        return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>()};
426
2
    }
_ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE30EE27get_variadic_argument_typesEv
Line
Count
Source
424
2
    static DataTypes get_variadic_argument_types() {
425
2
        return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>()};
426
2
    }
_ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE35EE27get_variadic_argument_typesEv
Line
Count
Source
424
2
    static DataTypes get_variadic_argument_types() {
425
2
        return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>()};
426
2
    }
427
428
    static void execute(FunctionContext* context, ColumnString* result_column, ColumnPtr col_ptr,
429
22
                        size_t input_rows_count) {
430
22
        if (auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) {
431
32
            for (size_t i = 0; i < input_rows_count; i++) {
432
28
                const auto& value = decimalv2_column->get_element(i);
433
                // unified_frac_value has 3 digits
434
28
                auto unified_frac_value = value.frac_value() / 1000000;
435
28
                StringRef str =
436
28
                        MoneyFormat::do_money_format<Int128,
437
28
                                                     MoneyFormat::MAX_FORMAT_LEN_DEC128V2()>(
438
28
                                context, 3, value.int_value(), unified_frac_value);
439
440
28
                result_column->insert_data(str.data, str.size);
441
28
            }
442
18
        } else if (auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) {
443
4
            const UInt32 scale = decimal32_column->get_scale();
444
8
            for (size_t i = 0; i < input_rows_count; i++) {
445
4
                const Int32& frac_part = decimal32_column->get_fractional_part(i);
446
4
                const Int32& whole_part = decimal32_column->get_intergral_part(i);
447
4
                StringRef str =
448
4
                        MoneyFormat::do_money_format<Int64, MoneyFormat::MAX_FORMAT_LEN_DEC32()>(
449
4
                                context, scale, static_cast<Int64>(whole_part),
450
4
                                static_cast<Int64>(frac_part));
451
452
4
                result_column->insert_data(str.data, str.size);
453
4
            }
454
14
        } else if (auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) {
455
10
            const UInt32 scale = decimal64_column->get_scale();
456
24
            for (size_t i = 0; i < input_rows_count; i++) {
457
14
                const Int64& frac_part = decimal64_column->get_fractional_part(i);
458
14
                const Int64& whole_part = decimal64_column->get_intergral_part(i);
459
460
14
                StringRef str =
461
14
                        MoneyFormat::do_money_format<Int64, MoneyFormat::MAX_FORMAT_LEN_DEC64()>(
462
14
                                context, scale, whole_part, frac_part);
463
464
14
                result_column->insert_data(str.data, str.size);
465
14
            }
466
10
        } else if (auto* decimal128_column = check_and_get_column<ColumnDecimal128V3>(*col_ptr)) {
467
4
            const UInt32 scale = decimal128_column->get_scale();
468
8
            for (size_t i = 0; i < input_rows_count; i++) {
469
4
                const Int128& frac_part = decimal128_column->get_fractional_part(i);
470
4
                const Int128& whole_part = decimal128_column->get_intergral_part(i);
471
472
4
                StringRef str =
473
4
                        MoneyFormat::do_money_format<Int128,
474
4
                                                     MoneyFormat::MAX_FORMAT_LEN_DEC128V3()>(
475
4
                                context, scale, whole_part, frac_part);
476
477
4
                result_column->insert_data(str.data, str.size);
478
4
            }
479
4
        } 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
22
    }
_ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE20EE7executeEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EEm
Line
Count
Source
429
4
                        size_t input_rows_count) {
430
4
        if (auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) {
431
32
            for (size_t i = 0; i < input_rows_count; i++) {
432
28
                const auto& value = decimalv2_column->get_element(i);
433
                // unified_frac_value has 3 digits
434
28
                auto unified_frac_value = value.frac_value() / 1000000;
435
28
                StringRef str =
436
28
                        MoneyFormat::do_money_format<Int128,
437
28
                                                     MoneyFormat::MAX_FORMAT_LEN_DEC128V2()>(
438
28
                                context, 3, value.int_value(), unified_frac_value);
439
440
28
                result_column->insert_data(str.data, str.size);
441
28
            }
442
4
        } 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
4
    }
_ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE28EE7executeEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EEm
Line
Count
Source
429
4
                        size_t input_rows_count) {
430
4
        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
4
        } else if (auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) {
443
4
            const UInt32 scale = decimal32_column->get_scale();
444
8
            for (size_t i = 0; i < input_rows_count; i++) {
445
4
                const Int32& frac_part = decimal32_column->get_fractional_part(i);
446
4
                const Int32& whole_part = decimal32_column->get_intergral_part(i);
447
4
                StringRef str =
448
4
                        MoneyFormat::do_money_format<Int64, MoneyFormat::MAX_FORMAT_LEN_DEC32()>(
449
4
                                context, scale, static_cast<Int64>(whole_part),
450
4
                                static_cast<Int64>(frac_part));
451
452
4
                result_column->insert_data(str.data, str.size);
453
4
            }
454
4
        } 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
4
    }
_ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE29EE7executeEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EEm
Line
Count
Source
429
10
                        size_t input_rows_count) {
430
10
        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
10
        } 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
10
        } else if (auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) {
455
10
            const UInt32 scale = decimal64_column->get_scale();
456
24
            for (size_t i = 0; i < input_rows_count; i++) {
457
14
                const Int64& frac_part = decimal64_column->get_fractional_part(i);
458
14
                const Int64& whole_part = decimal64_column->get_intergral_part(i);
459
460
14
                StringRef str =
461
14
                        MoneyFormat::do_money_format<Int64, MoneyFormat::MAX_FORMAT_LEN_DEC64()>(
462
14
                                context, scale, whole_part, frac_part);
463
464
14
                result_column->insert_data(str.data, str.size);
465
14
            }
466
10
        } 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
10
    }
_ZN5doris22MoneyFormatDecimalImplILNS_13PrimitiveTypeE30EE7executeEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EEm
Line
Count
Source
429
4
                        size_t input_rows_count) {
430
4
        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
4
        } 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
4
        } 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
4
        } else if (auto* decimal128_column = check_and_get_column<ColumnDecimal128V3>(*col_ptr)) {
467
4
            const UInt32 scale = decimal128_column->get_scale();
468
8
            for (size_t i = 0; i < input_rows_count; i++) {
469
4
                const Int128& frac_part = decimal128_column->get_fractional_part(i);
470
4
                const Int128& whole_part = decimal128_column->get_intergral_part(i);
471
472
4
                StringRef str =
473
4
                        MoneyFormat::do_money_format<Int128,
474
4
                                                     MoneyFormat::MAX_FORMAT_LEN_DEC128V3()>(
475
4
                                context, scale, whole_part, frac_part);
476
477
4
                result_column->insert_data(str.data, str.size);
478
4
            }
479
4
        } 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
4
    }
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
1.80k
    static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); }
_ZN5doris25FunctionStringFormatRoundINS_21FormatRoundDoubleImplEE6createEv
Line
Count
Source
511
6
    static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); }
_ZN5doris25FunctionStringFormatRoundINS_20FormatRoundInt64ImplEE6createEv
Line
Count
Source
511
20
    static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); }
_ZN5doris25FunctionStringFormatRoundINS_21FormatRoundInt128ImplEE6createEv
Line
Count
Source
511
14
    static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); }
_ZN5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE20EEEE6createEv
Line
Count
Source
511
6
    static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); }
_ZN5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EEEE6createEv
Line
Count
Source
511
288
    static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); }
_ZN5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EEEE6createEv
Line
Count
Source
511
372
    static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); }
_ZN5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EEEE6createEv
Line
Count
Source
511
616
    static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); }
_ZN5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EEEE6createEv
Line
Count
Source
511
480
    static FunctionPtr create() { return std::make_shared<FunctionStringFormatRound>(); }
512
16
    String get_name() const override { return name; }
_ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundDoubleImplEE8get_nameB5cxx11Ev
Line
Count
Source
512
2
    String get_name() const override { return name; }
_ZNK5doris25FunctionStringFormatRoundINS_20FormatRoundInt64ImplEE8get_nameB5cxx11Ev
Line
Count
Source
512
2
    String get_name() const override { return name; }
_ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundInt128ImplEE8get_nameB5cxx11Ev
Line
Count
Source
512
2
    String get_name() const override { return name; }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE20EEEE8get_nameB5cxx11Ev
Line
Count
Source
512
2
    String get_name() const override { return name; }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EEEE8get_nameB5cxx11Ev
Line
Count
Source
512
2
    String get_name() const override { return name; }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EEEE8get_nameB5cxx11Ev
Line
Count
Source
512
2
    String get_name() const override { return name; }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EEEE8get_nameB5cxx11Ev
Line
Count
Source
512
2
    String get_name() const override { return name; }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EEEE8get_nameB5cxx11Ev
Line
Count
Source
512
2
    String get_name() const override { return name; }
513
514
1.77k
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
515
1.77k
        if (arguments.size() != 2) {
516
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
517
0
                                   "Function {} requires exactly 2 argument", name);
518
0
        }
519
1.77k
        return std::make_shared<DataTypeString>();
520
1.77k
    }
_ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundDoubleImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
514
2
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
515
2
        if (arguments.size() != 2) {
516
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
517
0
                                   "Function {} requires exactly 2 argument", name);
518
0
        }
519
2
        return std::make_shared<DataTypeString>();
520
2
    }
_ZNK5doris25FunctionStringFormatRoundINS_20FormatRoundInt64ImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
514
16
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
515
16
        if (arguments.size() != 2) {
516
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
517
0
                                   "Function {} requires exactly 2 argument", name);
518
0
        }
519
16
        return std::make_shared<DataTypeString>();
520
16
    }
_ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundInt128ImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
514
10
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
515
10
        if (arguments.size() != 2) {
516
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
517
0
                                   "Function {} requires exactly 2 argument", name);
518
0
        }
519
10
        return std::make_shared<DataTypeString>();
520
10
    }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE20EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE
Line
Count
Source
514
2
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
515
2
        if (arguments.size() != 2) {
516
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
517
0
                                   "Function {} requires exactly 2 argument", name);
518
0
        }
519
2
        return std::make_shared<DataTypeString>();
520
2
    }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE
Line
Count
Source
514
284
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
515
284
        if (arguments.size() != 2) {
516
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
517
0
                                   "Function {} requires exactly 2 argument", name);
518
0
        }
519
284
        return std::make_shared<DataTypeString>();
520
284
    }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE
Line
Count
Source
514
368
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
515
368
        if (arguments.size() != 2) {
516
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
517
0
                                   "Function {} requires exactly 2 argument", name);
518
0
        }
519
368
        return std::make_shared<DataTypeString>();
520
368
    }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE
Line
Count
Source
514
612
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
515
612
        if (arguments.size() != 2) {
516
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
517
0
                                   "Function {} requires exactly 2 argument", name);
518
0
        }
519
612
        return std::make_shared<DataTypeString>();
520
612
    }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EEEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS9_EE
Line
Count
Source
514
476
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
515
476
        if (arguments.size() != 2) {
516
0
            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
517
0
                                   "Function {} requires exactly 2 argument", name);
518
0
        }
519
476
        return std::make_shared<DataTypeString>();
520
476
    }
521
16
    DataTypes get_variadic_argument_types_impl() const override {
522
16
        return Impl::get_variadic_argument_types();
523
16
    }
_ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundDoubleImplEE32get_variadic_argument_types_implEv
Line
Count
Source
521
2
    DataTypes get_variadic_argument_types_impl() const override {
522
2
        return Impl::get_variadic_argument_types();
523
2
    }
_ZNK5doris25FunctionStringFormatRoundINS_20FormatRoundInt64ImplEE32get_variadic_argument_types_implEv
Line
Count
Source
521
2
    DataTypes get_variadic_argument_types_impl() const override {
522
2
        return Impl::get_variadic_argument_types();
523
2
    }
_ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundInt128ImplEE32get_variadic_argument_types_implEv
Line
Count
Source
521
2
    DataTypes get_variadic_argument_types_impl() const override {
522
2
        return Impl::get_variadic_argument_types();
523
2
    }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE20EEEE32get_variadic_argument_types_implEv
Line
Count
Source
521
2
    DataTypes get_variadic_argument_types_impl() const override {
522
2
        return Impl::get_variadic_argument_types();
523
2
    }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EEEE32get_variadic_argument_types_implEv
Line
Count
Source
521
2
    DataTypes get_variadic_argument_types_impl() const override {
522
2
        return Impl::get_variadic_argument_types();
523
2
    }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EEEE32get_variadic_argument_types_implEv
Line
Count
Source
521
2
    DataTypes get_variadic_argument_types_impl() const override {
522
2
        return Impl::get_variadic_argument_types();
523
2
    }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EEEE32get_variadic_argument_types_implEv
Line
Count
Source
521
2
    DataTypes get_variadic_argument_types_impl() const override {
522
2
        return Impl::get_variadic_argument_types();
523
2
    }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EEEE32get_variadic_argument_types_implEv
Line
Count
Source
521
2
    DataTypes get_variadic_argument_types_impl() const override {
522
2
        return Impl::get_variadic_argument_types();
523
2
    }
524
1.77k
    size_t get_number_of_arguments() const override { return 2; }
_ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundDoubleImplEE23get_number_of_argumentsEv
Line
Count
Source
524
2
    size_t get_number_of_arguments() const override { return 2; }
_ZNK5doris25FunctionStringFormatRoundINS_20FormatRoundInt64ImplEE23get_number_of_argumentsEv
Line
Count
Source
524
16
    size_t get_number_of_arguments() const override { return 2; }
_ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundInt128ImplEE23get_number_of_argumentsEv
Line
Count
Source
524
10
    size_t get_number_of_arguments() const override { return 2; }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE20EEEE23get_number_of_argumentsEv
Line
Count
Source
524
2
    size_t get_number_of_arguments() const override { return 2; }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EEEE23get_number_of_argumentsEv
Line
Count
Source
524
284
    size_t get_number_of_arguments() const override { return 2; }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EEEE23get_number_of_argumentsEv
Line
Count
Source
524
368
    size_t get_number_of_arguments() const override { return 2; }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EEEE23get_number_of_argumentsEv
Line
Count
Source
524
612
    size_t get_number_of_arguments() const override { return 2; }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EEEE23get_number_of_argumentsEv
Line
Count
Source
524
476
    size_t get_number_of_arguments() const override { return 2; }
525
526
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
527
1.70k
                        uint32_t result, size_t input_rows_count) const override {
528
1.70k
        auto res_column = ColumnString::create();
529
1.70k
        ColumnPtr argument_column =
530
1.70k
                block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
531
1.70k
        ColumnPtr argument_column_2;
532
1.70k
        bool is_const;
533
1.70k
        std::tie(argument_column_2, is_const) =
534
1.70k
                unpack_if_const(block.get_by_position(arguments[1]).column);
535
1.70k
        auto* result_column = res_column.get();
536
537
1.70k
        if (is_const) {
538
556
            RETURN_IF_ERROR(Impl::template execute<true>(context, result_column, argument_column,
539
556
                                                         argument_column_2, input_rows_count));
540
1.14k
        } else {
541
1.14k
            RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column,
542
1.14k
                                                          argument_column_2, input_rows_count));
543
1.14k
        }
544
545
1.70k
        block.replace_by_position(result, std::move(res_column));
546
1.70k
        return Status::OK();
547
1.70k
    }
_ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundDoubleImplEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
527
2
                        uint32_t result, size_t input_rows_count) const override {
528
2
        auto res_column = ColumnString::create();
529
2
        ColumnPtr argument_column =
530
2
                block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
531
2
        ColumnPtr argument_column_2;
532
2
        bool is_const;
533
2
        std::tie(argument_column_2, is_const) =
534
2
                unpack_if_const(block.get_by_position(arguments[1]).column);
535
2
        auto* result_column = res_column.get();
536
537
2
        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
2
        } else {
541
2
            RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column,
542
2
                                                          argument_column_2, input_rows_count));
543
2
        }
544
545
2
        block.replace_by_position(result, std::move(res_column));
546
2
        return Status::OK();
547
2
    }
_ZNK5doris25FunctionStringFormatRoundINS_20FormatRoundInt64ImplEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
527
16
                        uint32_t result, size_t input_rows_count) const override {
528
16
        auto res_column = ColumnString::create();
529
16
        ColumnPtr argument_column =
530
16
                block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
531
16
        ColumnPtr argument_column_2;
532
16
        bool is_const;
533
16
        std::tie(argument_column_2, is_const) =
534
16
                unpack_if_const(block.get_by_position(arguments[1]).column);
535
16
        auto* result_column = res_column.get();
536
537
16
        if (is_const) {
538
4
            RETURN_IF_ERROR(Impl::template execute<true>(context, result_column, argument_column,
539
4
                                                         argument_column_2, input_rows_count));
540
12
        } else {
541
12
            RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column,
542
12
                                                          argument_column_2, input_rows_count));
543
12
        }
544
545
16
        block.replace_by_position(result, std::move(res_column));
546
16
        return Status::OK();
547
16
    }
_ZNK5doris25FunctionStringFormatRoundINS_21FormatRoundInt128ImplEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
527
10
                        uint32_t result, size_t input_rows_count) const override {
528
10
        auto res_column = ColumnString::create();
529
10
        ColumnPtr argument_column =
530
10
                block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
531
10
        ColumnPtr argument_column_2;
532
10
        bool is_const;
533
10
        std::tie(argument_column_2, is_const) =
534
10
                unpack_if_const(block.get_by_position(arguments[1]).column);
535
10
        auto* result_column = res_column.get();
536
537
10
        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
8
        } else {
541
8
            RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column,
542
8
                                                          argument_column_2, input_rows_count));
543
8
        }
544
545
10
        block.replace_by_position(result, std::move(res_column));
546
10
        return Status::OK();
547
10
    }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE20EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
527
2
                        uint32_t result, size_t input_rows_count) const override {
528
2
        auto res_column = ColumnString::create();
529
2
        ColumnPtr argument_column =
530
2
                block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
531
2
        ColumnPtr argument_column_2;
532
2
        bool is_const;
533
2
        std::tie(argument_column_2, is_const) =
534
2
                unpack_if_const(block.get_by_position(arguments[1]).column);
535
2
        auto* result_column = res_column.get();
536
537
2
        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
2
        } else {
541
2
            RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column,
542
2
                                                          argument_column_2, input_rows_count));
543
2
        }
544
545
2
        block.replace_by_position(result, std::move(res_column));
546
2
        return Status::OK();
547
2
    }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
527
272
                        uint32_t result, size_t input_rows_count) const override {
528
272
        auto res_column = ColumnString::create();
529
272
        ColumnPtr argument_column =
530
272
                block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
531
272
        ColumnPtr argument_column_2;
532
272
        bool is_const;
533
272
        std::tie(argument_column_2, is_const) =
534
272
                unpack_if_const(block.get_by_position(arguments[1]).column);
535
272
        auto* result_column = res_column.get();
536
537
272
        if (is_const) {
538
90
            RETURN_IF_ERROR(Impl::template execute<true>(context, result_column, argument_column,
539
90
                                                         argument_column_2, input_rows_count));
540
182
        } else {
541
182
            RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column,
542
182
                                                          argument_column_2, input_rows_count));
543
182
        }
544
545
272
        block.replace_by_position(result, std::move(res_column));
546
272
        return Status::OK();
547
272
    }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
527
350
                        uint32_t result, size_t input_rows_count) const override {
528
350
        auto res_column = ColumnString::create();
529
350
        ColumnPtr argument_column =
530
350
                block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
531
350
        ColumnPtr argument_column_2;
532
350
        bool is_const;
533
350
        std::tie(argument_column_2, is_const) =
534
350
                unpack_if_const(block.get_by_position(arguments[1]).column);
535
350
        auto* result_column = res_column.get();
536
537
350
        if (is_const) {
538
114
            RETURN_IF_ERROR(Impl::template execute<true>(context, result_column, argument_column,
539
114
                                                         argument_column_2, input_rows_count));
540
236
        } else {
541
236
            RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column,
542
236
                                                          argument_column_2, input_rows_count));
543
236
        }
544
545
350
        block.replace_by_position(result, std::move(res_column));
546
350
        return Status::OK();
547
350
    }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
527
588
                        uint32_t result, size_t input_rows_count) const override {
528
588
        auto res_column = ColumnString::create();
529
588
        ColumnPtr argument_column =
530
588
                block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
531
588
        ColumnPtr argument_column_2;
532
588
        bool is_const;
533
588
        std::tie(argument_column_2, is_const) =
534
588
                unpack_if_const(block.get_by_position(arguments[1]).column);
535
588
        auto* result_column = res_column.get();
536
537
588
        if (is_const) {
538
194
            RETURN_IF_ERROR(Impl::template execute<true>(context, result_column, argument_column,
539
194
                                                         argument_column_2, input_rows_count));
540
394
        } else {
541
394
            RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column,
542
394
                                                          argument_column_2, input_rows_count));
543
394
        }
544
545
588
        block.replace_by_position(result, std::move(res_column));
546
588
        return Status::OK();
547
588
    }
_ZNK5doris25FunctionStringFormatRoundINS_22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EEEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
527
464
                        uint32_t result, size_t input_rows_count) const override {
528
464
        auto res_column = ColumnString::create();
529
464
        ColumnPtr argument_column =
530
464
                block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
531
464
        ColumnPtr argument_column_2;
532
464
        bool is_const;
533
464
        std::tie(argument_column_2, is_const) =
534
464
                unpack_if_const(block.get_by_position(arguments[1]).column);
535
464
        auto* result_column = res_column.get();
536
537
464
        if (is_const) {
538
152
            RETURN_IF_ERROR(Impl::template execute<true>(context, result_column, argument_column,
539
152
                                                         argument_column_2, input_rows_count));
540
312
        } else {
541
312
            RETURN_IF_ERROR(Impl::template execute<false>(context, result_column, argument_column,
542
312
                                                          argument_column_2, input_rows_count));
543
312
        }
544
545
464
        block.replace_by_position(result, std::move(res_column));
546
464
        return Status::OK();
547
464
    }
548
};
549
550
struct FormatRoundDoubleImpl {
551
2
    static DataTypes get_variadic_argument_types() {
552
2
        return {std::make_shared<DataTypeFloat64>(), std::make_shared<DataTypeInt32>()};
553
2
    }
554
555
8
    static std::string add_thousands_separator(const std::string& formatted_num) {
556
        //  Find the position of the decimal point
557
8
        size_t dot_pos = formatted_num.find('.');
558
8
        if (dot_pos == std::string::npos) {
559
0
            dot_pos = formatted_num.size();
560
0
        }
561
562
        // Handle the integer part
563
8
        int start = (formatted_num[0] == '-') ? 1 : 0;
564
8
        int digit_count = dot_pos - start;
565
566
        // There is no need to add commas.
567
8
        if (digit_count <= 3) {
568
4
            return formatted_num;
569
4
        }
570
571
4
        std::string result;
572
573
4
        if (start == 1) result += '-';
574
575
        // Add the integer part (with comma)
576
4
        int first_group = digit_count % 3;
577
4
        if (first_group == 0) first_group = 3;
578
4
        result.append(formatted_num, start, first_group);
579
580
12
        for (size_t i = start + first_group; i < dot_pos; i += 3) {
581
8
            result += ',';
582
8
            result.append(formatted_num, i, 3);
583
8
        }
584
585
        // Add the decimal part (keep as it is)
586
4
        if (dot_pos != formatted_num.size()) {
587
4
            result.append(formatted_num, dot_pos);
588
4
        }
589
590
4
        return result;
591
8
    }
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
2
                          size_t input_rows_count) {
597
2
        const auto& arg_column_data_2 =
598
2
                assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data();
599
2
        const auto* data_column = assert_cast<const ColumnFloat64*>(col_ptr.get());
600
        // when scale is above 38, we will go here
601
10
        for (size_t i = 0; i < input_rows_count; i++) {
602
8
            int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
603
8
            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
8
            double value = MathFunctions::my_double_round(data_column->get_element(i),
610
8
                                                          decimal_places, false, false);
611
8
            std::string formatted_value = fmt::format("{:.{}f}", value, decimal_places);
612
8
            if (std::isfinite(value)) {
613
8
                result_column->insert_value(add_thousands_separator(formatted_value));
614
8
            } 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
8
        }
620
2
        return Status::OK();
621
2
    }
Unexecuted instantiation: _ZN5doris21FormatRoundDoubleImpl7executeILb1EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EESC_m
_ZN5doris21FormatRoundDoubleImpl7executeILb0EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EESC_m
Line
Count
Source
596
2
                          size_t input_rows_count) {
597
2
        const auto& arg_column_data_2 =
598
2
                assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data();
599
2
        const auto* data_column = assert_cast<const ColumnFloat64*>(col_ptr.get());
600
        // when scale is above 38, we will go here
601
10
        for (size_t i = 0; i < input_rows_count; i++) {
602
8
            int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
603
8
            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
8
            double value = MathFunctions::my_double_round(data_column->get_element(i),
610
8
                                                          decimal_places, false, false);
611
8
            std::string formatted_value = fmt::format("{:.{}f}", value, decimal_places);
612
8
            if (std::isfinite(value)) {
613
8
                result_column->insert_value(add_thousands_separator(formatted_value));
614
8
            } 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
8
        }
620
2
        return Status::OK();
621
2
    }
622
};
623
624
struct FormatRoundInt64Impl {
625
2
    static DataTypes get_variadic_argument_types() {
626
2
        return {std::make_shared<DataTypeInt64>(), std::make_shared<DataTypeInt32>()};
627
2
    }
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
16
                          size_t input_rows_count) {
633
16
        const auto* data_column = assert_cast<const ColumnInt64*>(col_ptr.get());
634
16
        const auto& arg_column_data_2 =
635
16
                assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data();
636
48
        for (size_t i = 0; i < input_rows_count; i++) {
637
32
            int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
638
32
            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
32
            Int64 value = data_column->get_element(i);
644
32
            StringRef str =
645
32
                    FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_INT64()>(
646
32
                            context, 0, value, 0, decimal_places);
647
32
            result_column->insert_data(str.data, str.size);
648
32
        }
649
16
        return Status::OK();
650
16
    }
_ZN5doris20FormatRoundInt64Impl7executeILb1EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EESC_m
Line
Count
Source
632
4
                          size_t input_rows_count) {
633
4
        const auto* data_column = assert_cast<const ColumnInt64*>(col_ptr.get());
634
4
        const auto& arg_column_data_2 =
635
4
                assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data();
636
8
        for (size_t i = 0; i < input_rows_count; i++) {
637
4
            int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
638
4
            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
4
            Int64 value = data_column->get_element(i);
644
4
            StringRef str =
645
4
                    FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_INT64()>(
646
4
                            context, 0, value, 0, decimal_places);
647
4
            result_column->insert_data(str.data, str.size);
648
4
        }
649
4
        return Status::OK();
650
4
    }
_ZN5doris20FormatRoundInt64Impl7executeILb0EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EESC_m
Line
Count
Source
632
12
                          size_t input_rows_count) {
633
12
        const auto* data_column = assert_cast<const ColumnInt64*>(col_ptr.get());
634
12
        const auto& arg_column_data_2 =
635
12
                assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data();
636
40
        for (size_t i = 0; i < input_rows_count; i++) {
637
28
            int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
638
28
            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
28
            Int64 value = data_column->get_element(i);
644
28
            StringRef str =
645
28
                    FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_INT64()>(
646
28
                            context, 0, value, 0, decimal_places);
647
28
            result_column->insert_data(str.data, str.size);
648
28
        }
649
12
        return Status::OK();
650
12
    }
651
};
652
653
struct FormatRoundInt128Impl {
654
2
    static DataTypes get_variadic_argument_types() {
655
2
        return {std::make_shared<DataTypeInt128>(), std::make_shared<DataTypeInt32>()};
656
2
    }
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
10
                          size_t input_rows_count) {
662
10
        const auto* data_column = assert_cast<const ColumnInt128*>(col_ptr.get());
663
10
        const auto& arg_column_data_2 =
664
10
                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
36
        for (size_t i = 0; i < input_rows_count; i++) {
669
26
            int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
670
26
            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
26
            Int128 value = data_column->get_element(i);
676
26
            StringRef str =
677
26
                    FormatRound::do_format_round<Int128, FormatRound::MAX_FORMAT_LEN_INT128()>(
678
26
                            context, 0, value, 0, decimal_places);
679
26
            result_column->insert_data(str.data, str.size);
680
26
        }
681
10
        return Status::OK();
682
10
    }
_ZN5doris21FormatRoundInt128Impl7executeILb1EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EESC_m
Line
Count
Source
661
2
                          size_t input_rows_count) {
662
2
        const auto* data_column = assert_cast<const ColumnInt128*>(col_ptr.get());
663
2
        const auto& arg_column_data_2 =
664
2
                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
4
        for (size_t i = 0; i < input_rows_count; i++) {
669
2
            int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
670
2
            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
2
            Int128 value = data_column->get_element(i);
676
2
            StringRef str =
677
2
                    FormatRound::do_format_round<Int128, FormatRound::MAX_FORMAT_LEN_INT128()>(
678
2
                            context, 0, value, 0, decimal_places);
679
2
            result_column->insert_data(str.data, str.size);
680
2
        }
681
2
        return Status::OK();
682
2
    }
_ZN5doris21FormatRoundInt128Impl7executeILb0EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrIS9_EESC_m
Line
Count
Source
661
8
                          size_t input_rows_count) {
662
8
        const auto* data_column = assert_cast<const ColumnInt128*>(col_ptr.get());
663
8
        const auto& arg_column_data_2 =
664
8
                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
32
        for (size_t i = 0; i < input_rows_count; i++) {
669
24
            int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
670
24
            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
24
            Int128 value = data_column->get_element(i);
676
24
            StringRef str =
677
24
                    FormatRound::do_format_round<Int128, FormatRound::MAX_FORMAT_LEN_INT128()>(
678
24
                            context, 0, value, 0, decimal_places);
679
24
            result_column->insert_data(str.data, str.size);
680
24
        }
681
8
        return Status::OK();
682
8
    }
683
};
684
685
template <PrimitiveType Type>
686
struct FormatRoundDecimalImpl {
687
10
    static DataTypes get_variadic_argument_types() {
688
10
        return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>(),
689
10
                std::make_shared<DataTypeInt32>()};
690
10
    }
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE20EE27get_variadic_argument_typesEv
Line
Count
Source
687
2
    static DataTypes get_variadic_argument_types() {
688
2
        return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>(),
689
2
                std::make_shared<DataTypeInt32>()};
690
2
    }
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EE27get_variadic_argument_typesEv
Line
Count
Source
687
2
    static DataTypes get_variadic_argument_types() {
688
2
        return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>(),
689
2
                std::make_shared<DataTypeInt32>()};
690
2
    }
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EE27get_variadic_argument_typesEv
Line
Count
Source
687
2
    static DataTypes get_variadic_argument_types() {
688
2
        return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>(),
689
2
                std::make_shared<DataTypeInt32>()};
690
2
    }
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EE27get_variadic_argument_typesEv
Line
Count
Source
687
2
    static DataTypes get_variadic_argument_types() {
688
2
        return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>(),
689
2
                std::make_shared<DataTypeInt32>()};
690
2
    }
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EE27get_variadic_argument_typesEv
Line
Count
Source
687
2
    static DataTypes get_variadic_argument_types() {
688
2
        return {std::make_shared<typename PrimitiveTypeTraits<Type>::DataType>(),
689
2
                std::make_shared<DataTypeInt32>()};
690
2
    }
691
692
    template <bool is_const>
693
    static Status execute(FunctionContext* context, ColumnString* result_column, ColumnPtr col_ptr,
694
1.67k
                          ColumnPtr decimal_places_col_ptr, size_t input_rows_count) {
695
1.67k
        const auto& arg_column_data_2 =
696
1.67k
                assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data();
697
1.67k
        if (const auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) {
698
8
            for (size_t i = 0; i < input_rows_count; i++) {
699
6
                int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
700
6
                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
6
                const auto& value = decimalv2_column->get_element(i);
706
                // unified_frac_value has 3 digits
707
6
                auto unified_frac_value = value.frac_value() / 1000000;
708
6
                StringRef str =
709
6
                        FormatRound::do_format_round<Int128,
710
6
                                                     FormatRound::MAX_FORMAT_LEN_DEC128V2()>(
711
6
                                context, 3, value.int_value(), unified_frac_value, decimal_places);
712
713
6
                result_column->insert_data(str.data, str.size);
714
6
            }
715
1.67k
        } else if (const auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) {
716
272
            const UInt32 scale = decimal32_column->get_scale();
717
636
            for (size_t i = 0; i < input_rows_count; i++) {
718
364
                int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
719
364
                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
364
                const Int32& frac_part = decimal32_column->get_fractional_part(i);
725
364
                const Int32& whole_part = decimal32_column->get_intergral_part(i);
726
364
                StringRef str =
727
364
                        FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC32()>(
728
364
                                context, scale, static_cast<Int64>(whole_part),
729
364
                                static_cast<Int64>(frac_part), decimal_places);
730
731
364
                result_column->insert_data(str.data, str.size);
732
364
            }
733
1.40k
        } else if (const auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) {
734
350
            const UInt32 scale = decimal64_column->get_scale();
735
816
            for (size_t i = 0; i < input_rows_count; i++) {
736
466
                int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
737
466
                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
466
                const Int64& frac_part = decimal64_column->get_fractional_part(i);
743
466
                const Int64& whole_part = decimal64_column->get_intergral_part(i);
744
745
466
                StringRef str =
746
466
                        FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC64()>(
747
466
                                context, scale, whole_part, frac_part, decimal_places);
748
749
466
                result_column->insert_data(str.data, str.size);
750
466
            }
751
1.05k
        } else if (const auto* decimal128_column =
752
1.05k
                           check_and_get_column<ColumnDecimal128V3>(*col_ptr)) {
753
588
            const UInt32 scale = decimal128_column->get_scale();
754
1.37k
            for (size_t i = 0; i < input_rows_count; i++) {
755
784
                int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
756
784
                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
784
                const Int128& frac_part = decimal128_column->get_fractional_part(i);
762
784
                const Int128& whole_part = decimal128_column->get_intergral_part(i);
763
764
784
                StringRef str =
765
784
                        FormatRound::do_format_round<Int128,
766
784
                                                     FormatRound::MAX_FORMAT_LEN_DEC128V3()>(
767
784
                                context, scale, whole_part, frac_part, decimal_places);
768
769
784
                result_column->insert_data(str.data, str.size);
770
784
            }
771
588
        } else if (const auto* decimal256_column =
772
464
                           check_and_get_column<ColumnDecimal256>(*col_ptr)) {
773
464
            const UInt32 scale = decimal256_column->get_scale();
774
1.07k
            for (size_t i = 0; i < input_rows_count; i++) {
775
612
                int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
776
612
                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
612
                const auto frac_part = decimal256_column->get_fractional_part(i);
782
612
                const auto whole_part = decimal256_column->get_intergral_part(i);
783
612
                StringRef str = FormatRound::do_format_round<wide::Int256,
784
612
                                                             FormatRound::MAX_FORMAT_LEN_DEC256()>(
785
612
                        context, scale, whole_part, frac_part, decimal_places);
786
787
612
                result_column->insert_data(str.data, str.size);
788
612
            }
789
464
        } else {
790
0
            return Status::InternalError("Not supported input argument type {}",
791
0
                                         col_ptr->get_name());
792
0
        }
793
1.67k
        return Status::OK();
794
1.67k
    }
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
2
                          ColumnPtr decimal_places_col_ptr, size_t input_rows_count) {
695
2
        const auto& arg_column_data_2 =
696
2
                assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data();
697
2
        if (const auto* decimalv2_column = check_and_get_column<ColumnDecimal128V2>(*col_ptr)) {
698
8
            for (size_t i = 0; i < input_rows_count; i++) {
699
6
                int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
700
6
                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
6
                const auto& value = decimalv2_column->get_element(i);
706
                // unified_frac_value has 3 digits
707
6
                auto unified_frac_value = value.frac_value() / 1000000;
708
6
                StringRef str =
709
6
                        FormatRound::do_format_round<Int128,
710
6
                                                     FormatRound::MAX_FORMAT_LEN_DEC128V2()>(
711
6
                                context, 3, value.int_value(), unified_frac_value, decimal_places);
712
713
6
                result_column->insert_data(str.data, str.size);
714
6
            }
715
2
        } 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
2
        return Status::OK();
794
2
    }
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EE7executeILb1EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m
Line
Count
Source
694
90
                          ColumnPtr decimal_places_col_ptr, size_t input_rows_count) {
695
90
        const auto& arg_column_data_2 =
696
90
                assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data();
697
90
        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
90
        } else if (const auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) {
716
90
            const UInt32 scale = decimal32_column->get_scale();
717
180
            for (size_t i = 0; i < input_rows_count; i++) {
718
90
                int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
719
90
                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
90
                const Int32& frac_part = decimal32_column->get_fractional_part(i);
725
90
                const Int32& whole_part = decimal32_column->get_intergral_part(i);
726
90
                StringRef str =
727
90
                        FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC32()>(
728
90
                                context, scale, static_cast<Int64>(whole_part),
729
90
                                static_cast<Int64>(frac_part), decimal_places);
730
731
90
                result_column->insert_data(str.data, str.size);
732
90
            }
733
90
        } 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
90
        return Status::OK();
794
90
    }
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE28EE7executeILb0EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m
Line
Count
Source
694
182
                          ColumnPtr decimal_places_col_ptr, size_t input_rows_count) {
695
182
        const auto& arg_column_data_2 =
696
182
                assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data();
697
182
        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
182
        } else if (const auto* decimal32_column = check_and_get_column<ColumnDecimal32>(*col_ptr)) {
716
182
            const UInt32 scale = decimal32_column->get_scale();
717
456
            for (size_t i = 0; i < input_rows_count; i++) {
718
274
                int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
719
274
                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
274
                const Int32& frac_part = decimal32_column->get_fractional_part(i);
725
274
                const Int32& whole_part = decimal32_column->get_intergral_part(i);
726
274
                StringRef str =
727
274
                        FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC32()>(
728
274
                                context, scale, static_cast<Int64>(whole_part),
729
274
                                static_cast<Int64>(frac_part), decimal_places);
730
731
274
                result_column->insert_data(str.data, str.size);
732
274
            }
733
182
        } 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
182
        return Status::OK();
794
182
    }
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EE7executeILb1EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m
Line
Count
Source
694
114
                          ColumnPtr decimal_places_col_ptr, size_t input_rows_count) {
695
114
        const auto& arg_column_data_2 =
696
114
                assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data();
697
114
        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
114
        } 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
114
        } else if (const auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) {
734
114
            const UInt32 scale = decimal64_column->get_scale();
735
228
            for (size_t i = 0; i < input_rows_count; i++) {
736
114
                int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
737
114
                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
114
                const Int64& frac_part = decimal64_column->get_fractional_part(i);
743
114
                const Int64& whole_part = decimal64_column->get_intergral_part(i);
744
745
114
                StringRef str =
746
114
                        FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC64()>(
747
114
                                context, scale, whole_part, frac_part, decimal_places);
748
749
114
                result_column->insert_data(str.data, str.size);
750
114
            }
751
114
        } 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
114
        return Status::OK();
794
114
    }
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE29EE7executeILb0EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m
Line
Count
Source
694
236
                          ColumnPtr decimal_places_col_ptr, size_t input_rows_count) {
695
236
        const auto& arg_column_data_2 =
696
236
                assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data();
697
236
        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
236
        } 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
236
        } else if (const auto* decimal64_column = check_and_get_column<ColumnDecimal64>(*col_ptr)) {
734
236
            const UInt32 scale = decimal64_column->get_scale();
735
588
            for (size_t i = 0; i < input_rows_count; i++) {
736
352
                int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
737
352
                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
352
                const Int64& frac_part = decimal64_column->get_fractional_part(i);
743
352
                const Int64& whole_part = decimal64_column->get_intergral_part(i);
744
745
352
                StringRef str =
746
352
                        FormatRound::do_format_round<Int64, FormatRound::MAX_FORMAT_LEN_DEC64()>(
747
352
                                context, scale, whole_part, frac_part, decimal_places);
748
749
352
                result_column->insert_data(str.data, str.size);
750
352
            }
751
236
        } 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
236
        return Status::OK();
794
236
    }
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EE7executeILb1EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m
Line
Count
Source
694
194
                          ColumnPtr decimal_places_col_ptr, size_t input_rows_count) {
695
194
        const auto& arg_column_data_2 =
696
194
                assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data();
697
194
        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
194
        } 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
194
        } 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
194
        } else if (const auto* decimal128_column =
752
194
                           check_and_get_column<ColumnDecimal128V3>(*col_ptr)) {
753
194
            const UInt32 scale = decimal128_column->get_scale();
754
388
            for (size_t i = 0; i < input_rows_count; i++) {
755
194
                int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
756
194
                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
194
                const Int128& frac_part = decimal128_column->get_fractional_part(i);
762
194
                const Int128& whole_part = decimal128_column->get_intergral_part(i);
763
764
194
                StringRef str =
765
194
                        FormatRound::do_format_round<Int128,
766
194
                                                     FormatRound::MAX_FORMAT_LEN_DEC128V3()>(
767
194
                                context, scale, whole_part, frac_part, decimal_places);
768
769
194
                result_column->insert_data(str.data, str.size);
770
194
            }
771
194
        } 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
194
        return Status::OK();
794
194
    }
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE30EE7executeILb0EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m
Line
Count
Source
694
394
                          ColumnPtr decimal_places_col_ptr, size_t input_rows_count) {
695
394
        const auto& arg_column_data_2 =
696
394
                assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data();
697
394
        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
394
        } 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
394
        } 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
394
        } else if (const auto* decimal128_column =
752
394
                           check_and_get_column<ColumnDecimal128V3>(*col_ptr)) {
753
394
            const UInt32 scale = decimal128_column->get_scale();
754
984
            for (size_t i = 0; i < input_rows_count; i++) {
755
590
                int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
756
590
                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
590
                const Int128& frac_part = decimal128_column->get_fractional_part(i);
762
590
                const Int128& whole_part = decimal128_column->get_intergral_part(i);
763
764
590
                StringRef str =
765
590
                        FormatRound::do_format_round<Int128,
766
590
                                                     FormatRound::MAX_FORMAT_LEN_DEC128V3()>(
767
590
                                context, scale, whole_part, frac_part, decimal_places);
768
769
590
                result_column->insert_data(str.data, str.size);
770
590
            }
771
394
        } 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
394
        return Status::OK();
794
394
    }
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EE7executeILb1EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m
Line
Count
Source
694
152
                          ColumnPtr decimal_places_col_ptr, size_t input_rows_count) {
695
152
        const auto& arg_column_data_2 =
696
152
                assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data();
697
152
        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
152
        } 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
152
        } 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
152
        } else if (const auto* decimal128_column =
752
152
                           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
152
        } else if (const auto* decimal256_column =
772
152
                           check_and_get_column<ColumnDecimal256>(*col_ptr)) {
773
152
            const UInt32 scale = decimal256_column->get_scale();
774
304
            for (size_t i = 0; i < input_rows_count; i++) {
775
152
                int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
776
152
                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
152
                const auto frac_part = decimal256_column->get_fractional_part(i);
782
152
                const auto whole_part = decimal256_column->get_intergral_part(i);
783
152
                StringRef str = FormatRound::do_format_round<wide::Int256,
784
152
                                                             FormatRound::MAX_FORMAT_LEN_DEC256()>(
785
152
                        context, scale, whole_part, frac_part, decimal_places);
786
787
152
                result_column->insert_data(str.data, str.size);
788
152
            }
789
152
        } else {
790
0
            return Status::InternalError("Not supported input argument type {}",
791
0
                                         col_ptr->get_name());
792
0
        }
793
152
        return Status::OK();
794
152
    }
_ZN5doris22FormatRoundDecimalImplILNS_13PrimitiveTypeE35EE7executeILb0EEENS_6StatusEPNS_15FunctionContextEPNS_9ColumnStrIjEENS_3COWINS_7IColumnEE13immutable_ptrISB_EESE_m
Line
Count
Source
694
312
                          ColumnPtr decimal_places_col_ptr, size_t input_rows_count) {
695
312
        const auto& arg_column_data_2 =
696
312
                assert_cast<const ColumnInt32*>(decimal_places_col_ptr.get())->get_data();
697
312
        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
312
        } 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
312
        } 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
312
        } else if (const auto* decimal128_column =
752
312
                           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
312
        } else if (const auto* decimal256_column =
772
312
                           check_and_get_column<ColumnDecimal256>(*col_ptr)) {
773
312
            const UInt32 scale = decimal256_column->get_scale();
774
772
            for (size_t i = 0; i < input_rows_count; i++) {
775
460
                int32_t decimal_places = arg_column_data_2[index_check_const<is_const>(i)];
776
460
                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
460
                const auto frac_part = decimal256_column->get_fractional_part(i);
782
460
                const auto whole_part = decimal256_column->get_intergral_part(i);
783
460
                StringRef str = FormatRound::do_format_round<wide::Int256,
784
460
                                                             FormatRound::MAX_FORMAT_LEN_DEC256()>(
785
460
                        context, scale, whole_part, frac_part, decimal_places);
786
787
460
                result_column->insert_data(str.data, str.size);
788
460
            }
789
312
        } else {
790
0
            return Status::InternalError("Not supported input argument type {}",
791
0
                                         col_ptr->get_name());
792
0
        }
793
312
        return Status::OK();
794
312
    }
795
};
796
797
#include "common/compile_check_avoid_end.h"
798
} // namespace doris