-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from xiaodaigh/inlinestring-support
Inlinestring support
- Loading branch information
Showing
4 changed files
with
36 additions
and
6 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
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
""" | ||
Load data from file using metadata | ||
""" | ||
column_loader(t::Type{T}, io, metadata) where {T} = begin | ||
function column_loader(t::Type{T}, io, metadata) where {T} | ||
buffer = Vector{UInt8}(undef, metadata.len) | ||
column_loader!(buffer, t, io, metadata) | ||
end | ||
|
||
# load bytes bytes from io decompress into type | ||
column_loader!(buffer, ::Type{T}, io, metadata) where {T} = begin | ||
# load bytes from io decompress into type | ||
function column_loader!(buffer, ::Type{T}, io, metadata) where {T} | ||
readbytes!(io, buffer, metadata.len) | ||
return Blosc.decompress(T, buffer) | ||
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
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,30 @@ | ||
# Based on the Julia implementation | ||
# InlineStringN are all `isbitstype` so they work with JDF automatically | ||
# However for other languages, we may still need to explicitly support them and conver them | ||
# to string is not available in those languages | ||
using JDF | ||
using InlineStrings, DataFrames, CSV | ||
|
||
using Random:randstring | ||
|
||
@testset "Test InlineStrings get loaded and saved properly" begin | ||
a = DataFrames.DataFrame(a = [randstring(254) |> String255 for i in 1:100]) | ||
|
||
path = tempdir() | ||
|
||
CSV.write(joinpath(path, "tmp.csv"), a) | ||
|
||
a1 = CSV.read(joinpath(path, "tmp.csv"), DataFrame) | ||
|
||
a1.a = a1.a .|> String255 | ||
|
||
JDF.save(joinpath(path, "tmp.jdf"), a1) | ||
|
||
a2 = JDF.load(joinpath(path, "tmp.jdf")) |> DataFrame | ||
|
||
@test eltype(a2.a) == String255 | ||
|
||
# clean up | ||
rm("tmp.csv"; force=true) | ||
rm("tmp.jdf"; force=true, recursive=true) | ||
end |