Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion c_glib/arrow-glib/basic-array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,11 @@ garrow_array_get_null_bitmap(GArrowArray *array)

auto arrow_array = garrow_array_get_raw(array);
auto arrow_null_bitmap = arrow_array->null_bitmap();
return garrow_buffer_new_raw(&arrow_null_bitmap);
if (arrow_null_bitmap) {
return garrow_buffer_new_raw(&arrow_null_bitmap);
} else {
return nullptr;
}
}

/**
Expand Down
46 changes: 46 additions & 0 deletions c_glib/arrow-glib/composite-array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,22 @@ garrow_base_list_array_get_value_offsets(GArrowArray *array, gint64 *n_offsets)
return arrow_list_array->raw_value_offsets();
};

template <typename LIST_ARRAY_CLASS>
GArrowBuffer *
garrow_base_list_array_get_value_offsets_buffer(GArrowArray *array)
{
GArrowBuffer *buffer = nullptr;
g_object_get(array, "buffer1", &buffer, nullptr);
if (buffer) {
return buffer;
}

auto arrow_array = garrow_array_get_raw(array);
auto arrow_list_array = std::static_pointer_cast<LIST_ARRAY_CLASS>(arrow_array);
auto arrow_buffer = arrow_list_array->value_offsets();
return garrow_buffer_new_raw(&arrow_buffer);
};

G_BEGIN_DECLS

static void
Expand Down Expand Up @@ -385,6 +401,21 @@ garrow_list_array_get_value_offsets(GArrowListArray *array, gint64 *n_offsets)
n_offsets);
}

/**
* garrow_list_array_get_value_offsets_buffer:
* @array: A #GArrowListArray.
*
* Returns: (transfer full) (nullable): The value offsets buffer.
*
* Since: 24.0.0
*/
GArrowBuffer *
garrow_list_array_get_value_offsets_buffer(GArrowListArray *array)
{
return garrow_base_list_array_get_value_offsets_buffer<arrow::ListArray>(
GARROW_ARRAY(array));
}

