apache/beam · error · UnsupportedOperationException
AUTO is applicable only to reading files
Error message
AUTO is applicable only to reading files
What it means
Compression.AUTO only applies when reading (compression detection by extension). Its writeCompressed() therefore always throws UnsupportedOperationException, since there is no concrete codec to compress with when writing.
Source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/io/Compression.java:60
import org.apache.commons.compress.compressors.zstandard.ZstdCompressorOutputStream;
/** Various compression types for reading/writing files. */
@SuppressWarnings("ImmutableEnumChecker")
public enum Compression {
/**
* When reading a file, automatically determine the compression type based on filename extension.
* Not applicable when writing files.
*/
AUTO("") {
@Override
public ReadableByteChannel readDecompressed(ReadableByteChannel channel) {
throw new UnsupportedOperationException(
"Must resolve compression into a concrete value before calling readDecompressed()");
}
@Override
public WritableByteChannel writeCompressed(WritableByteChannel channel) {
throw new UnsupportedOperationException("AUTO is applicable only to reading files");
}
},
/** No compression. */
UNCOMPRESSED("") {
@Override
public ReadableByteChannel readDecompressed(ReadableByteChannel channel) {
return channel;
}
@Override
public WritableByteChannel writeCompressed(WritableByteChannel channel) {
return channel;
}
},
/** GZip compression. */
GZIP(".gz", ".gz") {View on GitHub (pinned to 12126d8942)
Solutions
- Use a concrete compression for writing (GZIP, BZIP2, ZSTD, or UNCOMPRESSED).
- Special-case AUTO in writing code by substituting UNCOMPRESSED or a detected/appropriate type.
- Validate user-provided compression options at pipeline construction time and reject AUTO for sinks.
Example fix
// before Compression.AUTO.writeCompressed(channel); // after Compression.GZIP.writeCompressed(channel);
Defensive patterns
Strategy: validation
Validate before calling
if (compression == Compression.AUTO) {
compression = Compression.UNCOMPRESSED; // or GZIP
} Try / catch
try {
out = compression.writeCompressed(channel);
} catch (UnsupportedOperationException e) {
out = Compression.UNCOMPRESSED.writeCompressed(channel);
} Prevention
- Never configure sinks with AUTO compression
- Separate read-side and write-side compression options
- Validate compression config at pipeline construction
When it happens
Trigger: Calling Compression.AUTO.writeCompressed(channel) directly, or configuring a sink's write compression to AUTO (e.g., FileIO.write().withCompression(AUTO) reaching CompressionType.fromCanonical or the enum's write path).
Common situations: Reusing a read-side Compression value for writing; pipeline options where compression=AUTO was meant for reads but applied to an output sink.
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
- Must resolve compression into a concrete value before callin
- Writing ZIP files is currently unsupported
- Unsupported compression type: " + compression
- Failed to determine if the source is splittable
- AUTO is not supported for writing
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/247b43e642afc200.
Report an issue: GitHub.