Skip to content

Add AbstractChunkKeyEncoding - #234

Merged
mkitti merged 5 commits into
masterfrom
mkitti-abstract-chunk-key-encoding
Mar 13, 2026
Merged

Add AbstractChunkKeyEncoding#234
mkitti merged 5 commits into
masterfrom
mkitti-abstract-chunk-key-encoding

Conversation

@mkitti

@mkitti mkitti commented Mar 6, 2026

Copy link
Copy Markdown
Member
  • Add AbstractChunkKeyEncoding
  • Rename ChunkEncoding to ChunkKeyEncoding

Chunk Key Encodings are a potential extension point in Zarr:
https://zarr-specs.readthedocs.io/en/latest/v3/chunk-key-encodings/index.html

There are two chunk key encoding extensions:

  1. I proposed a suffix chunk key encoding to add a file extension:
    feat: Add suffix chunk key encoding zarr-developers/zarr-extensions#28
  2. There is also a fanout chunk key encoding:
    Fanout chunk key encoding zarr-developers/zarr-extensions#31

Thus, I think we need an AbstractChunkKeyEncoding to allow for alternate
chunk key encoding extensions.

While ChunkEncoding is a shorter name, it could be confused with the
encoding of a chunk itself rather than it's name. Including the word "Key"
would make it clearer that we are indeed referring to the Zarr v3 concept
of a "chunk key encoding".

@mkitti mkitti mentioned this pull request Mar 6, 2026
@mkitti

mkitti commented Mar 6, 2026

Copy link
Copy Markdown
Member Author

I'm pretty sure that we at least need an abstract type. I could be convinced to not use the word "key", but I do think this will be confusing.

@asinghvi17 asinghvi17 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine to me. I think we don't yet set the API for that, but we can probably do that later. I don't think that's necessary quite yet.

@mkitti

mkitti commented Mar 6, 2026

Copy link
Copy Markdown
Member Author

If the suffix type advances in zarr-extensions, I think we should consider integrating it into the main ChunkKeyEncoding type rather than creating another type for it.

Comment thread src/metadata.jl Outdated

"""Metadata for Zarr version 3 arrays"""
struct MetadataV3{T,N,C,F} <: AbstractMetadata{T,N,C,F}
struct MetadataV3{T,N,C,F,E} <: AbstractMetadata{T,N,C,F,E}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asinghvi17 Do we need a type parameter for the ChunkKeyEncoding?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, yeah. I added an extra comment about constraining that at the abstract type level.

@mkitti
mkitti marked this pull request as ready for review March 6, 2026 12:03
@mkitti

mkitti commented Mar 6, 2026

Copy link
Copy Markdown
Member Author

A prefix chunk key encoding scheme has appeared:
zarr-developers/zarr-extensions#47

Comment thread src/metadata.jl Outdated
@asinghvi17

asinghvi17 commented Mar 7, 2026

Copy link
Copy Markdown
Member

Nightly CI is an expected failure from CondaPkg, I would not worry about that too much. Perhaps we should not load CondaPkg on nightly...

The doctest failure is a bit odd though

@mkitti

mkitti commented Mar 7, 2026

Copy link
Copy Markdown
Member Author

There is an available patch. I was thinking we should test that patch on nightly.

@lazarusA

lazarusA commented Mar 7, 2026

Copy link
Copy Markdown
Member

The doctest failure is a bit odd though

I fixed docs build on #237.

@mkitti

mkitti commented Mar 9, 2026

Copy link
Copy Markdown
Member Author

I intend to merge this if CI passes here.

@coveralls

coveralls commented Mar 9, 2026

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 23070014955

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 59 of 62 (95.16%) changed or added relevant lines in 5 files are covered.
  • 6 unchanged lines in 3 files lost coverage.
  • Overall coverage remained the same at 82.336%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/Storage/Storage.jl 9 10 90.0%
src/chunkkeyencoding.jl 32 34 94.12%
Files with Coverage Reduction New Missed Lines %
src/metadata.jl 1 93.68%
src/Storage/Storage.jl 1 83.74%
src/metadata3.jl 4 96.83%
Totals Coverage Status
Change from base Build 22929818448: 0.0%
Covered Lines: 1403
Relevant Lines: 1704

💛 - Coveralls

@mkitti

mkitti commented Mar 9, 2026

Copy link
Copy Markdown
Member Author

I will follow this up with another pull request to test adding the SuffixChunkKeyEncoding.

@mkitti

mkitti commented Mar 10, 2026

Copy link
Copy Markdown
Member Author

Actually, I think I will wait for #232 to merge into master.

@mkitti
mkitti force-pushed the mkitti-abstract-chunk-key-encoding branch from 8970310 to 5fc50ef Compare March 11, 2026 02:52
@mkitti
mkitti requested review from asinghvi17 and lazarusA March 11, 2026 03:09
Comment thread src/metadata3.jl Outdated
Comment on lines +315 to +320
E = ChunkKeyEncoding
else
error("Unknown chunk key encoding: ", chunk_key_encoding["name"])
end

MetadataV3{TU, N, typeof(pipeline)}(
MetadataV3{TU, N, typeof(pipeline),ChunkKeyEncoding}(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing where E gets used here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
E = ChunkKeyEncoding
else
error("Unknown chunk key encoding: ", chunk_key_encoding["name"])
end
MetadataV3{TU, N, typeof(pipeline)}(
MetadataV3{TU, N, typeof(pipeline),ChunkKeyEncoding}(
E = ChunkKeyEncoding
else
error("Unknown chunk key encoding: ", chunk_key_encoding["name"])
end
MetadataV3{TU, N, typeof(pipeline),E}(

perhaps?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may have been caught between commits. I added a SuffixChunkKeyEncoding to see how this might generalize across multiple AbstractChunkKeyEncodings.

@mkitti

mkitti commented Mar 11, 2026

Copy link
Copy Markdown
Member Author

I've added a SuffixChunkKeyEncoding in 4681551 mainly to assess how the current code would work with multiple AbstractChunkKeyEncoding types. However, the longer term plan if we want to keep this would be to integrate it into the main ChunkKeyEncoding class.

My current expectation is that introducing a new type here will cause some type instability.

@mkitti

mkitti commented Mar 11, 2026

Copy link
Copy Markdown
Member Author

Thinking about this, perhaps we are being inconsistent with naming. Some of the abstract types do not start with Abstract.

@asinghvi17

Copy link
Copy Markdown
Member

True, but then they probably should start with Abstract (in my opinion, anyway :D)

* Implement a registration system for chunk key encoding

* refactor: Add typed ChunkKeyEncodingEntry to chunk key encoding registration

Introduce `ChunkKeyEncodingEntry` struct pairing
`return_type::Type{<:AbstractChunkKeyEncoding}` with `parser::Function`,
replacing the bare `Dict{String, Function}` registry.

- `register_chunk_key_encoding(parser, name, ::Type{T}=AbstractChunkKeyEncoding)`
  now stores a `ChunkKeyEncodingEntry` with the declared return type; the type
  is the last (optional) argument to work naturally with do-block syntax
- `parse_chunk_key_encoding` asserts the result against `entry.return_type`
  at runtime
- All built-in registrations updated with their specific concrete types
  (`ChunkKeyEncoding` for "default" and "v2", `SuffixChunkKeyEncoding` for
  "suffix")

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@mkitti
mkitti merged commit d13f7cf into master Mar 13, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants