跳到內容

在 nanoarrow 中,「array stream」對應於 Arrow C Stream 介面中定義的 struct ArrowArrayStream。 此物件用於表示具有通用 schemaarrays stream。 這類似於 arrow::RecordBatchReader,但它可以用於表示任何類型的 stream(不僅僅是 record batches)。 請注意,record batches 的 stream 和 non-nullable struct arrays 的 stream 以相同方式表示。 另請注意,array streams 是可變物件,並通過引用而不是值傳遞。

用法

as_nanoarrow_array_stream(x, ..., schema = NULL)

參數

x

要轉換為 array_stream 的物件

...

傳遞給 S3 方法

schema

用於強制轉換為特定類型的可選 schema。 預設為 infer_nanoarrow_schema()

類別為 'nanoarrow_array_stream' 的物件

範例

(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()