zeroshade commented on code in PR #37040:
URL: https://github.com/apache/arrow/pull/37040#discussion_r1289206353
##########
cpp/src/arrow/c/bridge_test.cc:
##########
@@ -3552,6 +3580,190 @@ TEST_F(TestArrayRoundtrip, RecordBatch) {
}
}
+class TestDeviceArrayRoundtrip : public ::testing::Test {
+ public:
+ using ArrayFactory = std::function<Result<std::shared_ptr<Array>>()>;
+
+ void SetUp() override { pool_ = default_memory_pool(); }
+
+ static Result<std::shared_ptr<MemoryManager>> DeviceMapper(ArrowDeviceType
type,
+ int64_t id) {
+ if (type != kMyDeviceType) {
+ return Status::NotImplemented("should only be MyDevice");
+ }
+
+ std::shared_ptr<Device> device = std::make_shared<MyDevice>(id);
+ return device->default_memory_manager();
+ }
+
+ static Result<std::shared_ptr<ArrayData>> ToDeviceData(
+ const std::shared_ptr<MemoryManager>& mm, const ArrayData& data) {
+ arrow::BufferVector buffers;
+ for (const auto& buf : data.buffers) {
+ if (buf) {
+ ARROW_ASSIGN_OR_RAISE(auto dest, mm->CopyBuffer(buf, mm));
+ buffers.push_back(dest);
+ } else {
+ buffers.push_back(nullptr);
+ }
+ }
+
+ arrow::ArrayDataVector children;
+ for (const auto& child : data.child_data) {
+ ARROW_ASSIGN_OR_RAISE(auto dest, ToDeviceData(mm, *child));
+ children.push_back(dest);
+ }
+
+ return ArrayData::Make(data.type, data.length, buffers, children,
data.null_count,
+ data.offset);
+ }
+
+ static Result<std::shared_ptr<Array>> ToDevice(const
std::shared_ptr<MemoryManager>& mm,
+ const ArrayData& data) {
+ ARROW_ASSIGN_OR_RAISE(auto result, ToDeviceData(mm, data));
+ return MakeArray(result);
+ }
+
+ static ArrayFactory ToDeviceFactory(const std::shared_ptr<MemoryManager>& mm,
+ ArrayFactory&& factory) {
+ return [&]() -> Result<std::shared_ptr<Array>> {
+ ARROW_ASSIGN_OR_RAISE(auto arr, factory());
+ return ToDevice(mm, *arr->data());
+ };
+ }
+
+ static ArrayFactory JSONArrayFactory(const std::shared_ptr<MemoryManager>&
mm,
+ std::shared_ptr<DataType> type, const
char* json) {
Review Comment:
Yea it's assumed to be null terminated for these tests
--
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]