Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-PLACET committed Oct 17, 2024
1 parent 6623735 commit 78bdbb0
Show file tree
Hide file tree
Showing 8 changed files with 335 additions and 202 deletions.
4 changes: 1 addition & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ set(SPARROW_SRC
${SPARROW_SOURCE_DIR}/arrow_interface/arrow_schema.cpp
${SPARROW_SOURCE_DIR}/list_value.cpp
${SPARROW_SOURCE_DIR}/run_encoded_array.cpp
${SPARROW_SOURCE_DIR}/struct_value.cpp
${SPARROW_SOURCE_DIR}/arrow_array_schema_proxy_bitmap_manipulation.cpp
)
${SPARROW_SOURCE_DIR}/struct_value.cpp)

add_library(sparrow SHARED ${SPARROW_HEADERS} ${SPARROW_SRC})
# TODO: handle static lib, so name and versionning
Expand Down
106 changes: 97 additions & 9 deletions include/sparrow/arrow_array_schema_proxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
#include <string_view>

#include "sparrow/arrow_interface/arrow_array/private_data.hpp"
#include "sparrow/arrow_interface/arrow_array_schema_info_utils.hpp"
#include "sparrow/arrow_interface/arrow_schema/private_data.hpp"
#include "sparrow/buffer/buffer_view.hpp"
#include "sparrow/buffer/dynamic_bitset/non_owning_dynamic_bitset.hpp"
#include "sparrow/c_interface.hpp"
#include "sparrow/config/config.hpp"
#include "sparrow/types/data_type.hpp"


