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


##########
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:
   I got a compiler error if I did what u suggested which can be fixed if I 
change `int64_t i` to `int i` in the proceeding for loop. Not sure what 
approach is better, or if there is anything else I can do. I guess using `i` 
variable in both for loops is not the best practice either.



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