zanmato1984 commented on code in PR #43760:
URL: https://github.com/apache/arrow/pull/43760#discussion_r1734437215


##########
cpp/src/arrow/compute/light_array_internal.cc:
##########
@@ -323,8 +322,7 @@ Status ResizableArrayData::ResizeFixedLengthBuffers(int 
num_rows_new) {
 }
 
 Status ResizableArrayData::ResizeVaryingLengthBuffer() {
-  KeyColumnMetadata column_metadata;
-  column_metadata = ColumnMetadataFromDataType(data_type_).ValueOrDie();
+  KeyColumnMetadata column_metadata = 
ColumnMetadataFromDataType(data_type_).ValueOrDie();

Review Comment:
   > Why not use `ARROW_ASSIGN_OR_RAISE`? We are able to return a `Status` here.
   
   Right, I would suggest the same. Also, there are other occurrences of 
unnecessary `ValueOrDie()` in this file. We'd better clean them all up.
   
   > Also, it seems `ColumnMetadataFromDataType(data_type_)` is being called 
from multiple methods. Why is the result not stored somewhere on the class?
   
   Seems like `ColumnMetadataFromDataType()` is not so trivial - there are a 
bunch of dynamic casts. So yes, it's even better to store it in a private 
member of `ResizableArrayData` - this would save us a lot of 
`s/ValueOrDie()/ARROW_ASSIGN_OR_RAISE` work as well:
   
   ```diff
   -void ResizableArrayData::Init(const std::shared_ptr<DataType>& data_type,
   +Status ResizableArrayData::Init(const std::shared_ptr<DataType>& data_type,
                                 MemoryPool* pool, int log_num_rows_min) {
   +  ARROW_ASSIGN_OR_RAISE(auto metadata_after, 
ColumnMetadataFromDataType(data_type));
   #ifndef NDEBUG
     if (num_rows_allocated_ > 0) {
       ARROW_DCHECK(data_type_ != NULLPTR);
   -    KeyColumnMetadata metadata_before =
   -        ColumnMetadataFromDataType(data_type_).ValueOrDie();
   -    ARROW_DCHECK(metadata_before.is_fixed_length == 
metadata_after.is_fixed_length &&
   -                 metadata_before.fixed_length == 
metadata_after.fixed_length);
   +    ARROW_DCHECK(metadata_.is_fixed_length == 
metadata_after.is_fixed_length &&
   +                 metadata_.fixed_length == metadata_after.fixed_length);
     }
   #endif
   +  metadata_ = metadata_after;
     Clear(/*release_buffers=*/false);
     log_num_rows_min_ = log_num_rows_min;
     data_type_ = data_type;
     pool_ = pool;
   +  return Status::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: [email protected]

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

Reply via email to