You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2021/08/05 12:23:19 UTC

[GitHub] [incubator-doris] caiconghui opened a new pull request #6384: [Optimize] Speed up converting the data of other type to string in mysql_result_writer

caiconghui opened a new pull request #6384:
URL: https://github.com/apache/incubator-doris/pull/6384


   ## Proposed changes
   
   Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue.
   
   ## Types of changes
   
   What types of changes does your code introduce to Doris?
   _Put an `x` in the boxes that apply_
   
   - [ ] Bugfix (non-breaking change which fixes an issue)
   - [ ] New feature (non-breaking change which adds functionality)
   - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
   - [ ] Documentation Update (if none of the other choices apply)
   - [ ] Code refactor (Modify the code structure, format the code, etc...)
   - [x] Optimization. Including functional usability improvements and performance improvements.
   - [ ] Dependency. Such as changes related to third-party components.
   - [ ] Other.
   
   ## Checklist
   
   _Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._
   
   - [ ] I have created an issue on (Fix #ISSUE) and described the bug/feature there in detail
   - [ ] Compiling and unit tests pass locally with my changes
   - [ ] I have added tests that prove my fix is effective or that my feature works
   - [ ] If these changes need document changes, I have updated the document
   - [ ] Any dependent changes have been merged
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...
   


-- 
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


[GitHub] [incubator-doris] caiconghui commented on a change in pull request #6384: [Optimize] Speed up converting the data of other type to string in mysql_result_writer

Posted by GitBox <gi...@apache.org>.
caiconghui commented on a change in pull request #6384:
URL: https://github.com/apache/incubator-doris/pull/6384#discussion_r690105542



##########
File path: be/test/util/CMakeLists.txt
##########
@@ -72,3 +72,7 @@ ADD_BE_TEST(s3_uri_test)
 ADD_BE_TEST(s3_storage_backend_test)
 ADD_BE_TEST(broker_storage_backend_test)
 ADD_BE_TEST(sort_heap_test)
+ADD_BE_TEST(date_func_test)
+
+target_link_libraries(Test_util Common Util Gutil ${Boost_LIBRARIES} glog gflags fmt protobuf)

Review comment:
       actually I have no idea why should add this? without this, it will report some undefined function error in my PR




-- 
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


[GitHub] [incubator-doris] hk53315 commented on pull request #6384: [Optimize] Speed up converting the data of other type to string in mysql_result_writer

Posted by GitBox <gi...@apache.org>.
hk53315 commented on pull request #6384:
URL: https://github.com/apache/incubator-doris/pull/6384#issuecomment-901092794


   Did you do the benchmark ? how much it can improve ?


-- 
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


[GitHub] [incubator-doris] github-actions[bot] commented on pull request #6384: [Optimize] Speed up converting the data of other type to string in mysql_result_writer

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #6384:
URL: https://github.com/apache/incubator-doris/pull/6384#issuecomment-904517956






-- 
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


[GitHub] [incubator-doris] caiconghui commented on a change in pull request #6384: [Optimize] Speed up converting the data of other type to string in mysql_result_writer

Posted by GitBox <gi...@apache.org>.
caiconghui commented on a change in pull request #6384:
URL: https://github.com/apache/incubator-doris/pull/6384#discussion_r690086354



##########
File path: fe/fe-core/src/main/java/org/apache/doris/planner/Planner.java
##########
@@ -101,9 +101,7 @@ private void setResultExprScale(Analyzer analyzer, ArrayList<Expr> outputExprs)
                             }
 
                     if (slotList.contains(slotDesc.getId()) && null != slotDesc.getColumn()) {
-                        // TODO output scale
-                        // int outputScale = slotDesc.getColumn().getType().getScale();
-                        int outputScale = 10;
+                        int outputScale = slotDesc.getColumn().getScale();

Review comment:
       it is only for decimal, if scale < 0,  be will ignore it




-- 
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


[GitHub] [incubator-doris] hk53315 commented on pull request #6384: [Optimize] Speed up converting the data of other type to string in mysql_result_writer

Posted by GitBox <gi...@apache.org>.
hk53315 commented on pull request #6384:
URL: https://github.com/apache/incubator-doris/pull/6384#issuecomment-901092794


   Did you do the benchmark ? how much it can improve ?


-- 
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


[GitHub] [incubator-doris] caiconghui merged pull request #6384: [Optimize] Speed up converting the data of other type to string in mysql_result_writer

Posted by GitBox <gi...@apache.org>.
caiconghui merged pull request #6384:
URL: https://github.com/apache/incubator-doris/pull/6384


   


-- 
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


[GitHub] [incubator-doris] caiconghui commented on a change in pull request #6384: [Optimize] Speed up converting the data of other type to string in mysql_result_writer

Posted by GitBox <gi...@apache.org>.
caiconghui commented on a change in pull request #6384:
URL: https://github.com/apache/incubator-doris/pull/6384#discussion_r690105542



##########
File path: be/test/util/CMakeLists.txt
##########
@@ -72,3 +72,7 @@ ADD_BE_TEST(s3_uri_test)
 ADD_BE_TEST(s3_storage_backend_test)
 ADD_BE_TEST(broker_storage_backend_test)
 ADD_BE_TEST(sort_heap_test)
+ADD_BE_TEST(date_func_test)
+
+target_link_libraries(Test_util Common Util Gutil ${Boost_LIBRARIES} glog gflags fmt protobuf)

Review comment:
       actually I have no idea why should add this? without this, it will report some undefined function error




-- 
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


[GitHub] [incubator-doris] caiconghui commented on a change in pull request #6384: [Optimize] Speed up converting the data of other type to string in mysql_result_writer

Posted by GitBox <gi...@apache.org>.
caiconghui commented on a change in pull request #6384:
URL: https://github.com/apache/incubator-doris/pull/6384#discussion_r690158219



##########
File path: be/test/util/date_func_test.cpp
##########
@@ -0,0 +1,59 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "util/date_func.h"
+#include <gtest/gtest.h>
+#include <iostream>
+
+namespace doris {
+
+class DateFuncTest : public testing::Test {
+public:
+    DateFuncTest() {}
+    virtual ~DateFuncTest() {}
+};
+
+TEST_F(DateFuncTest, convert_string_to_int) {
+    uint64_t result1 = timestamp_from_datetime(std::string("2021-06-08 15:21:18"));
+    ASSERT_EQ(20210608152118, result1);
+
+    uint24_t result2 = timestamp_from_date(std::string("2021-09-08"));
+    ASSERT_EQ(std::string("2021-09-08"), result2.to_string());

Review comment:
       done




-- 
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


[GitHub] [incubator-doris] caiconghui commented on a change in pull request #6384: [Optimize] Speed up converting the data of other type to string in mysql_result_writer

Posted by GitBox <gi...@apache.org>.
caiconghui commented on a change in pull request #6384:
URL: https://github.com/apache/incubator-doris/pull/6384#discussion_r690106418



##########
File path: be/src/util/date_func.cpp
##########
@@ -55,11 +55,55 @@ uint24_t timestamp_from_date(const std::string& date_str) {
 }
 
 std::string time_str_from_double(double time) {

Review comment:
       removed

##########
File path: be/src/util/date_func.cpp
##########
@@ -55,11 +55,55 @@ uint24_t timestamp_from_date(const std::string& date_str) {
 }
 
 std::string time_str_from_double(double time) {
+    std::string result;
+    result.reserve(MAX_TIME_WIDTH);
     if (time < 0) {
         time = -time;
-        return fmt::format("-{:02d}:{:02d}:{:02d}", (int64_t)(time / 60 / 60), ((int64_t)(time / 60)) % 60, ((int64_t)time) % 60);
+        result.push_back('-');
     }
-    return fmt::format("{:02d}:{:02d}:{:02d}", (int64_t)(time / 60 / 60), ((int64_t)(time / 60)) % 60, ((int64_t)time) % 60);
+    int64_t hour = (int64_t)(time / 3600);
+    if (hour >= 100) {
+        auto f = fmt::format_int(hour);
+        result.append(f.data(), f.size());
+    } else {
+        result.push_back((char)('0' + (hour / 10)));
+        result.push_back((char)('0' + (hour % 10)));
+    }
+    result.push_back(':');
+    int32_t minute = ((int32_t)(time / 60)) % 60;
+    result.push_back((char)('0' + (minute / 10)));
+    result.push_back((char)('0' + (minute % 10)));
+    result.push_back(':');
+    int32_t second = ((int32_t)time) % 60;
+    result.push_back((char)('0' + (second / 10)));
+    result.push_back((char)('0' + (second % 10)));
+    return result;
+}
+
+int32_t time_to_buffer_from_double(double time, char* buffer) {

Review comment:
       added




-- 
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


[GitHub] [incubator-doris] caiconghui edited a comment on pull request #6384: [Optimize] Speed up converting the data of other type to string in mysql_result_writer

Posted by GitBox <gi...@apache.org>.
caiconghui edited a comment on pull request #6384:
URL: https://github.com/apache/incubator-doris/pull/6384#issuecomment-901804587


   > Did you do the benchmark ? how much it can improve ?
   
   CREATE TABLE `baseall` (
     `k1` tinyint(4) NULL COMMENT "",
     `k2` smallint(6) NULL COMMENT "",
     `k3` int(11) NULL COMMENT "",
     `k4` bigint(20) NULL COMMENT "",
     `k5` decimal(9, 3) NULL COMMENT "",
     `k6` char(5) NULL COMMENT "",
     `k10` date NULL COMMENT "",
     `k11` datetime NULL COMMENT "",
     `k7` varchar(20) NULL COMMENT "",
     `k8` double NULL COMMENT "",
     `k9` float NULL COMMENT ""
   ) ENGINE=OLAP
   DUPLICATE KEY(`k1`, `k2`, `k3`, `k4`)
   COMMENT "OLAP"
   DISTRIBUTED BY HASH(`k1`) BUCKETS 10
   PROPERTIES (
   "replication_num" = "1",
   "in_memory" = "false",
   "storage_format" = "V2"
   ); 
   
   and insert more than one hundred thousand records,
   the select * from baseall limit 100000;
    the TupleConvertTime reduced from about 350ms to 180ms


-- 
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


[GitHub] [incubator-doris] morningman commented on a change in pull request #6384: [Optimize] Speed up converting the data of other type to string in mysql_result_writer

Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #6384:
URL: https://github.com/apache/incubator-doris/pull/6384#discussion_r690084612



##########
File path: be/test/util/date_func_test.cpp
##########
@@ -0,0 +1,59 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "util/date_func.h"
+#include <gtest/gtest.h>
+#include <iostream>
+
+namespace doris {
+
+class DateFuncTest : public testing::Test {
+public:
+    DateFuncTest() {}
+    virtual ~DateFuncTest() {}
+};
+
+TEST_F(DateFuncTest, convert_string_to_int) {
+    uint64_t result1 = timestamp_from_datetime(std::string("2021-06-08 15:21:18"));
+    ASSERT_EQ(20210608152118, result1);
+
+    uint24_t result2 = timestamp_from_date(std::string("2021-09-08"));
+    ASSERT_EQ(std::string("2021-09-08"), result2.to_string());

Review comment:
       also need some abnormal test




-- 
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


[GitHub] [incubator-doris] caiconghui commented on a change in pull request #6384: [Optimize] Speed up converting the data of other type to string in mysql_result_writer

Posted by GitBox <gi...@apache.org>.
caiconghui commented on a change in pull request #6384:
URL: https://github.com/apache/incubator-doris/pull/6384#discussion_r690115540



##########
File path: be/src/runtime/decimalv2_value.cpp
##########
@@ -354,50 +354,86 @@ int DecimalV2Value::parse_from_str(const char* decimal_str, int32_t length) {
     return error;
 }
 
-std::string DecimalV2Value::to_string(int round_scale) const {
-    if (_value == 0) return std::string(1, '0');
-
-    int last_char_idx = PRECISION + 2 + (_value < 0);
-    std::string str = std::string(last_char_idx, '0');
-
-    int128_t remaining_value = _value;
-    int first_digit_idx = 0;
-    if (_value < 0) {
-        remaining_value = -_value;
-        first_digit_idx = 1;
+std::string DecimalV2Value::to_string(int scale) const {
+    int64_t int_val = int_value();
+    int32_t frac_val = abs(frac_value());
+    if (scale < 0 || scale > SCALE) {
+        if (frac_val == 0) {
+            scale = 0;
+        } else {
+            scale = SCALE;
+            while (frac_val != 0 && frac_val % 10 == 0) {
+                frac_val = frac_val / 10;
+                scale--;
+            }
+        }
+    } else {
+        frac_val = frac_val / SCALE_TRIM_ARRAY[scale];
     }
-
-    int remaining_scale = SCALE;
-    do {
-        str[--last_char_idx] = (remaining_value % 10) + '0';
-        remaining_value /= 10;
-    } while (--remaining_scale > 0);
-    str[--last_char_idx] = '.';
-
-    do {
-        str[--last_char_idx] = (remaining_value % 10) + '0';
-        remaining_value /= 10;
-        if (remaining_value == 0) {
-            if (last_char_idx > first_digit_idx) str.erase(0, last_char_idx - first_digit_idx);
-            break;
+    auto f_int = fmt::format_int(int_val);
+    if (scale == 0) {
+        return f_int.str();
+    }
+    std::string str;
+    if (_value < 0 && int_val == 0 && frac_val != 0) {
+        str.reserve(f_int.size() + scale + 2);
+        str.push_back('-');
+    } else {
+        str.reserve(f_int.size() + scale + 1);
+    }
+    str.append(f_int.data(), f_int.size());
+    str.push_back('.');
+    if (frac_val == 0) {
+        str.append(scale, '0');
+    } else {
+        auto f_frac = fmt::format_int(frac_val);
+        if (f_frac.size() < scale) {
+           str.append(scale - f_frac.size(), '0');
         }
-    } while (last_char_idx > first_digit_idx);
-
-    if (_value < 0) str[0] = '-';
+        str.append(f_frac.data(), f_frac.size());
+    }
+    return str;
+}
 
-    // right trim and round
-    int scale = 0;
-    int len = str.size();
-    for (scale = 0; scale < SCALE && scale < len; scale++) {
-        if (str[len - scale - 1] != '0') break;
+int32_t DecimalV2Value::to_buffer(char* buffer, int scale) const {

Review comment:
       done




-- 
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


[GitHub] [incubator-doris] morningman commented on a change in pull request #6384: [Optimize] Speed up converting the data of other type to string in mysql_result_writer

Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #6384:
URL: https://github.com/apache/incubator-doris/pull/6384#discussion_r690071874



##########
File path: be/src/util/date_func.cpp
##########
@@ -55,11 +55,55 @@ uint24_t timestamp_from_date(const std::string& date_str) {
 }
 
 std::string time_str_from_double(double time) {

Review comment:
       This method seems not used?

##########
File path: be/src/runtime/decimalv2_value.cpp
##########
@@ -354,50 +354,86 @@ int DecimalV2Value::parse_from_str(const char* decimal_str, int32_t length) {
     return error;
 }
 
-std::string DecimalV2Value::to_string(int round_scale) const {
-    if (_value == 0) return std::string(1, '0');
-
-    int last_char_idx = PRECISION + 2 + (_value < 0);
-    std::string str = std::string(last_char_idx, '0');
-
-    int128_t remaining_value = _value;
-    int first_digit_idx = 0;
-    if (_value < 0) {
-        remaining_value = -_value;
-        first_digit_idx = 1;
+std::string DecimalV2Value::to_string(int scale) const {
+    int64_t int_val = int_value();
+    int32_t frac_val = abs(frac_value());
+    if (scale < 0 || scale > SCALE) {
+        if (frac_val == 0) {
+            scale = 0;
+        } else {
+            scale = SCALE;
+            while (frac_val != 0 && frac_val % 10 == 0) {
+                frac_val = frac_val / 10;
+                scale--;
+            }
+        }
+    } else {
+        frac_val = frac_val / SCALE_TRIM_ARRAY[scale];
     }
-
-    int remaining_scale = SCALE;
-    do {
-        str[--last_char_idx] = (remaining_value % 10) + '0';
-        remaining_value /= 10;
-    } while (--remaining_scale > 0);
-    str[--last_char_idx] = '.';
-
-    do {
-        str[--last_char_idx] = (remaining_value % 10) + '0';
-        remaining_value /= 10;
-        if (remaining_value == 0) {
-            if (last_char_idx > first_digit_idx) str.erase(0, last_char_idx - first_digit_idx);
-            break;
+    auto f_int = fmt::format_int(int_val);
+    if (scale == 0) {
+        return f_int.str();
+    }
+    std::string str;
+    if (_value < 0 && int_val == 0 && frac_val != 0) {
+        str.reserve(f_int.size() + scale + 2);
+        str.push_back('-');
+    } else {
+        str.reserve(f_int.size() + scale + 1);
+    }
+    str.append(f_int.data(), f_int.size());
+    str.push_back('.');
+    if (frac_val == 0) {
+        str.append(scale, '0');
+    } else {
+        auto f_frac = fmt::format_int(frac_val);
+        if (f_frac.size() < scale) {
+           str.append(scale - f_frac.size(), '0');
         }
-    } while (last_char_idx > first_digit_idx);
-
-    if (_value < 0) str[0] = '-';
+        str.append(f_frac.data(), f_frac.size());
+    }
+    return str;
+}
 
-    // right trim and round
-    int scale = 0;
-    int len = str.size();
-    for (scale = 0; scale < SCALE && scale < len; scale++) {
-        if (str[len - scale - 1] != '0') break;
+int32_t DecimalV2Value::to_buffer(char* buffer, int scale) const {

Review comment:
       This function needs to be fully tested with unit test

##########
File path: be/src/util/date_func.cpp
##########
@@ -55,11 +55,55 @@ uint24_t timestamp_from_date(const std::string& date_str) {
 }
 
 std::string time_str_from_double(double time) {
+    std::string result;
+    result.reserve(MAX_TIME_WIDTH);
     if (time < 0) {
         time = -time;
-        return fmt::format("-{:02d}:{:02d}:{:02d}", (int64_t)(time / 60 / 60), ((int64_t)(time / 60)) % 60, ((int64_t)time) % 60);
+        result.push_back('-');
     }
-    return fmt::format("{:02d}:{:02d}:{:02d}", (int64_t)(time / 60 / 60), ((int64_t)(time / 60)) % 60, ((int64_t)time) % 60);
+    int64_t hour = (int64_t)(time / 3600);
+    if (hour >= 100) {
+        auto f = fmt::format_int(hour);
+        result.append(f.data(), f.size());
+    } else {
+        result.push_back((char)('0' + (hour / 10)));
+        result.push_back((char)('0' + (hour % 10)));
+    }
+    result.push_back(':');
+    int32_t minute = ((int32_t)(time / 60)) % 60;
+    result.push_back((char)('0' + (minute / 10)));
+    result.push_back((char)('0' + (minute % 10)));
+    result.push_back(':');
+    int32_t second = ((int32_t)time) % 60;
+    result.push_back((char)('0' + (second / 10)));
+    result.push_back((char)('0' + (second % 10)));
+    return result;
+}
+
+int32_t time_to_buffer_from_double(double time, char* buffer) {

Review comment:
       need tests

##########
File path: be/test/util/CMakeLists.txt
##########
@@ -72,3 +72,7 @@ ADD_BE_TEST(s3_uri_test)
 ADD_BE_TEST(s3_storage_backend_test)
 ADD_BE_TEST(broker_storage_backend_test)
 ADD_BE_TEST(sort_heap_test)
+ADD_BE_TEST(date_func_test)
+
+target_link_libraries(Test_util Common Util Gutil ${Boost_LIBRARIES} glog gflags fmt protobuf)

Review comment:
       Why adding this? Add comment to explain.

##########
File path: fe/fe-core/src/main/java/org/apache/doris/planner/Planner.java
##########
@@ -101,9 +101,7 @@ private void setResultExprScale(Analyzer analyzer, ArrayList<Expr> outputExprs)
                             }
 
                     if (slotList.contains(slotDesc.getId()) && null != slotDesc.getColumn()) {
-                        // TODO output scale
-                        // int outputScale = slotDesc.getColumn().getType().getScale();
-                        int outputScale = 10;
+                        int outputScale = slotDesc.getColumn().getScale();

Review comment:
       Are you sure the scale is always >= 0?




-- 
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


[GitHub] [incubator-doris] caiconghui commented on pull request #6384: [Optimize] Speed up converting the data of other type to string in mysql_result_writer

Posted by GitBox <gi...@apache.org>.
caiconghui commented on pull request #6384:
URL: https://github.com/apache/incubator-doris/pull/6384#issuecomment-901804587


   > Did you do the benchmark ? how much it can improve ?
   
   CREATE TABLE `baseall` (
     `k1` tinyint(4) NULL COMMENT "",
     `k2` smallint(6) NULL COMMENT "",
     `k3` int(11) NULL COMMENT "",
     `k4` bigint(20) NULL COMMENT "",
     `k5` decimal(9, 3) NULL COMMENT "",
     `k6` char(5) NULL COMMENT "",
     `k10` date NULL COMMENT "",
     `k11` datetime NULL COMMENT "",
     `k7` varchar(20) NULL COMMENT "",
     `k8` double NULL COMMENT "",
     `k9` float NULL COMMENT ""
   ) ENGINE=OLAP
   DUPLICATE KEY(`k1`, `k2`, `k3`, `k4`)
   COMMENT "OLAP"
   DISTRIBUTED BY HASH(`k1`) BUCKETS 10
   PROPERTIES (
   "replication_num" = "1",
   "in_memory" = "false",
   "storage_format" = "V2"
   ); 
   
   and insert more than one hundred thousand record, the TupleConvertTime reduced from about 350ms to 180ms


-- 
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


[GitHub] [incubator-doris] morningman commented on pull request #6384: [Optimize] Speed up converting the data of other type to string in mysql_result_writer

Posted by GitBox <gi...@apache.org>.
morningman commented on pull request #6384:
URL: https://github.com/apache/incubator-doris/pull/6384#issuecomment-894667765


   ut failed at `test/util/tdigest_test`


-- 
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