typedef struct GArrowLargeListArrayPrivate_
{
GArrowArray *raw_values;
Expand Down Expand Up @@ -602,6 +633,21 @@ garrow_large_list_array_get_value_offsets(GArrowLargeListArray *array, gint64 *n
return reinterpret_cast<const gint64 *>(value_offsets);
}

/**
* garrow_large_list_array_get_value_offsets_buffer:
* @array: A #GArrowLargeListArray.
*
* Returns: (transfer full) (nullable): The value offsets buffer.
*
* Since: 24.0.0
*/
GArrowBuffer *
garrow_large_list_array_get_value_offsets_buffer(GArrowLargeListArray *array)
{
return garrow_base_list_array_get_value_offsets_buffer<arrow::LargeListArray>(
GARROW_ARRAY(array));
}

typedef struct GArrowFixedSizeListArrayPrivate_
{
GArrowArray *raw_values;
Expand Down
8 changes: 8 additions & 0 deletions c_glib/arrow-glib/composite-array.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ GARROW_AVAILABLE_IN_2_0
const gint32 *
garrow_list_array_get_value_offsets(GArrowListArray *array, gint64 *n_offsets);

GARROW_AVAILABLE_IN_24_0
GArrowBuffer *
garrow_list_array_get_value_offsets_buffer(GArrowListArray *array);

#define GARROW_TYPE_LARGE_LIST_ARRAY (garrow_large_list_array_get_type())
GARROW_AVAILABLE_IN_0_16
G_DECLARE_DERIVABLE_TYPE(
Expand Down Expand Up @@ -110,6 +114,10 @@ GARROW_AVAILABLE_IN_2_0
const gint64 *
garrow_large_list_array_get_value_offsets(GArrowLargeListArray *array, gint64 *n_offsets);

GARROW_AVAILABLE_IN_24_0
GArrowBuffer *
garrow_large_list_array_get_value_offsets_buffer(GArrowLargeListArray *array);

#define GARROW_TYPE_FIXED_SIZE_LIST_ARRAY (garrow_fixed_size_list_array_get_type())
GARROW_AVAILABLE_IN_23_0
G_DECLARE_DERIVABLE_TYPE(GArrowFixedSizeListArray,
Expand Down
8 changes: 8 additions & 0 deletions ruby/red-arrow-format/lib/arrow-format/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,20 @@ class Decimal256Array < DecimalArray
end

class VariableSizeListArray < Array
attr_reader :child
def initialize(type, size, validity_buffer, offsets_buffer, child)
super(type, size, validity_buffer)
@offsets_buffer = offsets_buffer
@child = child
end

def each_buffer(&block)
return to_enum(__method__) unless block_given?

yield(@validity_buffer)
yield(@offsets_buffer)
end

def to_a
child_values = @child.to_a
values = @offsets_buffer.
Expand Down
4 changes: 3 additions & 1 deletion ruby/red-arrow-format/lib/arrow-format/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def to_flatbuffers
else
fb_field.type = @type.to_flatbuffers
end
if @type.respond_to?(:children)
if @type.respond_to?(:child)
fb_field.children = [@type.child.to_flatbuffers]
elsif @type.respond_to?(:children)
fb_field.children = @type.children.collect(&:to_flatbuffers)
end
# fb_field.custom_metadata = @custom_metadata
Expand Down
4 changes: 3 additions & 1 deletion ruby/red-arrow-format/lib/arrow-format/record-batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def all_columns_enumerator
Enumerator.new do |yielder|
traverse = lambda do |array|
yielder << array
if array.respond_to?(:children)
if array.respond_to?(:child)
traverse.call(array.child)
elsif array.respond_to?(:children)
array.children.each do |child_array|
traverse.call(child_array)
end
Expand Down
9 changes: 8 additions & 1 deletion ruby/red-arrow-format/lib/arrow-format/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,6 @@ def initialize(child)
super()
@child = child
end

end

class ListType < VariableSizeListType
Expand All @@ -689,6 +688,10 @@ def name
def build_array(size, validity_buffer, offsets_buffer, child)
ListArray.new(self, size, validity_buffer, offsets_buffer, child)
end

def to_flatbuffers
FB::List::Data.new
end
end

class LargeListType < VariableSizeListType
Expand All @@ -699,6 +702,10 @@ def name
def build_array(size, validity_buffer, offsets_buffer, child)
LargeListArray.new(self, size, validity_buffer, offsets_buffer, child)
end

def to_flatbuffers
FB::LargeList::Data.new
end
end

class StructType < Type
Expand Down
42 changes: 42 additions & 0 deletions ruby/red-arrow-format/test/test-writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,22 @@ def convert_type(red_arrow_type)
red_arrow_type.scale)
when Arrow::FixedSizeBinaryDataType
ArrowFormat::FixedSizeBinaryType.new(red_arrow_type.byte_width)
when Arrow::ListDataType
ArrowFormat::ListType.new(convert_field(red_arrow_type.field))
when Arrow::LargeListDataType
ArrowFormat::LargeListType.new(convert_field(red_arrow_type.field))
else
raise "Unsupported type: #{red_arrow_type.inspect}"
end
end

def convert_field(red_arrow_field)
ArrowFormat::Field.new(red_arrow_field.name,
convert_type(red_arrow_field.data_type),
red_arrow_field.nullable?,
nil)
end

def convert_buffer(buffer)
return nil if buffer.nil?
IO::Buffer.for(buffer.data.to_s)
Expand All @@ -105,6 +116,11 @@ def convert_array(red_arrow_array)
type.build_array(red_arrow_array.size,
convert_buffer(red_arrow_array.null_bitmap),
convert_buffer(red_arrow_array.data_buffer))
when ArrowFormat::VariableSizeListType
type.build_array(red_arrow_array.size,
convert_buffer(red_arrow_array.null_bitmap),
convert_buffer(red_arrow_array.value_offsets_buffer),
convert_array(red_arrow_array.values_raw))
else
raise "Unsupported array #{red_arrow_array.inspect}"
end
Expand Down Expand Up @@ -635,6 +651,32 @@ def test_write
@values)
end
end

sub_test_case("List") do
def build_array
data_type = Arrow::ListDataType.new(name: "count", type: :int8)
Arrow::ListArray.new(data_type, [[-128, 127], nil, [-1, 0, 1]])
end

def test_write
assert_equal([[-128, 127], nil, [-1, 0, 1]],
@values)
end
end

sub_test_case("LargeList") do
def build_array
data_type = Arrow::LargeListDataType.new(name: "count",
type: :int8)
Arrow::LargeListArray.new(data_type,
[[-128, 127], nil, [-1, 0, 1]])
end

def test_write
assert_equal([[-128, 127], nil, [-1, 0, 1]],
@values)
end
end
end
end
end
Expand Down
Loading