jorisvandenbossche commented on code in PR #40359:
URL: https://github.com/apache/arrow/pull/40359#discussion_r1521336406


##########
cpp/src/arrow/record_batch.cc:
##########
@@ -248,49 +248,101 @@ Result<std::shared_ptr<StructArray>> 
RecordBatch::ToStructArray() const {
                                        /*offset=*/0);
 }
 
+#define TYPE_CASE(type)                                                \
+  case Type::type: {                                                   \
+    using T = typename TypeIdTraits<Type::type>::Type;                 \
+    using CType_in = typename TypeTraits<T>::CType;                    \
+    auto* in_values = batch.column(i)->data()->GetValues<CType_in>(1); \
+    for (int64_t i = 0; i < arr.length(); ++i) {                       \
+      *out_values++ = static_cast<CType>(*in_values++);                \
+    }                                                                  \
+    break;                                                             \
+  }
+
 template <typename DataType>
 inline void ConvertColumnsToTensor(const RecordBatch& batch, uint8_t* out) {
   using CType = typename arrow::TypeTraits<DataType>::CType;
   auto* out_values = reinterpret_cast<CType*>(out);
 
-  // Loop through all of the columns
   for (int i = 0; i < batch.num_columns(); ++i) {
-    const auto* in_values = batch.column(i)->data()->GetValues<CType>(1);
-
-    // Copy data of each column
-    memcpy(out_values, in_values, sizeof(CType) * batch.num_rows());
-    out_values += batch.num_rows();
-  }  // End loop through columns
+    const auto& arr = *batch.column(i);

Review Comment:
   This `arr` variable is only used for `arr.length()` in the for loop 
specification. But in other places you use `batch.num_rows()` for the same 
purpose (that should give the sme value, right?)  
   So can probably remove `arr`, and could maybe also define a single 
`num_rows` variable before the loop



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