-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement ZstdZarrCompressor #149
Open
mkitti
wants to merge
6
commits into
JuliaIO:master
Choose a base branch
from
mkitti:mkitti-zstd-compressor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f2a432f
Implement ZstdZarrCompressor
mkitti 2def22f
Remove info debugging statements
mkitti a04080e
Remove doctest
mkitti 96a93cc
Add test for UnknownCompressorException
mkitti 7232211
Add tests for UnknownCompressorException
mkitti 5ab65d9
Fix tests
mkitti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,54 @@ | ||
module CodecZstdExt | ||
|
||
using Zarr: Zarr | ||
using JSON: JSON | ||
using CodecZstd: CodecZstd | ||
|
||
""" | ||
ZstdZarrCompressor(clevel::Int=0) | ||
ZstdZarrCompressor(c::CodecZstd.ZstdCompressor, [d::CodecZstd.ZstdDecompressor]) | ||
|
||
Zstandard compression for Zarr.jl. This is a `Zarr.Compressor` wrapper around | ||
`CodecZstd`. Construct with either the compression level, `clevel`, or by | ||
providing an instance of a `ZstdCompressor`. `ZstdFrameCompressor` is | ||
recommended. | ||
""" | ||
struct ZstdZarrCompressor <: Zarr.Compressor | ||
compressor::CodecZstd.ZstdCompressor | ||
decompressor::CodecZstd.ZstdDecompressor | ||
end | ||
# Use default ZstdDecompressor if only compressor is provided | ||
function ZstdZarrCompressor(compressor::CodecZstd.ZstdCompressor) | ||
return ZstdZarrCompressor( | ||
compressor, | ||
CodecZstd.ZstdDecompressor() | ||
) | ||
end | ||
function ZstdZarrCompressor(clevel::Int) | ||
return ZstdZarrCompressor( | ||
CodecZstd.ZstdFrameCompressor(; level = clevel) | ||
) | ||
end | ||
ZstdZarrCompressor(;clevel::Int=3) = ZstdZarrCompressor(clevel) | ||
|
||
function Zarr.getCompressor(::Type{ZstdZarrCompressor}, d::Dict) | ||
return ZstdZarrCompressor(d["level"]) | ||
end | ||
|
||
function Zarr.zuncompress(a, z::ZstdZarrCompressor, T) | ||
result = transcode(z.decompressor, a) | ||
return Zarr._reinterpret(Base.nonmissingtype(T), result) | ||
end | ||
|
||
function Zarr.zcompress(a, z::ZstdZarrCompressor) | ||
a_uint8 = Zarr._reinterpret(UInt8,a)[:] | ||
transcode(z.compressor, a_uint8) | ||
end | ||
|
||
JSON.lower(z::ZstdZarrCompressor) = Dict("id"=>"zstd", "level" => z.compressor.level) | ||
|
||
function __init__() | ||
Zarr.compressortypes["zstd"] = ZstdZarrCompressor | ||
end | ||
|
||
end # module CodecZstdExt |
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
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,34 @@ | ||
using Zarr | ||
using Test | ||
|
||
@testset "Zarr Extension Packages" begin | ||
@test_throws Zarr.UnknownCompressorException("zstd") zzeros(UInt8, 512, compressor="zstd") | ||
@test_throws Zarr.UnknownCompressorException("asdf") zzeros(UInt8, 512, compressor="asdf") | ||
d = Dict("id" => "zstd") | ||
@test_throws Zarr.UnknownCompressorException("zstd") Zarr.getCompressor(d) | ||
|
||
iob = IOBuffer() | ||
show(iob, Zarr.UnknownCompressorException("zstd")) | ||
@test occursin("CodecZstd.jl", String(take!(iob))) | ||
|
||
iob = IOBuffer() | ||
show(iob, Zarr.UnknownCompressorException("asdf")) | ||
@test occursin("issue", String(take!(iob))) | ||
@test Zarr.getCompressor(nothing) == Zarr.NoCompressor() | ||
end | ||
|
||
using CodecZstd | ||
@testset "Zarr CodecZstd Extension" begin | ||
CodecZstdExt = Base.get_extension(Zarr, :CodecZstdExt) | ||
@test haskey(Zarr.compressortypes, "zstd") | ||
@test Zarr.compressortypes["zstd"] == CodecZstdExt.ZstdZarrCompressor | ||
td = tempname() | ||
zarray = zzeros(UInt16, 16, 16, compressor="zstd", path=td) | ||
zarray .= reshape(1:256,16,16) | ||
@test isa(zarray, ZArray{UInt16}) | ||
@test zarray.metadata.compressor isa CodecZstdExt.ZstdZarrCompressor | ||
zarray2 = zopen(td) | ||
@test isa(zarray2, ZArray{UInt16}) | ||
@test zarray2.metadata.compressor isa CodecZstdExt.ZstdZarrCompressor | ||
@test zarray2 == reshape(1:256,16,16) | ||
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 |
---|---|---|
|
@@ -266,9 +266,7 @@ end | |
end | ||
|
||
include("storage.jl") | ||
|
||
|
||
|
||
include("python.jl") | ||
include("ext.jl") | ||
|
||
end # @testset "Zarr" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't support multithreaded use IIUC. I think this should be like
Zarr.jl/src/Compressors.jl
Lines 129 to 131 in f436713
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially wrote it like this, but then I was thinking about all the other potential parameters, even if they do not need to be serialized. I think what we should implement is the ability to copy a compessor.
Frankly, I'm somewhat confused about why one actually needs to serialize the compression level into the array metadata. You do not need that information to decompress the data.