ZhangHuiGui opened a new issue, #38567:
URL: https://github.com/apache/arrow/issues/38567

   ### Describe the enhancement requested
   
   A simple enhancememnt ? 
   Currently we will init the left_output and right_output  FieldRef vector if 
user didn't input them.
   And the schema.fields() size will be used for init the FieldRef vector.
   
   ```c
     if (join_type != JoinType::RIGHT_SEMI && join_type != 
JoinType::RIGHT_ANTI) {
       const FieldVector& left_fields = left_schema.fields();
       left_output.resize(left_fields.size());
       for (size_t i = 0; i < left_fields.size(); ++i) {
         left_output[i] = FieldRef(static_cast<int>(i));
       }
     }
   ```
   
   We don't actually need to construct a FieldVector array, just taking 
schema.fields.size() is enough, so as the right_ouput.
   ```c
   diff --git a/cpp/src/arrow/acero/hash_join_node.cc 
b/cpp/src/arrow/acero/hash_join_node.cc
   index a61791416..b425e5a7c 100644
   --- a/cpp/src/arrow/acero/hash_join_node.cc
   +++ b/cpp/src/arrow/acero/hash_join_node.cc
   @@ -103,18 +103,18 @@ Status HashJoinSchema::Init(JoinType join_type, const 
Schema& left_schema,
                                const std::string& right_field_name_suffix) {
      std::vector<FieldRef> left_output;
      if (join_type != JoinType::RIGHT_SEMI && join_type != 
JoinType::RIGHT_ANTI) {
   -    const FieldVector& left_fields = left_schema.fields();
   -    left_output.resize(left_fields.size());
   -    for (size_t i = 0; i < left_fields.size(); ++i) {
   +    const size_t& left_fields_size = left_schema.fields().size();
   +    left_output.resize(left_fields_size);
   +    for (size_t i = 0; i < left_fields_size; ++i) {
          left_output[i] = FieldRef(static_cast<int>(i));
        }
      }
      // Repeat the same for the right side
      std::vector<FieldRef> right_output;
      if (join_type != JoinType::LEFT_SEMI && join_type != JoinType::LEFT_ANTI) 
{
   -    const FieldVector& right_fields = right_schema.fields();
   -    right_output.resize(right_fields.size());
   -    for (size_t i = 0; i < right_fields.size(); ++i) {
   +    const size_t& right_fields_size = right_schema.fields().size();
   +    right_output.resize(right_fields_size);
   +    for (size_t i = 0; i < right_fields_size; ++i) {
          right_output[i] = FieldRef(static_cast<int>(i));
        }
      }
   
   ```
   
   
   ### Component(s)
   
   C++


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to