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
1 change: 1 addition & 0 deletions ruby/red-arrow-format/lib/arrow-format/file-reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class FileReader
FOOTER_SIZE_FORMAT = :s32
FOOTER_SIZE_SIZE = IO::Buffer.size_of(FOOTER_SIZE_FORMAT)

attr_reader :schema
def initialize(input)
case input
when IO
Expand Down
53 changes: 53 additions & 0 deletions ruby/red-arrow-format/lib/arrow-format/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

module ArrowFormat
class Type
def to_s
name
end
end

class NullType < Type
Expand Down Expand Up @@ -412,6 +415,10 @@ def initialize(bit_width, unit)
@unit = unit
end

def to_s
"#{super}(#{unit})"
end

def to_flatbuffers
fb_type = FB::Time::Data.new
fb_type.bit_width = @bit_width
Expand Down Expand Up @@ -477,6 +484,12 @@ def build_array(size, validity_buffer, values_buffer)
TimestampArray.new(self, size, validity_buffer, values_buffer)
end

def to_s
options = [@unit]
options << @time_zone if @time_zone
"#{super}(#{options.join(", ")})"
end

def to_flatbuffers
fb_type = FB::Timestamp::Data.new
fb_type.unit = FB::TimeUnit.try_convert(@unit.to_s.upcase)
Expand Down Expand Up @@ -581,6 +594,10 @@ def build_array(size, validity_buffer, values_buffer)
DurationArray.new(self, size, validity_buffer, values_buffer)
end

def to_s
"#{super}(#{@unit})"
end

def to_flatbuffers
fb_type = FB::Duration::Data.new
fb_type.unit = FB::TimeUnit.try_convert(@unit.to_s.upcase)
Expand Down Expand Up @@ -730,6 +747,10 @@ def build_array(size, validity_buffer, values_buffer)
FixedSizeBinaryArray.new(self, size, validity_buffer, values_buffer)
end

def to_s
"#{super}(#{@byte_width})"
end

def to_flatbuffers
fb_type = FB::FixedSizeBinary::Data.new
fb_type.byte_width = @byte_width
Expand All @@ -746,6 +767,10 @@ def initialize(byte_width, precision, scale)
@scale = scale
end

def to_s
"#{name}(#{@precision}, #{@scale})"
end

def to_flatbuffers
fb_type = FB::Decimal::Data.new
fb_type.bit_width = @byte_width * 8
Expand Down Expand Up @@ -789,6 +814,10 @@ def initialize(child)
super()
@child = child
end

def to_s
"#{super}<#{child.name}: #{child.type}>"
end
end

class ListType < VariableSizeListType
Expand Down Expand Up @@ -842,6 +871,13 @@ def build_array(size, validity_buffer, children)
StructArray.new(self, size, validity_buffer, children)
end

def to_s
fields = children.collect do |child|
"#{child.name}: #{child.type}"
end
"#{super}<#{fields.join(", ")}>"
end

def to_flatbuffers
FB::Struct::Data.new
end
Expand Down Expand Up @@ -880,6 +916,11 @@ def build_array(size, validity_buffer, offsets_buffer, child)
MapArray.new(self, size, validity_buffer, offsets_buffer, child)
end

def to_s
key, value, = child.type.children
"#{name}<#{key.type}, #{value.type}>"
end

def to_flatbuffers
FB::Map::Data.new
end
Expand All @@ -900,6 +941,13 @@ def resolve_type_index(type)
@type_indexes[type] ||= @type_ids.index(type)
end

def to_s
children = @children.collect.with_index do |child, i|
"#{child.name}: #{child.type}=#{@type_ids[i]}"
end
"#{super}<#{children.join(", ")}>"
end

def to_flatbuffers
fb_type = FB::Union::Data.new
fb_type.mode = FB::UnionMode.try_convert(@mode.to_s.capitalize)
Expand Down Expand Up @@ -975,5 +1023,10 @@ def build_fb_field(fb_field, field)
fb_field.type = @value_type.to_flatbuffers
fb_field.dictionary = fb_dictionary_encoding
end

def to_s
"#{super}<index=#{@index_type}, value=#{@value_type}, " +
"ordered=#{@ordered}>"
end
end
end
Loading
Loading