class DuckDB::ArrowArrayStream
The ArrowArrayStream class represents an exported Arrow C stream of a query result (Arrow C Data Interface). It is created by DuckDB::Result#arrow_c_stream and cannot be instantiated directly.
The object satisfies the Ruby Arrow C stream protocol: arrow_c_stream returns self and to_i returns the address of the underlying struct ArrowArrayStream, so it can be consumed by ruby-polars, red-arrow and other Arrow consumers:
result = con.query('SELECT * FROM users') # ruby-polars df = Polars::DataFrame.new(result) # red-arrow reader = Arrow::RecordBatchReader.import(result.arrow_c_stream.to_i)
The consumer takes ownership of the stream’s contents; a result can be exported only once.
- EXPERIMENTAL
-
This API is built on DuckDB’s unstable Arrow C API and
may change in any minor release.
Public Class Methods
Source
# File lib/duckdb/arrow_array_stream.rb, line 28 def new raise DuckDB::Error, 'DuckDB::ArrowArrayStream cannot be instantiated directly. Use DuckDB::Result#arrow_c_stream.' end
Public Instance Methods
Source
static VALUE arrow_array_stream_arrow_c_stream(VALUE self) {
return self;
}
Returns self. Defined so that the stream object itself satisfies the Arrow C stream protocol used by ruby-polars and others.
Source
static VALUE arrow_array_stream_to_i(VALUE self) {
rubyDuckDBArrowArrayStream *p;
TypedData_Get_Struct(self, rubyDuckDBArrowArrayStream, &arrow_array_stream_data_type, p);
return ULL2NUM((unsigned long long)(uintptr_t)&(p->stream));
}
Returns the address of the underlying C struct ArrowArrayStream. Arrow consumers such as red-arrow accept this address directly:
reader = Arrow::RecordBatchReader.import(stream.to_i)