sparrow 0.9.0
Loading...
Searching...
No Matches
sparrow::sparse_union_array Class Reference

Sparse union array implementation without offset buffer. More...

#include <union_array.hpp>

Inheritance diagram for sparrow::sparse_union_array:
[legend]
Collaboration diagram for sparrow::sparse_union_array:
[legend]

Public Types

using base_type = union_array_crtp_base<sparse_union_array>
 
using type_id_buffer_type = typename base_type::type_id_buffer_type
 
- Public Types inherited from sparrow::union_array_crtp_base< sparse_union_array >
using self_type
 
using derived_type
 
using inner_value_type
 
using value_type
 
using const_reference
 
using functor_type
 
using const_functor_type
 
using iterator
 
using const_iterator
 
using const_reverse_iterator
 
using size_type
 
using type_id_buffer_type
 

Public Member Functions

template<class... Args>
requires (mpl::excludes_copy_and_move_ctor_v<sparse_union_array, Args...>)
 sparse_union_array (Args &&... args)
 Generic constructor for creating sparse union arrays.
 
SPARROW_API sparse_union_array (arrow_proxy proxy)
 Constructs sparse union array from Arrow proxy.
 
- Public Member Functions inherited from sparrow::union_array_crtp_base< sparse_union_array >
constexpr std::optional< std::string_view > name () const
 Gets the optional name of the union array.
 
SPARROW_CONSTEXPR_CLANG_17 std::optional< key_value_viewmetadata () const
 Gets the metadata associated with the union array.
 
SPARROW_CONSTEXPR_CLANG_17 value_type at (size_type i) const
 Gets element at specified position with bounds checking.
 
SPARROW_CONSTEXPR_CLANG_17 value_type operator[] (size_type i) const
 Gets element at specified position without bounds checking.
 
SPARROW_CONSTEXPR_CLANG_17 value_type operator[] (size_type i)
 Gets mutable element at specified position.
 
SPARROW_CONSTEXPR_CLANG_17 value_type front () const
 Gets reference to the first element.
 
SPARROW_CONSTEXPR_CLANG_17 value_type back () const
 Gets reference to the last element.
 
constexpr bool empty () const
 Checks if the union array is empty.
 
constexpr size_type size () const
 Gets the number of elements in the union array.
 
constexpr iterator begin ()
 Gets iterator to the beginning of the array.
 
constexpr iterator end ()
 Gets iterator to the end of the array.
 
constexpr const_iterator begin () const
 Gets const iterator to the beginning of the array.
 
constexpr const_iterator end () const
 Gets const iterator to the end of the array.
 
constexpr const_iterator cbegin () const
 Gets const iterator to the beginning of the array.
 
constexpr const_iterator cend () const
 Gets const iterator to the end of the array.
 
constexpr const_reverse_iterator rbegin () const
 Gets reverse iterator to the beginning of reversed array.
 
constexpr const_reverse_iterator rend () const
 Gets reverse iterator to the end of reversed array.
 
constexpr const_reverse_iterator crbegin () const
 Gets const reverse iterator to the beginning of reversed array.
 
constexpr const_reverse_iterator crend () const
 Gets const reverse iterator to the end of reversed array.
 
constexpr void zero_null_values (const inner_value_type &value)
 Sets all null values to the specified value.
 
constexpr auto type_id_map_from_child_to_type_id (const std::optional< R > &child_index_to_type_id) -> type_id_map
 
constexpr std::optional< std::string_view > name () const
 Gets the optional name of the union array.
 
SPARROW_CONSTEXPR_CLANG_17 std::optional< key_value_viewmetadata () const
 Gets the metadata associated with the union array.
 
SPARROW_CONSTEXPR_CLANG_17 value_type at (size_type i) const
 Gets element at specified position with bounds checking.
 
SPARROW_CONSTEXPR_CLANG_17 value_type operator[] (size_type i) const
 Gets element at specified position without bounds checking.
 
SPARROW_CONSTEXPR_CLANG_17 value_type operator[] (size_type i)
 Gets mutable element at specified position.
 
SPARROW_CONSTEXPR_CLANG_17 value_type front () const
 Gets reference to the first element.
 
