Class: DuckDB::ArrowArrayStream

Inherits:
Object
  • Object
show all
Defined in:
lib/duckdb/arrow_array_stream.rb,
ext/duckdb/arrow_array_stream.c

Overview

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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.newObject

Raises:



28
29
30
# 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

Instance Method Details

#arrow_c_streamself

Returns self. Defined so that the stream object itself satisfies the Arrow C stream protocol used by ruby-polars and others.

Returns:

  • (self)


212
213
214
# File 'ext/duckdb/arrow_array_stream.c', line 212

static VALUE arrow_array_stream_arrow_c_stream(VALUE self) {
    return self;
}

#to_iInteger

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)

Returns:

  • (Integer)


198
199
200
201
202
203
# File 'ext/duckdb/arrow_array_stream.c', line 198

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));
}