在 nanoarrow 中,一个“数组流”对应于 Arrow C 流接口中定义的 struct ArrowArrayStream。此对象用于表示具有共同模式的数组流。这类似于 arrow::RecordBatchReader,但它可用于表示任何类型(不仅仅是记录批次)的流。请注意,记录批次流和非空结构数组流的表示方式相同。另请注意,数组流是可变对象,并通过引用而不是通过值传递。
参数
- x
要转换为数组流的对象
- ...
传递给 S3 方法
- schema
可选模式,用于强制转换为特定类型。默认为
infer_nanoarrow_schema()。
示例
(stream <- as_nanoarrow_array_stream(data.frame(x = 1:5)))
#> <nanoarrow_array_stream struct<x: int32>>
#> $ get_schema:function ()
#> $ get_next :function (schema = x$get_schema(), validate = TRUE)
#> $ release :function ()
stream$get_schema()
#> <nanoarrow_schema struct>
#> $ format : chr "+s"
#> $ name : chr ""
#> $ metadata : list()
#> $ flags : int 0
#> $ children :List of 1
#> ..$ x:<nanoarrow_schema int32>
#> .. ..$ format : chr "i"
#> .. ..$ name : chr "x"
#> .. ..$ metadata : list()
#> .. ..$ flags : int 2
#> .. ..$ children : list()
#> .. ..$ dictionary: NULL
#> $ dictionary: NULL
stream$get_next()
#> <nanoarrow_array struct[5]>
#> $ length : int 5
#> $ null_count: int 0
#> $ offset : int 0
#> $ buffers :List of 1
#> ..$ :<nanoarrow_buffer validity<bool>[null] ``
#> $ children :List of 1
#> ..$ x:<nanoarrow_array int32[5]>
#> .. ..$ length : int 5
#> .. ..$ null_count: int 0
#> .. ..$ offset : int 0
#> .. ..$ buffers :List of 2
#> .. .. ..$ :<nanoarrow_buffer validity<bool>[null] ``
#> .. .. ..$ :<nanoarrow_buffer data<int32>[5][20 b]> `1 2 3 4 5`
#> .. ..$ dictionary: NULL
#> .. ..$ children : list()
#> $ dictionary: NULL
# The last batch is returned as NULL
stream$get_next()
#> NULL
# Release the stream
stream$release()