SPARROW_CONSTEXPR_CLANG_17 value_type back () const
 Gets reference to the last element.
 
constexpr bool empty () const
 Checks if the union array is empty.
 
constexpr size_type size () const
 Gets the number of elements in the union array.
 
constexpr iterator begin ()
 Gets iterator to the beginning of the array.
 
constexpr const_iterator begin () const
 Gets const iterator to the beginning of the array.
 
constexpr iterator end ()
 Gets iterator to the end of the array.
 
constexpr const_iterator end () const
 Gets const iterator to the end of the array.
 
constexpr const_iterator cbegin () const
 Gets const iterator to the beginning of the array.
 
constexpr const_iterator cend () const
 Gets const iterator to the end of the array.
 
constexpr const_reverse_iterator rbegin () const
 Gets reverse iterator to the beginning of reversed array.
 
constexpr const_reverse_iterator rend () const
 Gets reverse iterator to the end of reversed array.
 
constexpr const_reverse_iterator crbegin () const
 Gets const reverse iterator to the beginning of reversed array.
 
constexpr const_reverse_iterator crend () const
 Gets const reverse iterator to the end of reversed array.
 
constexpr void zero_null_values (const inner_value_type &value)
 Sets all null values to the specified value.
 
constexpr auto type_id_map_from_child_to_type_id (const std::optional< R > &child_index_to_type_id) -> type_id_map
 

Friends

class union_array_crtp_base< sparse_union_array >
 

Additional Inherited Members

- Protected Types inherited from sparrow::union_array_crtp_base< sparse_union_array >
using type_id_map
 
using children_type
 
- Protected Types inherited from sparrow::crtp_base< D >
using derived_type = D
 
- Protected Member Functions inherited from sparrow::union_array_crtp_base< sparse_union_array >
constexpr children_type make_children (arrow_proxy &proxy)
 Creates child array wrappers from Arrow proxy.
 
 union_array_crtp_base (arrow_proxy proxy)
 Protected constructor from Arrow proxy.
 
constexpr union_array_crtp_base (const self_type &rhs)
 Copy constructor.
 
constexpr self_typeoperator= (const self_type &rhs)
 Copy assignment operator.
 
constexpr union_array_crtp_base (self_type &&rhs)=default
 
constexpr self_typeoperator= (self_type &&rhs)=default
 
constexpr arrow_proxyget_arrow_proxy ()
 Gets mutable reference to the Arrow proxy.
 
constexpr const arrow_proxyget_arrow_proxy () const
 Gets const reference to the Arrow proxy.
 
constexpr children_type make_children (arrow_proxy &proxy)
 Creates child array wrappers from Arrow proxy.
 
 union_array_crtp_base (arrow_proxy proxy)
 Protected constructor from Arrow proxy.
 
constexpr union_array_crtp_base (const self_type &rhs)
 Copy constructor.
 
constexpr union_array_crtp_base (self_type &&rhs)=default
 
constexpr self_typeoperator= (const self_type &rhs)
 Copy assignment operator.
 
constexpr self_typeoperator= (self_type &&rhs)=default
 
constexpr arrow_proxyget_arrow_proxy ()
 Gets mutable reference to the Arrow proxy.
 
constexpr const arrow_proxyget_arrow_proxy () const
 Gets const reference to the Arrow proxy.
 
- Protected Member Functions inherited from sparrow::crtp_base< D >
constexpr derived_typederived_cast ()
 
constexpr const derived_typederived_cast () const
 
- Static Protected Member Functions inherited from sparrow::union_array_crtp_base< sparse_union_array >
static constexpr type_id_map parse_type_id_map (std::string_view format_string)
 Parses type ID mapping from Arrow format string.
 
static constexpr type_id_map type_id_map_from_child_to_type_id (const std::optional< R > &child_index_to_type_id)
 Creates type ID mapping from child index to type ID mapping.
 
static constexpr std::string make_format_string (bool dense, std::size_t n, const std::optional< R > &child_index_to_type_id)
 Creates Arrow format string for union arrays.
 
static constexpr type_id_map parse_type_id_map (std::string_view format_string)
 Parses type ID mapping from Arrow format string.
 
