-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
missed a spot little refactor pycall and conda to extras little refactoring
- Loading branch information
Showing
7 changed files
with
176 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ Manifest.toml | |
*.jl.mem | ||
|
||
test/_scrap.jl | ||
.DS_STORE | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module CDataInterface | ||
|
||
export ArrowSchema, ArrowArray, getschema, getarray | ||
|
||
include("c_definitions.jl") | ||
include("jl_definitions.jl") | ||
|
||
function getschema(f) | ||
schref = Ref{CArrowSchema}() | ||
ptr = Base.unsafe_convert(Ptr{CArrowSchema}, schref) | ||
f(ptr) | ||
sch = ArrowSchema(schref) | ||
finalizer(sch) do x | ||
r = getfield(x.carrowschema[], :release) | ||
if r != C_NULL | ||
ccall(r, Cvoid, (Ptr{CArrowSchema},), x.carrowschema) | ||
end | ||
end | ||
return sch | ||
end | ||
|
||
function getarray(f) | ||
arr_ref = Ref{CArrowArray}() | ||
ptr = Base.unsafe_convert(Ptr{CArrowArray}, arr_ref) | ||
f(ptr) | ||
arr = ArrowArray(arr_ref) | ||
finalizer(arr) do x | ||
r = getfield(x.c_arrow_array[], :release) | ||
if r != C_NULL | ||
ccall(r, Cvoid, (Ptr{CArrowArray},), x.c_arrow_array) | ||
end | ||
end | ||
return arr | ||
end | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# https://arrow.apache.org/docs/format/CDataInterface.html#data-type-description-format-strings | ||
|
||
function get_type_from_format_string(format_string ::String) ::DataType | ||
if format_string == "n" | ||
Nothing | ||
elseif format_string == "b" | ||
Bool | ||
elseif format_string == "c" | ||
Int8 | ||
elseif format_string == "C" | ||
UInt8 | ||
elseif format_string == "s" | ||
Int16 | ||
elseif format_string == "S" | ||
UInt16 | ||
elseif format_string == "i" | ||
Int32 | ||
elseif format_string == "I" | ||
UInt32 | ||
elseif format_string == "l" | ||
Int64 | ||
elseif format_string == "L" | ||
UInt64 | ||
elseif format_string == "e" | ||
Float16 | ||
elseif format_string == "f" | ||
Float32 | ||
elseif format_string == "g" | ||
Float64 | ||
elseif format_string == "z" || format_string == "Z" | ||
Vector{UInt8} | ||
elseif format_string == "u" || format_string == "U" | ||
String | ||
elseif format_string[1] == 'd' | ||
const splits = split(format_string[3:end], ",") | ||
precision = Int(splits[1]) | ||
scale = Int(splits[2]) | ||
if length(splits) == 3 | ||
bandwidth = splits[3] | ||
end | ||
#TODO return something here | ||
elseif format_string[1] == 'w' | ||
#TODO figure out fixed width binary | ||
elseif format_string[1] == '+' | ||
if format_string[2] == 'l' || format_string[2] == 'L' | ||
Arrow.List | ||
elseif format_string[2] == 'w' | ||
size = Int(format_string[4:end]) #TODO use this somehow | ||
Arrow.FixedSizeList | ||
elseif format_string[2] == 's' | ||
Arrow.Struct | ||
elseif format_string[2] == 'm' | ||
Arrow.Map | ||
elseif format_string[2:3] == "ud" | ||
type_strings = split(format_string[5:end], ",") # todo use this somehow | ||
Arrow.DenseUnion | ||
elseif format_string[2:3] == "us" | ||
type_strings = split(format_string[5:end], ",") # todo use this somehow | ||
Arrow.DenseUnion | ||
end | ||
elseif format_string [1] == 't' | ||
# todo return something here | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
mutable struct ArrowSchema | ||
format::String | ||
name::String | ||
metadata::Dict{String, String} | ||
flags::Int64 | ||
n_children::Int64 | ||
children::Vector{ArrowSchema} | ||
dictionary::Union{Nothing, ArrowSchema} | ||
carrowschema::Ref{CArrowSchema} | ||
end | ||
|
||
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 | ||
) | ||
|
||
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}() | ||
) | ||
|
||
mutable struct ArrowArray | ||
length::Int64 | ||
null_count::Int64 | ||
offset::Int64 | ||
n_buffers::Int64 | ||
n_children::Int64 | ||
buffers::Vector{Ptr{UInt8}} | ||
children::Vector{ArrowArray} | ||
dictionary::Union{Nothing, ArrowArray} | ||
c_arrow_array::Ref{CArrowArray} | ||
end | ||
|
||
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 | ||
) | ||
|
||
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}() | ||
) |