AlenkaF commented on code in PR #40359:
URL: https://github.com/apache/arrow/pull/40359#discussion_r1519816688
##########
cpp/src/arrow/record_batch.cc:
##########
@@ -248,49 +248,103 @@ 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);
+
+ // If the column is of the same type than resulting data type
+ if (TypeTraits<DataType>::type_singleton() == batch.column(i)->type()) {
+ for (int i = 0; i < batch.num_columns(); ++i) {
Review Comment:
Also not sure how the compiler is happy about this :D
--
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]