You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by github-actions on 2023/01/26 05:44:55 UTC

[GitHub] [doris] github-actions[bot] commented on a diff in pull request #16141: [refactor](remove non vec code) remove json functions string functions match functions and some code

github-actions[bot] commented on code in PR #16141:
URL: https://github.com/apache/doris/pull/16141#discussion_r1087455603


##########
be/src/vec/functions/function_string.h:
##########
@@ -1949,6 +1949,45 @@ class FunctionMoneyFormat : public IFunction {
     }
 };
 
+namespace MoneyFormat {
+
+template <typename T, size_t N>
+static StringVal do_money_format(FunctionContext* context, const T int_value,
+                                 const int32_t frac_value = 0) {
+    char local[N];
+    char* p = SimpleItoaWithCommas(int_value, local, sizeof(local));
+    int32_t string_val_len = local + sizeof(local) - p + 3;
+    StringVal result = StringVal::create_temp_string_val(context, string_val_len);
+    memcpy(result.ptr, p, string_val_len - 3);
+    *(result.ptr + string_val_len - 3) = '.';
+    *(result.ptr + string_val_len - 2) = '0' + (frac_value / 10);
+    *(result.ptr + string_val_len - 1) = '0' + (frac_value % 10);
+    return result;
+};
+
+// Note string value must be valid decimal string which contains two digits after the decimal point
+static StringVal do_money_format(FunctionContext* context, const string& value) {
+    bool is_positive = (value[0] != '-');
+    int32_t result_len = value.size() + (value.size() - (is_positive ? 4 : 5)) / 3;
+    StringVal result = StringVal::create_temp_string_val(context, result_len);
+    if (!is_positive) {
+        *result.ptr = '-';
+    }
+    for (int i = value.size() - 4, j = result_len - 4; i >= 0; i = i - 3, j = j - 4) {
+        *(result.ptr + j) = *(value.data() + i);
+        if (i - 1 < 0) break;

Review Comment:
   warning: statement should be inside braces [readability-braces-around-statements]
   
   ```suggestion
           if (i - 1 < 0) { break;
   }
   ```
   



##########
be/src/vec/functions/function_string.h:
##########
@@ -1949,6 +1949,45 @@
     }
 };
 
+namespace MoneyFormat {
+
+template <typename T, size_t N>
+static StringVal do_money_format(FunctionContext* context, const T int_value,
+                                 const int32_t frac_value = 0) {
+    char local[N];
+    char* p = SimpleItoaWithCommas(int_value, local, sizeof(local));
+    int32_t string_val_len = local + sizeof(local) - p + 3;
+    StringVal result = StringVal::create_temp_string_val(context, string_val_len);
+    memcpy(result.ptr, p, string_val_len - 3);
+    *(result.ptr + string_val_len - 3) = '.';
+    *(result.ptr + string_val_len - 2) = '0' + (frac_value / 10);
+    *(result.ptr + string_val_len - 1) = '0' + (frac_value % 10);
+    return result;
+};
+
+// Note string value must be valid decimal string which contains two digits after the decimal point
+static StringVal do_money_format(FunctionContext* context, const string& value) {
+    bool is_positive = (value[0] != '-');
+    int32_t result_len = value.size() + (value.size() - (is_positive ? 4 : 5)) / 3;
+    StringVal result = StringVal::create_temp_string_val(context, result_len);
+    if (!is_positive) {
+        *result.ptr = '-';
+    }
+    for (int i = value.size() - 4, j = result_len - 4; i >= 0; i = i - 3, j = j - 4) {
+        *(result.ptr + j) = *(value.data() + i);
+        if (i - 1 < 0) break;
+        *(result.ptr + j - 1) = *(value.data() + i - 1);
+        if (i - 2 < 0) break;

Review Comment:
   warning: statement should be inside braces [readability-braces-around-statements]
   
   ```suggestion
           if (i - 2 < 0) { break;
   }
   ```
   



##########
be/test/testutil/array_utils.cpp:
##########
@@ -38,19 +37,6 @@ void ArrayUtils::prepare_context(FunctionContext& context, MemPool& mem_pool,
     context.impl()->_pool = new FreePool(&mem_pool);

Review Comment:
   warning: '_pool' is a private member of 'doris::FunctionContextImpl' [clang-diagnostic-error]
   ```cpp
       context.impl()->_pool = new FreePool(&mem_pool);
                       ^
   ```
   **be/src/udf/udf_internal.h:136:** declared private here
   ```cpp
       FreePool* _pool;
                 ^
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org