sparrow-ipc 0.2.0
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <optional>
5#include <string_view>
6
7#include <sparrow/record_batch.hpp>
8
10
11namespace sparrow_ipc::utils
12{
13 // Aligns a value to the next multiple of 8, as required by the Arrow IPC format for message bodies
14 SPARROW_IPC_API size_t align_to_8(const size_t n);
15
31 template <std::ranges::input_range R>
32 requires std::same_as<std::ranges::range_value_t<R>, sparrow::record_batch>
33 bool check_record_batches_consistency(const R& record_batches)
34 {
35 if (record_batches.empty() || record_batches.size() == 1)
36 {
37 return true;
38 }
39 const sparrow::record_batch& first_rb = record_batches[0];
40 const size_t first_rb_nb_columns = first_rb.nb_columns();
41 for (const sparrow::record_batch& rb : record_batches)
42 {
43 const auto rb_nb_columns = rb.nb_columns();
44 if (rb_nb_columns != first_rb_nb_columns)
45 {
46 return false;
47 }
48 for (size_t col_idx = 0; col_idx < rb.nb_columns(); ++col_idx)
49 {
50 const sparrow::array& arr = rb.get_column(col_idx);
51 const sparrow::array& first_arr = first_rb.get_column(col_idx);
52 const auto arr_data_type = arr.data_type();
53 const auto first_arr_data_type = first_arr.data_type();
54 if (arr_data_type != first_arr_data_type)
55 {
56 return false;
57 }
58 }
59 }
60 return true;
61 }
62
63 // Parse the format string
64 // The format string is expected to be "w:size", "+w:size", "d:precision,scale", etc
65 std::optional<int32_t> parse_format(std::string_view format_str, std::string_view sep);
66 // size_t calculate_output_serialized_size(const sparrow::record_batch& record_batch);
67}
#define SPARROW_IPC_API
Definition config.hpp:12
SPARROW_IPC_API size_t align_to_8(const size_t n)
std::optional< int32_t > parse_format(std::string_view format_str, std::string_view sep)
bool check_record_batches_consistency(const R &record_batches)
Checks if all record batches in a collection have consistent structure.
Definition utils.hpp:33