You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "andishgar (via GitHub)" <gi...@apache.org> on 2025/05/25 10:05:41 UTC

[I] [C++][Statistics]: Fix the ownership handling of arrow::ArrayData::statistics in arrow::ArrayData::CopyTo and arrow::ArrayDataCopy [arrow]

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

   ### Describe the bug, including details regarding any error messages, version, and platform.
   
   As discussed [here](https://github.com/apache/arrow/issues/46485#issuecomment-2907631297), the following line should either share or copy arrow::ArrayData::statistics, depending on whether the buffers are copied or viewed.
   
   https://github.com/apache/arrow/blob/8afaf95b38459f97ab12b22ebb7e1913b31025bf/cpp/src/arrow/array/data.cc#L167-L169
   
   ### 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: issues-unsubscribe@arrow.apache.org.apache.org

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


Re: [I] [C++][Statistics] Fix the ownership handling of arrow::ArrayData::statistics in arrow::ArrayData::CopyTo and arrow::ArrayDataViewOrCopy [arrow]

Posted by "thisisnic (via GitHub) via github" <gi...@arrow.apache.org>.
thisisnic commented on issue #46578:
URL: https://github.com/apache/arrow/issues/46578#issuecomment-7285603617

   Thanks for reporting this! I'm just going through older bug issues to see if we can close them out or we need further action.
   
   In #46625, @kou's view was that `ArrayData::CopyTo()` and `ArrayData::ViewOrCopyTo()` can always share `statistics`, since neither changes the data type. That's what the code already does, so I'm closing this as not planned. If there's a case where sharing gives a wrong result, please open a new issue, or please reopen this if I've misinterpreted the comments above and on the closed 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: github-unsubscribe@arrow.apache.org

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


Re: [I] [C++][Statistics]: Fix the ownership handling of arrow::ArrayData::statistics in arrow::ArrayData::CopyTo and arrow::ArrayDataViewOrCopy [arrow]

Posted by "andishgar (via GitHub)" <gi...@apache.org>.
andishgar commented on issue #46578:
URL: https://github.com/apache/arrow/issues/46578#issuecomment-2908723678

   Since it's possible to create an` arrow::Array` from multiple `arrow::Buffer `instances via` arrow::ArrayData`, and each `arrow::Buffer` can have its own memory manager, the behavior of` arrow::ArrayData::ViewOrCopyTo` depends on whether the target const` std::shared_ptr<MemoryManager>& to` is associated with the CPU. A buffer will be either copied or viewed based on whether its memory manager is CPU-tied or not, regardless of whether it uses `arrow::CPUMemoryManager `or `arrow::MyMemoryManager.`
   
   1. Are there any practical examples where an `arrow::Array` contains buffers from different memory managers, or is this scenario purely theoretical?


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [I] [C++][Statistics] Fix the ownership handling of arrow::ArrayData::statistics in arrow::ArrayData::CopyTo and arrow::ArrayDataViewOrCopy [arrow]

Posted by "thisisnic (via GitHub) via issues" <is...@arrow.apache.org>.
thisisnic closed issue #46578: [C++][Statistics] Fix the ownership handling of arrow::ArrayData::statistics in arrow::ArrayData::CopyTo and arrow::ArrayDataViewOrCopy
URL: https://github.com/apache/arrow/issues/46578


-- 
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: issues-unsubscribe@arrow.apache.org

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


Re: [I] [C++][Statistics]: Fix the ownership handling of arrow::ArrayData::statistics in arrow::ArrayData::CopyTo and arrow::ArrayDataViewOrCopy [arrow]

Posted by "andishgar (via GitHub)" <gi...@apache.org>.
andishgar commented on issue #46578:
URL: https://github.com/apache/arrow/issues/46578#issuecomment-2907736993

   @kou 
   I’d like to first implement an initial solution. Then we can discuss, in the relevant pull request, the range of better or more correct approaches that might exist.
   However, if some buffers in the array are viewed while others are copied, should arrow::ArrayData::statistics be copied or shared?


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [I] [C++][Statistics]: Fix the ownership handling of arrow::ArrayData::statistics in arrow::ArrayData::CopyTo and arrow::ArrayDataViewOrCopy [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on issue #46578:
URL: https://github.com/apache/arrow/issues/46578#issuecomment-2908290928

   When does the mixed case happen?


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [I] [C++][Statistics]: Fix the ownership handling of arrow::ArrayData::statistics in arrow::ArrayData::CopyTo and arrow::ArrayDataViewOrCopy [arrow]

Posted by "andishgar (via GitHub)" <gi...@apache.org>.
andishgar commented on issue #46578:
URL: https://github.com/apache/arrow/issues/46578#issuecomment-2908870300

   It's possible to create an arrow::Array from multiple `arrow::Buffer` instances via `arrow::ArrayData`, and each `arrow::Buffer` can have its own memory manager, and device allocation type. the behavior of
   ` arrow::ArrayData::ViewOrCopyTo` depends on the behavior of MemoryManager fo `to `[parameter](https://github.com/apache/arrow/blob/cfff4d5b848ba551959d92c2631c582e8508241e/cpp/src/arrow/array/data.cc#L179-L182) in `arrow::ArrayData::ViewOrCopyTo` and MemoryManager and DeviceAllocationType type of a buffer according to below codes
   
   https://github.com/apache/arrow/blob/cfff4d5b848ba551959d92c2631c582e8508241e/cpp/src/arrow/device.cc#L103-L117
   https://github.com/apache/arrow/blob/cfff4d5b848ba551959d92c2631c582e8508241e/cpp/src/arrow/device.cc#L221-L234.
   1. Are there any practical examples where an `arrow::Array` contains buffers from different memory managers and device allocation type, or is this scenario purely theoretical?


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [I] [C++][Statistics]: Fix the ownership handling of arrow::ArrayData::statistics in arrow::ArrayData::CopyTo and arrow::ArrayDataViewOrCopy [arrow]

Posted by "andishgar (via GitHub)" <gi...@apache.org>.
andishgar commented on issue #46578:
URL: https://github.com/apache/arrow/issues/46578#issuecomment-2915664149

   @kou, the example below demonstrates a practical case where one buffer is viewed and the other is copied (when cpu_memory_manager_ is passed). I will send a pull request soon to clarify this further
   
   ```c++
   TEST_F(TestArrayDataStatisticsViewOrCopyTO, CudaBufferAndCudaBufferPointToCpuMemory) {
     ASSERT_OK_AND_ASSIGN(auto bitmap_buffer, GenerateGPUBitmapBufferPointToCpuMemory(10));
     ASSERT_OK_AND_ASSIGN(auto data_buffer, GenerateGPUtDataBuffer(
                                                {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}));
     auto array_data = ArrayData::Make(int32(), 10, {bitmap_buffer, data_buffer});
     auto statistics = std::make_shared<ArrayStatistics>();
     statistics->max = 10;
     array_data->statistics = statistics;
     array_data->null_count = 4;
     // Why does the assertion below fail?
     // ASSERT_TRUE(is_valid_as_array(array_data));
     {
       // Since it's not possible to get  a host pointer from data_buffer,
       //data_buffer is copied. (bitmap_buffer is viewed)
       ASSERT_OK_AND_ASSIGN(auto copied_array_data,
                            array_data->ViewOrCopyTo(cpu_memory_manager_));
       ASSERT_FALSE(is_statistics_viewed(array_data, copied_array_data));
     }
     {
       // Despite using the same memory manager, data_buffer is still being copied.
       // Should we consider this a bug?
       ASSERT_OK_AND_ASSIGN(auto copied_array_data,
                            array_data->ViewOrCopyTo(cuda_memory_manager_));
       ASSERT_FALSE(is_statistics_viewed(array_data, copied_array_data));
     }
     {
       // Since neither the buffer nor the 'to' memory manager belong to the CPU,
       // the buffers are copied.
       ASSERT_OK_AND_ASSIGN(auto copied_array_data,
                            array_data->ViewOrCopyTo(my_cuda_memory_manager));
       ASSERT_FALSE(is_statistics_viewed(array_data, copied_array_data));
     }
   }
   ``` 


-- 
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: github-unsubscribe@arrow.apache.org

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