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/12/06 06:59:00 UTC

[GitHub] [incubator-doris] zuochunwei opened a new pull request #7319: refactor tuple & RowBatch

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


   ## Proposed changes
   
   code refactor: improve code's readability, avoid const_cast
   
   1. make loop simpler and clearer by using range-based loop grammar, it's safer than old loop style
   2. iteration for _row_desc.tuple_descriptors() use index replace index and iterator mixed
   3. use union casting between two types to replace reinterpret, it's more readable
   4. avoid using the same varible name for nested loop
   5. add const keyword for member functions as much as possiable, it's recommended by CppCoreGuidelines
   
   
   ## 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)
   - [x ] Code refactor (Modify the code structure, format the code, etc...)
   - [ ] 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
   - [ x] 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] zuochunwei commented on a change in pull request #7319: [refactor] modify the implements of tuple & RowBatch

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



##########
File path: be/src/runtime/row_batch.cpp
##########
@@ -120,37 +120,39 @@ RowBatch::RowBatch(const RowDescriptor& row_desc, const PRowBatch& input_batch,
         if (offset == -1) {
             _tuple_ptrs[tuple_idx++] = nullptr;
         } else {
-            _tuple_ptrs[tuple_idx++] = reinterpret_cast<Tuple*>(tuple_data + offset);
+            _tuple_ptrs[tuple_idx++] = convert_to<Tuple*>(tuple_data + offset);
         }
     }
 
     // Check whether we have slots that require offset-to-pointer conversion.
     if (!_row_desc.has_varlen_slots()) {
         return;
     }
-    const std::vector<TupleDescriptor*>& tuple_descs = _row_desc.tuple_descriptors();
+
+    const auto& tuple_descs = _row_desc.tuple_descriptors();
 
     // For every unique tuple, convert string offsets contained in tuple data into
     // pointers. Tuples were serialized in the order we are deserializing them in,
     // so the first occurrence of a tuple will always have a higher offset than any tuple
     // we already converted.
     for (int i = 0; i < _num_rows; ++i) {
         TupleRow* row = get_row(i);
-        std::vector<TupleDescriptor*>::const_iterator desc = tuple_descs.begin();
-        for (int j = 0; desc != tuple_descs.end(); ++desc, ++j) {
-            if ((*desc)->string_slots().empty() && (*desc)->collection_slots().empty()) {
+        for (size_t j = 0; j < tuple_descs.size(); ++j) {
+            auto desc = tuple_descs[i];

Review comment:
       OK, 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 #7319: [refactor] modify the implements of tuple & RowBatch

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



##########
File path: be/src/runtime/tuple.cpp
##########
@@ -270,8 +269,9 @@ void Tuple::materialize_exprs(TupleRow* row, const TupleDescriptor& desc,
     memset(this, 0, desc.num_null_bytes());
     // Evaluate the output_slot_exprs and place the results in the tuples.
     int mat_expr_index = 0;
+    auto& slots = desc.slots();
     for (int i = 0; i < desc.slots().size(); ++i) {

Review comment:
       ```suggestion
       for (int i = 0; i < slots.size(); ++i) {
   ```




-- 
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 #7319: [refactor] modify the implements of tuple & RowBatch

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






-- 
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] zuochunwei commented on a change in pull request #7319: [refactor] modify the implements of tuple & RowBatch

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



##########
File path: be/src/runtime/tuple.cpp
##########
@@ -270,8 +269,9 @@ void Tuple::materialize_exprs(TupleRow* row, const TupleDescriptor& desc,
     memset(this, 0, desc.num_null_bytes());
     // Evaluate the output_slot_exprs and place the results in the tuples.
     int mat_expr_index = 0;
+    auto& slots = desc.slots();
     for (int i = 0; i < desc.slots().size(); ++i) {

Review comment:
       ok




-- 
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 merged pull request #7319: [refactor] modify the implements of tuple & RowBatch

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


   


-- 
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 #7319: [refactor] modify the implements of tuple & RowBatch

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



##########
File path: be/src/runtime/row_batch.cpp
##########
@@ -120,37 +120,39 @@ RowBatch::RowBatch(const RowDescriptor& row_desc, const PRowBatch& input_batch,
         if (offset == -1) {
             _tuple_ptrs[tuple_idx++] = nullptr;
         } else {
-            _tuple_ptrs[tuple_idx++] = reinterpret_cast<Tuple*>(tuple_data + offset);
+            _tuple_ptrs[tuple_idx++] = convert_to<Tuple*>(tuple_data + offset);
         }
     }
 
     // Check whether we have slots that require offset-to-pointer conversion.
     if (!_row_desc.has_varlen_slots()) {
         return;
     }
-    const std::vector<TupleDescriptor*>& tuple_descs = _row_desc.tuple_descriptors();
+
+    const auto& tuple_descs = _row_desc.tuple_descriptors();
 
     // For every unique tuple, convert string offsets contained in tuple data into
     // pointers. Tuples were serialized in the order we are deserializing them in,
     // so the first occurrence of a tuple will always have a higher offset than any tuple
     // we already converted.
     for (int i = 0; i < _num_rows; ++i) {
         TupleRow* row = get_row(i);
-        std::vector<TupleDescriptor*>::const_iterator desc = tuple_descs.begin();
-        for (int j = 0; desc != tuple_descs.end(); ++desc, ++j) {
-            if ((*desc)->string_slots().empty() && (*desc)->collection_slots().empty()) {
+        for (size_t j = 0; j < tuple_descs.size(); ++j) {
+            auto desc = tuple_descs[i];

Review comment:
       ```suggestion
               auto desc = tuple_descs[j];
   ```




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