databendlabs/databend · error
Zip type requires additional judgment and use…
Error message
Zip type requires additional judgment and use `compress_all_zip`
What it means
The compression codec factory in src/common/compress cannot build a generic streaming encoder for the Zip algorithm, because ZIP is an archive format requiring per-entry bookkeeping, not a single-stream compressor. CompressAlgorithm::Zip therefore reaches an unreachable!() panic in CompressCodec::from; callers must use compress_all_zip instead.
Solutions
- Dispatch Zip inputs to compress_all_zip before building a CompressCodec
- Validate the configured compression algorithm up front and reject Zip on stream-based encoders
- Use a supported single-stream algorithm (gzip, zstd, zstd_raw, etc.) when archive semantics are not required
- Return a typed unsupported-algorithm error instead of panicking for clearer user feedback
Example fix
// before
let codec = CompressCodec::from(algorithm); // panics when algorithm == Zip
// after
let out = match algorithm {
CompressAlgorithm::Zip => compress_all_zip(entries)?,
alg => CompressCodec::from(alg).encode(&data)?,
}; Defensive patterns
Strategy: validation
Validate before calling
if matches!(algorithm, CompressAlgorithm::Zip) {
return Err(ErrorCode::InvalidConfigValue(
"compression",
"zip requires compress_all_zip; use gzip or zstd for stream output",
));
} Type guard
fn supports_stream_encode(alg: CompressAlgorithm) -> bool {
!matches!(alg, CompressAlgorithm::Zip)
} Try / catch
let out = if algorithm == CompressAlgorithm::Zip {
compress_all_zip(&entries)?
} else {
CompressCodec::from(algorithm).encode(&data)?
}; Prevention
- Validate user/config compression options before encoding; reject Zip on streaming paths
- Centralize algorithm dispatch in one function so Zip special-casing cannot be forgotten
- Add a unit test asserting from() panics only for Zip and all other algorithms encode
When it happens
Trigger: Constructing a CompressCodec via from() with CompressAlgorithm::Zip — e.g. a user-selected compression algorithm from stage/COPY options or API parameters is Zip while the generic encode path is invoked.
Common situations: Configuring compression=zip on an export/unload that uses stream-based encoding; an API caller picks Zip for a single-output writer; code refactoring dropped the special case that previously dispatched Zip to compress_all_zip.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Zip type requires additional judgment and use…
- internal error: entered unreachable code
- {}
- Temp table id used up
- Invalid temp table desc
AI-assisted analysis of databendlabs/databend@288d84d76e (2026-09-11).
Data as JSON: /api/errors/256736f53b7546b7.
Report an issue: GitHub.
Appendix: source
Thrown at src/common/compress/src/encode.rs:86
}
CompressAlgorithm::Deflate => {
CompressCodec::Deflate(DeflateEncoder::new(Level::Default.into_flate2()))
}
CompressAlgorithm::Gzip => {
CompressCodec::Gzip(GzipEncoder::new(Level::Default.into_flate2()))
}
CompressAlgorithm::Lzma => {
CompressCodec::Lzma(LzmaEncoder::new(Level::Default.into_xz2()))
}
CompressAlgorithm::Xz => CompressCodec::Xz(XzEncoder::new(Level::Default.into_xz2())),
CompressAlgorithm::Zlib => {
CompressCodec::Zlib(ZlibEncoder::new(Level::Default.into_flate2()))
}
CompressAlgorithm::Zstd => {
CompressCodec::Zstd(ZstdEncoder::new(Level::Default.into_zstd()))
}
CompressAlgorithm::Zip => {
unreachable!("Zip type requires additional judgment and use `compress_all_zip`")
}
}
}
}
impl Encode for CompressCodec {
fn encode(
&mut self,
input: &mut PartialBuffer<impl AsRef<[u8]>>,
output: &mut PartialBuffer<impl AsRef<[u8]> + AsMut<[u8]>>,
) -> Result<()> {
match self {
CompressCodec::Brotli(v) => v.encode(input, output),
CompressCodec::Bz2(v) => v.encode(input, output),
CompressCodec::Deflate(v) => v.encode(input, output),
CompressCodec::Gzip(v) => v.encode(input, output),
CompressCodec::Lzma(v) => v.encode(input, output),
CompressCodec::Xz(v) => v.encode(input, output),View on GitHub (pinned to 288d84d76e)