namespace sparrow
{
/**
Expand Down Expand Up @@ -138,7 +140,7 @@ namespace sparrow
* @param null_count The null count to set.
*/
SPARROW_API void set_null_count(int64_t null_count);
[[nodiscard]] SPARROW_API size_t offset() const;
[[nodiscard]] SPARROW_API size_t offset() const;

/**
* Set the offset of the `ArrowArray`.
Expand Down Expand Up @@ -179,21 +181,105 @@ namespace sparrow

/**
* Resize the bitmap buffer of the `ArrowArray`.
* @exception `arrow_proxy_exception` If the `ArrowArray` was not created with sparrow.
* @exception `arrow_proxy_exception` If the array format does not support a validity bitmap.
* @param new_size The new size of the bitmap buffer.
*/
SPARROW_API void resize_bitmap(size_t new_size);

/**
* Insert a value in the bitmap buffer at the given index.
* @exception `arrow_proxy_exception` If the `ArrowArray` was not created with sparrow.
* @exception `arrow_proxy_exception` If the array format does not support a validity bitmap.
* @exception `std::out_of_range` If the index is greater than the length of the bitmap.
* @param index The index where to insert the value. Must be less than the length of the bitmap.
* @param value The value to insert.
* @return The index of the inserted value.
*/
SPARROW_API size_t insert_bitmap(size_t index, bool value);

/**
* Insert several element of the same value in the bitmap buffer at the given index.
* @exception `arrow_proxy_exception` If the `ArrowArray` was not created with sparrow.
* @exception `arrow_proxy_exception` If the array format does not support a validity bitmap.
* @exception `std::out_of_range` If the index is greater than the length of the bitmap.
* @param index The index where to insert the value. Must be less than the length of the bitmap.
* @param value The value to insert.
* @param count The number of times to insert the value.
* @return The index of the first inserted value.
*/
SPARROW_API size_t insert_bitmap(size_t index, bool value, size_t count);

/**
* Insert several elements in the bitmap buffer at the given index.
* @exception `arrow_proxy_exception` If the `ArrowArray` was not created with sparrow.
* @exception `arrow_proxy_exception` If the array format does not support a validity bitmap.
* @exception `std::out_of_range` If the index is greater than the length of the bitmap.
* @param index The index where to insert the values. Must be less than the length of the bitmap.
* @param values The values to insert.
* @return The index of the first inserted value.
*/
SPARROW_API size_t insert_bitmap(size_t index, std::initializer_list<bool> values);

/**
* Insert several elements in the bitmap buffer at the given index.
* @exception `arrow_proxy_exception` If the `ArrowArray` was not created with sparrow.
* @exception `arrow_proxy_exception` If the array format does not support a validity bitmap.
* @exception `std::out_of_range` If the index is greater than the length of the bitmap.
* @param index The index where to insert the values. Must be less than the length of the bitmap.
* @param first The beginning of the range of values to insert.
* @param last The end of the range of values to insert.
* @return The index of the first inserted value.
*/
template <std::input_iterator InputIt>
SPARROW_API size_t insert_bitmap(size_t index, InputIt first, InputIt last);
size_t insert_bitmap(size_t index, InputIt first, InputIt last);

/**
* Insert several elements in the bitmap buffer at the given index.
* @exception `arrow_proxy_exception` If the `ArrowArray` was not created with sparrow.
* @exception `arrow_proxy_exception` If the array format does not support a validity bitmap.
* @exception `std::out_of_range` If the index is greater than the length of the bitmap.
* @param index The index where to insert the values. Must be less than the length of the bitmap.
* @param range The range of values to insert.
* @return The index of the first inserted value.
*/
template <std::ranges::input_range R>
SPARROW_API size_t insert_bitmap(size_t index, const R& range);
size_t insert_bitmap(size_t index, const R& range);

/**
* Erase a value in the bitmap buffer at the given index.
* @exception `arrow_proxy_exception` If the `ArrowArray` was not created with sparrow.
* @exception `arrow_proxy_exception` If the array format does not support a validity bitmap.
* @exception `std::out_of_range` If the index is greater than the length of the bitmap.
* @param index The index of the element to erase. Must be less than the length of the bitmap.
* @return The index of the erased value.
*/
SPARROW_API size_t erase_bitmap(size_t index);

/**
* Erase several elements in the bitmap buffer at the given index.
* @exception `arrow_proxy_exception` If the `ArrowArray` was not created with sparrow.
* @exception `arrow_proxy_exception` If the array format does not support a validity bitmap.
* @exception `std::out_of_range` If the index is greater than the length of the bitmap.
* @param index The index of the first value to erase. Must be less than the length of the bitmap.
* @param count The number of elements to erase.
* @return The index of the first erased value.
*/
SPARROW_API size_t erase_bitmap(size_t index, size_t count);

/**
* Push a value at the end of the bitmap buffer.
* @exception `arrow_proxy_exception` If the `ArrowArray` was not created with sparrow.
* @exception `arrow_proxy_exception` If the array format does not support a validity bitmap.
* @param value The value to push.
*/
SPARROW_API void push_back_bitmap(bool value);

/**
* Pop a value at the end of the bitmap buffer.
* @exception `arrow_proxy_exception` If the `ArrowArray` was not created with sparrow.
* @exception `arrow_proxy_exception` If the array format does not support a validity bitmap.
*/
SPARROW_API void pop_back_bitmap();

/**
Expand Down Expand Up @@ -260,6 +346,9 @@ namespace sparrow
[[nodiscard]] SPARROW_API ArrowSchema& schema();
[[nodiscard]] SPARROW_API const ArrowSchema& schema() const;

[[nodiscard]] [[nodiscard]]SPARROW_API arrow_schema_private_data* get_schema_private_data();
[[nodiscard]] SPARROW_API arrow_array_private_data* get_array_private_data();

SPARROW_API void update_buffers();

private:
Expand All @@ -281,7 +370,7 @@ namespace sparrow

SPARROW_API void resize_children(size_t children_count);

[[nodiscard]] non_owning_dynamic_bitset<uint8_t> get_non_owning_dynamic_bitset();
[[nodiscard]] SPARROW_API non_owning_dynamic_bitset<uint8_t> get_non_owning_dynamic_bitset();

void update_children();
void update_dictionary();
Expand All @@ -293,13 +382,12 @@ namespace sparrow

void validate_array_and_schema() const;

arrow_schema_private_data* get_schema_private_data();
arrow_array_private_data* get_array_private_data();

[[nodiscard]] bool is_arrow_array_valid() const;
[[nodiscard]] bool is_arrow_schema_valid() const;
[[nodiscard]] bool is_proxy_valid() const;

[[nodiscard]] size_t get_null_count() const;

void swap(arrow_proxy& other) noexcept;
};

Expand Down Expand Up @@ -328,7 +416,7 @@ namespace sparrow
}

template <std::input_iterator InputIt>
size_t arrow_proxy::insert_bitmap(size_t index, InputIt first, InputIt last)
inline size_t arrow_proxy::insert_bitmap(size_t index, InputIt first, InputIt last)
{
if (!is_created_with_sparrow())
{
Expand All @@ -344,7 +432,7 @@ namespace sparrow
}

template <std::ranges::input_range R>
size_t arrow_proxy::insert_bitmap(size_t index, const R& range)
inline size_t arrow_proxy::insert_bitmap(size_t index, const R& range)
{
if (!is_created_with_sparrow())
{
Expand Down
58 changes: 0 additions & 58 deletions include/sparrow/arrow_array_schema_proxy_bitmap_manipulation.hpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ namespace sparrow
mpl::unreachable();
}

bool has_bitmap(data_type dt)
constexpr bool has_bitmap(data_type dt)
{
switch (dt)
{
Expand All @@ -258,6 +258,9 @@ namespace sparrow
case data_type::FIXED_SIZE_BINARY:
case data_type::FIXED_WIDTH_BINARY:
case data_type::LARGE_LIST:
case data_type::LIST_VIEW:
case data_type::LARGE_LIST_VIEW:
case data_type::FIXED_SIZED_LIST:
return true;
case data_type::NA:
case data_type::SPARSE_UNION:
Expand Down
Loading

0 comments on commit 78bdbb0

Please sign in to comment.