1- module CData
2-
3- export ArrowSchema, ArrowArray, getschema, getarray
4-
51const ARROW_FLAG_DICTIONARY_ORDERED = 1
62const ARROW_FLAG_NULLABLE = 2
73const ARROW_FLAG_MAP_KEYS_SORTED = 4
@@ -22,7 +18,7 @@ CArrowSchema() = CArrowSchema(C_NULL, C_NULL, C_NULL, 0, 0, C_NULL, C_NULL, _CNU
2218
2319Base. propertynames (:: CArrowSchema ) = (:format , :name , :metadata , :flags , :n_children , :children , :dictionary )
2420
25- function readmetadata (ptr:: Ptr{UInt8} )
21+ function read_c_arrow_schema_metadata (ptr:: Ptr{UInt8} )
2622 pos = 1
2723 meta = Dict {String, String} ()
2824 if ptr != C_NULL
@@ -49,7 +45,7 @@ function Base.getproperty(x::CArrowSchema, nm::Symbol)
4945 elseif nm === :name
5046 return unsafe_string (getfield (x, :name ))
5147 elseif nm === :metadata
52- return readmetadata (getfield (x, :metadata ))
48+ return read_c_arrow_schema_metadata (getfield (x, :metadata ))
5349 elseif nm === :flags
5450 return getfield (x, :flags )
5551 elseif nm === :n_children
@@ -64,34 +60,6 @@ function Base.getproperty(x::CArrowSchema, nm::Symbol)
6460 error (" unknown property requested: $nm " )
6561end
6662
67- mutable struct ArrowSchema
68- format:: String
69- name:: String
70- metadata:: Dict{String, String}
71- flags:: Int64
72- n_children:: Int64
73- children:: Vector{ArrowSchema}
74- dictionary:: Union{Nothing, ArrowSchema}
75- carrowschema:: Ref{CArrowSchema}
76- end
77-
78- ArrowSchema (s:: Ref{CArrowSchema} ) = ArrowSchema (s[]. format, s[]. name, s[]. metadata, s[]. flags, s[]. n_children, map (ArrowSchema, s[]. children), s[]. dictionary === nothing ? nothing : ArrowSchema (s[]. dictionary), s)
79- ArrowSchema (s:: CArrowSchema ) = ArrowSchema (s. format, s. name, s. metadata, s. flags, s. n_children, map (ArrowSchema, s. children), s. dictionary === nothing ? nothing : ArrowSchema (s. dictionary), Ref {CArrowSchema} ())
80-
81- function getschema (f)
82- schref = Ref {CArrowSchema} ()
83- ptr = Base. unsafe_convert (Ptr{CArrowSchema}, schref)
84- f (ptr)
85- sch = ArrowSchema (schref)
86- finalizer (sch) do x
87- r = getfield (x. carrowschema[], :release )
88- if r != C_NULL
89- ccall (r, Cvoid, (Ptr{CArrowSchema},), x. carrowschema)
90- end
91- end
92- return sch
93- end
94-
9563struct CArrowArray
9664 length:: Int64
9765 null_count:: Int64
@@ -131,35 +99,4 @@ function Base.getproperty(x::CArrowArray, nm::Symbol)
13199 return d == C_NULL ? nothing : unsafe_load (d)
132100 end
133101 error (" unknown property requested: $nm " )
134- end
135-
136- mutable struct ArrowArray
137- length:: Int64
138- null_count:: Int64
139- offset:: Int64
140- n_buffers:: Int64
141- n_children:: Int64
142- buffers:: Vector{Ptr{UInt8}}
143- children:: Vector{ArrowArray}
144- dictionary:: Union{Nothing, ArrowArray}
145- carrowarray:: Ref{CArrowArray}
146- end
147-
148- ArrowArray (a:: Ref{CArrowArray} ) = ArrowArray (a[]. length, a[]. null_count, a[]. offset, a[]. n_buffers, a[]. n_children, a[]. buffers, map (ArrowArray, a[]. children), a[]. dictionary === nothing ? nothing : ArrowArray (a[]. dictionary), a)
149- ArrowArray (a:: CArrowArray ) = ArrowArray (a. length, a. null_count, a. offset, a. n_buffers, a. n_children, a. buffers, map (ArrowArray, a. children), a. dictionary === nothing ? nothing : ArrowArray (a. dictionary), Ref {CArrowArray} ())
150-
151- function getarray (f)
152- arrref = Ref {CArrowArray} ()
153- ptr = Base. unsafe_convert (Ptr{CArrowArray}, arrref)
154- f (ptr)
155- arr = ArrowArray (arrref)
156- finalizer (arr) do x
157- r = getfield (x. carrowarray[], :release )
158- if r != C_NULL
159- ccall (r, Cvoid, (Ptr{CArrowArray},), x. carrowarray)
160- end
161- end
162- return arr
163- end
164-
165- end # module
102+ end
0 commit comments