43 constexpr size_t n_children = 2;
45 if (!field_desc.
field.children() || field_desc.
field.children()->size() != n_children)
47 throw std::runtime_error(
48 "Run-end encoded array field must have exactly 2 children (run ends and values)"
52 const auto* run_ends_field = field_desc.
field.children()->Get(0);
55 throw std::runtime_error(
"Run-end encoded array field has null run ends child.");
59 if (!nodes || context.
node_index >= nodes->size())
61 throw std::runtime_error(
62 "Run-end encoded array: insufficient FieldNodes. Expected run_ends child node at index "
67 const auto* run_ends_node = nodes->Get(context.
node_index);
70 throw std::runtime_error(
"Run-end encoded array: null run_ends FieldNode.");
73 const int64_t encoded_length = run_ends_node->length();
75 std::optional<std::vector<sparrow::metadata_pair>> run_ends_metadata;
76 if (run_ends_field->custom_metadata())
92 std::move(run_ends_metadata),
99 sparrow::array run_ends_array = array_deserializer::deserialize(
105 const auto* values_field = field_desc.
field.children()->Get(1);
108 throw std::runtime_error(
"Run-end encoded array field has null values child.");
111 std::optional<std::vector<sparrow::metadata_pair>> values_metadata;
112 if (values_field->custom_metadata())
128 std::move(values_metadata),
135 sparrow::array values_array = array_deserializer::deserialize(
140 auto [run_ends_arrow_array, run_ends_arrow_schema] = sparrow::extract_arrow_structures(std::move(run_ends_array));
141 auto [values_arrow_array, values_arrow_schema] = sparrow::extract_arrow_structures(std::move(values_array));
143 auto** schema_children =
new ArrowSchema*[n_children];
144 schema_children[0] =
new ArrowSchema(std::move(run_ends_arrow_schema));
145 schema_children[1] =
new ArrowSchema(std::move(values_arrow_schema));
147 const std::string_view format =
"+r";
158 auto** array_children =
new ArrowArray*[n_children];
159 array_children[0] =
new ArrowArray(std::move(run_ends_arrow_array));
160 array_children[1] =
new ArrowArray(std::move(values_arrow_array));
170 std::vector<arrow_array_private_data::optionally_owned_buffer>{}
173 sparrow::arrow_proxy ap{std::move(array), std::move(schema)};
174 return sparrow::run_end_encoded_array{std::move(ap)};
ArrowSchema make_non_owning_arrow_schema(std::string_view format, std::string_view name, std::optional< M > metadata, std::optional< std::unordered_set< sparrow::ArrowFlag > > flags, size_t children_count, ArrowSchema **children, ArrowSchema *dictionary)
ArrowArray make_arrow_array(int64_t length, int64_t null_count, int64_t offset, size_t children_count, ArrowArray **children, ArrowArray *dictionary, Arg &&private_data_arg)
Encapsulates the context required for deserialization.
std::span< const uint8_t > body
const org::apache::arrow::flatbuf::RecordBatch & record_batch