Skip to content

Commit aa81bd7

Browse files
committed
Another try
1 parent 74e0d21 commit aa81bd7

File tree

4 files changed

+25
-31
lines changed

4 files changed

+25
-31
lines changed

include/sparrow_ipc/flatbuffer_utils.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ namespace sparrow_ipc
200200
{
201201
std::vector<org::apache::arrow::flatbuf::Buffer> buffers;
202202
int64_t offset = 0;
203-
for (const auto& column : record_batch.columns())
203+
for (size_t i = 0; i < record_batch.nb_columns(); ++i)
204204
{
205+
const auto& column = record_batch.get_column(i);
205206
const auto& arrow_proxy = sparrow::detail::array_access::get_arrow_proxy(column);
206207
fill_buffers_func(arrow_proxy, buffers, offset);
207208
}

src/flatbuffer_utils.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,13 @@ namespace sparrow_ipc
468468
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<org::apache::arrow::flatbuf::Field>>>
469469
create_children(flatbuffers::FlatBufferBuilder& builder, const sparrow::record_batch& record_batch)
470470
{
471-
const auto& columns = record_batch.columns();
472471
std::vector<flatbuffers::Offset<org::apache::arrow::flatbuf::Field>> children_vec;
473-
children_vec.reserve(columns.size());
472+
children_vec.reserve(record_batch.nb_columns());
474473
const auto names = record_batch.names();
475-
for (size_t i = 0; i < columns.size(); ++i)
474+
for (size_t i = 0; i < record_batch.nb_columns(); ++i)
476475
{
477-
const auto& arrow_schema = sparrow::detail::array_access::get_arrow_proxy(columns[i]).schema();
476+
const auto& column = record_batch.get_column(i);
477+
const auto& arrow_schema = sparrow::detail::array_access::get_arrow_proxy(column).schema();
478478
flatbuffers::Offset<org::apache::arrow::flatbuf::Field> field = create_field(
479479
builder,
480480
arrow_schema,
@@ -523,9 +523,10 @@ namespace sparrow_ipc
523523
create_fieldnodes(const sparrow::record_batch& record_batch)
524524
{
525525
std::vector<org::apache::arrow::flatbuf::FieldNode> nodes;
526-
nodes.reserve(record_batch.columns().size());
527-
for (const auto& column : record_batch.columns())
526+
nodes.reserve(record_batch.nb_columns());
527+
for (size_t i = 0; i < record_batch.nb_columns(); ++i)
528528
{
529+
const auto& column = record_batch.get_column(i);
529530
fill_fieldnodes(sparrow::detail::array_access::get_arrow_proxy(column), nodes);
530531
}
531532
return nodes;
@@ -608,16 +609,14 @@ namespace sparrow_ipc
608609
std::optional<CompressionType> compression,
609610
std::optional<std::reference_wrapper<CompressionCache>> cache)
610611
{
611-
return std::accumulate(
612-
record_batch.columns().begin(),
613-
record_batch.columns().end(),
614-
int64_t{0},
615-
[&](int64_t acc, const sparrow::array& arr)
616-
{
617-
const auto& arrow_proxy = sparrow::detail::array_access::get_arrow_proxy(arr);
618-
return acc + calculate_body_size(arrow_proxy, compression, cache);
619-
}
620-
);
612+
int64_t acc = 0;
613+
for (size_t i = 0; i < record_batch.nb_columns(); ++i)
614+
{
615+
const auto& arr = record_batch.get_column(i);
616+
const auto& arrow_proxy = sparrow::detail::array_access::get_arrow_proxy(arr);
617+
acc += calculate_body_size(arrow_proxy, compression, cache);
618+
}
619+
return acc;
621620
}
622621

623622
flatbuffers::FlatBufferBuilder get_record_batch_message_builder(const sparrow::record_batch& record_batch,

src/serialize_utils.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ namespace sparrow_ipc
3838
std::optional<CompressionType> compression,
3939
std::optional<std::reference_wrapper<CompressionCache>> cache)
4040
{
41-
std::for_each(record_batch.columns().begin(), record_batch.columns().end(), [&](const auto& column) {
41+
for (size_t i = 0; i < record_batch.nb_columns(); ++i)
42+
{
43+
const auto& column = record_batch.get_column(i);
4244
const auto& arrow_proxy = sparrow::detail::array_access::get_arrow_proxy(column);
4345
fill_body(arrow_proxy, stream, compression, cache);
44-
});
46+
}
4547
}
4648

4749
std::size_t calculate_schema_message_size(const sparrow::record_batch& record_batch)
@@ -85,17 +87,9 @@ namespace sparrow_ipc
8587
{
8688
std::vector<sparrow::data_type> dtypes;
8789
dtypes.reserve(rb.nb_columns());
88-
// std::ranges::transform(
89-
// rb.columns(),
90-
// std::back_inserter(dtypes),
91-
// [](const auto& col)
92-
// {
93-
// return col.data_type();
94-
// }
95-
// );
96-
for (const auto& col : rb.columns())
90+
for (size_t i = 0; i < rb.nb_columns(); ++i)
9791
{
98-
dtypes.push_back(col.data_type());
92+
dtypes.push_back(rb.get_column(i).data_type());
9993
}
10094
return dtypes;
10195
}

src/serializer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ namespace sparrow_ipc
2323
{
2424
std::vector<sparrow::data_type> dtypes;
2525
dtypes.reserve(rb.nb_columns());
26-
for (const auto& col : rb.columns())
26+
for (size_t i = 0; i < rb.nb_columns(); ++i)
2727
{
28-
dtypes.push_back(col.data_type());
28+
dtypes.push_back(rb.get_column(i).data_type());
2929
}
3030
return dtypes;
3131
}

0 commit comments

Comments
 (0)