apache/beam · error · UnsupportedOperationException

Unsupported compression type: " + canonical

Error message

Unsupported compression type: " + canonical

What it means

fromCanonical() throws UnsupportedOperationException when the Compression enum value has no mapping in the switch. This guards against future/unknown canonical types reaching the sink's compression translation.

Solutions

  1. Upgrade the Beam SDK so the sink's switch handles your Compression value.
  2. Set compression to a supported value (GZIP, BZIP2, ZSTD, SNAPPY, DEFLATE, or UNCOMPRESSED).
  3. Check where the Compression value is constructed from config and constrain it to the supported set.

Example fix

// before
Compression c = Compression.valueOf(config.get("compression")); // UNDEFINED
// after
Compression c = Compression.valueOf(config.getOrDefault("compression", "GZIP"));
Defensive patterns

Strategy: validation

Validate before calling

Set<Compression> supported = EnumSet.of(UNCOMPRESSED, GZIP, BZIP2, ZIP, ZSTD, DEFLATE, SNAPPY);
if (!supported.contains(compression)) { throw new IllegalArgumentException("Compression not supported by this sink: " + compression); }

Try / catch

try { sink = buildSink(compression); } catch (UnsupportedOperationException e) { log.error("Unsupported compression {}", compression, e); sink = buildSink(Compression.GZIP); }

Prevention

When it happens

Trigger: Passing a Compression value to FileBasedSink that is not one of UNCOMPRESSED, GZIP, BZIP2, ZIP, ZSTD, DEFLATE, or SNAPPY — typically from a newly added enum constant or a custom/unrecognized value.

Common situations: Version mismatches where a Compression constant exists in a newer SDK but this FileBasedSink switch does not handle it, or reflection/config-driven construction passing a bogus value.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/cfcb206548c700da. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/io/FileBasedSink.java:213

          throw new IllegalArgumentException("ZIP is unsupported");

        case ZSTD:
          return ZSTD;

        case LZO:
          return LZO;

        case LZOP:
          return LZOP;

        case DEFLATE:
          return DEFLATE;

        case SNAPPY:
          return SNAPPY;

        default:
          throw new UnsupportedOperationException("Unsupported compression type: " + canonical);
      }
    }
  }

  /**
   * This is a helper function for turning a user-provided output filename prefix and converting it
   * into a {@link ResourceId} for writing output files. See {@link TextIO.Write#to(String)} for an
   * example use case.
   *
   * <p>Typically, the input prefix will be something like {@code /tmp/foo/bar}, and the user would
   * like output files to be named as {@code /tmp/foo/bar-0-of-3.txt}. Thus, this function tries to
   * interpret the provided string as a file {@link ResourceId} path.
   *
   * <p>However, this may fail, for example if the user gives a prefix that is a directory. E.g.,
   * {@code /}, {@code gs://my-bucket}, or {@code c://}. In that case, interpreting the string as a
   * file will fail and this function will return a directory {@link ResourceId} instead.
   */
  public static ResourceId convertToFileResourceIfPossible(String outputPrefix) {

View on GitHub (pinned to 12126d8942)