static constexpr type_id_map type_id_map_from_child_to_type_id (const std::optional< R > &child_index_to_type_id)
 Creates type ID mapping from child index to type ID mapping.
 
static constexpr std::string make_format_string (bool dense, std::size_t n, const std::optional< R > &child_index_to_type_id)
 Creates Arrow format string for union arrays.
 
- Protected Attributes inherited from sparrow::union_array_crtp_base< sparse_union_array >
arrow_proxy m_proxy
 Internal Arrow proxy.
 
const std::uint8_t * p_type_ids
 Pointer to type ID buffer.
 
children_type m_children
 Child array wrappers.
 
std::array< std::uint8_t, TYPE_ID_MAP_SIZEm_type_id_map
 Type ID to child index mapping.
 
arrow_proxy m_proxy
 Internal Arrow proxy.
 
const std::uint8_t * p_type_ids
 Pointer to type ID buffer.
 
children_type m_children
 Child array wrappers.
 
std::array< std::uint8_t, TYPE_ID_MAP_SIZEm_type_id_map
 Type ID to child index mapping.
 
- Static Protected Attributes inherited from sparrow::union_array_crtp_base< sparse_union_array >
static constexpr size_t TYPE_ID_MAP_SIZE
 
static constexpr size_t TYPE_ID_MAP_SIZE
 

Detailed Description

Sparse union array implementation without offset buffer.

Sparse union arrays do not store an offset buffer. Instead, all child arrays have the same length as the union array, and each element directly corresponds to the same position in its child array. This is simpler but less memory efficient when union elements are sparse.

Memory layout:

  • Type ID buffer: Maps each element to child array type
  • Child arrays: All have the same length as the union array

Related Apache Arrow specification: https://arrow.apache.org/docs/dev/format/Columnar.html#sparse-union

Postcondition
Maintains Arrow sparse union format compatibility ("+us:")
All child arrays have the same length as the union array
Provides simpler access pattern at the cost of memory efficiency
//Create sparse union with int and string children
std::vector<array> children = {int_array, string_array}; // same length as union
type_id_buffer_type type_ids = {0, 1, 0, 1}; // alternating types
sparse_union_array union_arr(std::move(children),
std::move(type_ids));
void sparse_union_array()
typename base_type::type_id_buffer_type type_id_buffer_type
string_array_impl< std::int32_t > string_array
Type alias for variable-size string arrays with 32-bit offsets.

Definition at line 803 of file union_array.hpp.

Member Typedef Documentation

◆ base_type

◆ type_id_buffer_type

using sparrow::sparse_union_array::type_id_buffer_type = typename base_type::type_id_buffer_type

Definition at line 808 of file union_array.hpp.

Constructor & Destructor Documentation

◆ sparse_union_array() [1/2]

template<class... Args>
requires (mpl::excludes_copy_and_move_ctor_v<sparse_union_array, Args...>)
sparrow::sparse_union_array::sparse_union_array ( Args &&... args)
inlineexplicit

Generic constructor for creating sparse union arrays.

Creates a sparse union array from various input combinations including child arrays, type IDs, and optional type mapping.

Template Parameters
ArgsParameter pack for constructor arguments
Parameters
argsConstructor arguments (children, type_ids, etc.)
Precondition
Args must match one of the create_proxy() overload signatures
Args must exclude copy and move constructor signatures
All child arrays must have the same length
Postcondition
Array is created with the specified children and configuration

Definition at line 826 of file union_array.hpp.

Here is the caller graph for this function:

◆ sparse_union_array() [2/2]

SPARROW_API sparrow::sparse_union_array::sparse_union_array ( arrow_proxy proxy)
explicit

Constructs sparse union array from Arrow proxy.

Parameters
proxyArrow proxy containing sparse union array data and schema
Precondition
proxy must contain valid Arrow sparse union array and schema
proxy format must be "+us:..."
proxy must have type ID buffer
All child arrays must have same length as union array
Postcondition
Array is initialized with data from proxy
Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ union_array_crtp_base< sparse_union_array >

friend class union_array_crtp_base< sparse_union_array >
friend

Definition at line 912 of file union_array.hpp.


The documentation for this class was generated from the following file: