This is an automated email from the ASF dual-hosted git repository.

quinnj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-julia.git


The following commit(s) were added to refs/heads/main by this push:
     new aaa4cf8  Implement Tables.columnnames and Tables.schema for 
Arrow.Stream (#395)
aaa4cf8 is described below

commit aaa4cf878a2f116944d910b84aa4747fa3112ecb
Author: Ben Baumgold <[email protected]>
AuthorDate: Mon Mar 13 18:37:27 2023 -0400

    Implement Tables.columnnames and Tables.schema for Arrow.Stream (#395)
---
 src/table.jl | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/table.jl b/src/table.jl
index da873e2..b1695e9 100644
--- a/src/table.jl
+++ b/src/table.jl
@@ -80,12 +80,33 @@ function Stream(inputs::Vector{ArrowBlob}; 
convert::Bool=true)
     Stream(inputs, inputindex, batchiterator, names, types, schema, 
dictencodings, dictencoded, convert, compression)
 end
 
-Tables.partitions(x::Stream) = x
-
 Stream(input, pos::Integer=1, len=nothing; kw...) = 
Stream([ArrowBlob(tobytes(input), pos, len)]; kw...)
 Stream(input::Vector{UInt8}, pos::Integer=1, len=nothing; kw...) = 
Stream([ArrowBlob(tobytes(input), pos, len)]; kw...)
 Stream(inputs::Vector; kw...) = Stream([ArrowBlob(tobytes(x), 1, nothing) for 
x in inputs]; kw...)
 
+function initialize!(x::Stream)
+    isempty(getfield(x, :names)) || return
+    # Initialize member fields using iteration and reset state
+    lastinputindex = x.inputindex
+    lastbatchiterator = x.batchiterator
+    iterate(x)
+    x.inputindex = lastinputindex
+    x.batchiterator = lastbatchiterator
+    nothing
+end
+
+Tables.partitions(x::Stream) = x
+
+function Tables.columnnames(x::Stream)
+    initialize!(x)
+    getfield(x, :names)
+end
+
+function Tables.schema(x::Stream)
+    initialize!(x)
+    Tables.Schema(Tables.columnnames(x), getfield(x, :types))
+end
+
 Base.IteratorSize(::Type{Stream}) = Base.SizeUnknown()
 Base.eltype(::Type{Stream}) = Table
 

Reply via email to