[Ruby] Add builder API for red-arrow-format
Describe the enhancement requested
red-arrow-format is a pure Ruby Apache Arrow reader/writer implementation. It can write Apache Arrow IPC file/streaming format data but users need to build Apache Arrow in-memory layout data by themselves. For example, [1, 2, 3].pack("l") + padding for int32 array. It's inconvenient. We should provide builder API for easy to build Apache Arrow in-memory layout data.
Component(s)
Ruby
take
I’d like to work on this. Since ArrowFormat::ArrayBuilder already exists internally and #51214 added schema-aware RecordBatch construction, would exposing a public builder for primitive, string, and null-containing arrays first—while deferring nested, dictionary, and union arrays—match the intended scope?
I want to add support for all types (including nested, dictionary and so on) before we work on this because we may need different API for non primitive types. If we defer these types, we may design inconsistent API.
Could you work on other types before this?
Yes. I’ll map the builder behavior across nested, dictionary, union, and primitive types first, then propose one consistent public API and test matrix here before implementing it.
I mapped the current ArrowFormat type families. I suggest one explicit-type path for every represented type:
ArrowFormat::ArrayBuilder.build(values, type: nil)
ArrowFormat::Array.build(values, type: nil) # delegate
Inference would stay conservative; empty/all-null values and ambiguous Hash values would require type:. Dictionary arrays also need a stateful ArrayBuilder.new(type:) API so memo/delta state can survive multiple finish calls.
Two scope questions before I implement: does “all types” mean the existing ArrowFormat::Type subclasses, or also currently missing IPC types such as run-end encoded and view arrays? And should the stateful dictionary API ship together with the batch API?
I want to use ArrowFormat::Int32Array.new(values) like API instead of ArrowFormat::Array.build(values, type: :int32) like API for explicit type build API because Ruby is an object oriented language.
does “all types” mean the existing ArrowFormat::Type subclasses, or also currently missing IPC types such as run-end encoded and view arrays?
The former.
For example, we don't have ArrowFormat::ListArray.new(type, values) like API for now. We need to work on it as a separated task (separated issue and separated PR) before this.
And should the stateful dictionary API ship together with the batch API?
We can work on them as separated tasks.
Opened and claimed #51262 for the separate ArrowFormat::ListArray.new(type, values) prerequisite. I’ll keep the dictionary state API separate as suggested.