prestodb/presto · error · IllegalArgumentException

Unknown codec: ${codecName}

Error message

Unknown codec: ${codecName}

What it means

HadoopCodecFactory.createCompressionCodec instantiates a Hadoop compression codec class by reflective name lookup. If the class cannot be loaded/instantiated (ClassNotFoundException, instantiation failure), it throws IllegalArgumentException 'Unknown codec: <name>'. The configured codec name is not resolvable on the classpath.

Source

Thrown at presto-rcfile/src/main/java/com/facebook/presto/rcfile/HadoopCodecFactory.java:62

    }

    private CompressionCodec createCompressionCodec(String codecName)
    {
        try {
            Class<? extends CompressionCodec> codecClass = classLoader.loadClass(codecName).asSubclass(CompressionCodec.class);
            Constructor<? extends CompressionCodec> constructor = codecClass.getDeclaredConstructor();
            constructor.setAccessible(true);
            CompressionCodec codec = constructor.newInstance();
            if (codec instanceof Configurable) {
                // Hadoop is crazy... you have to give codecs an empty configuration or they throw NPEs
                // but you need to make sure the configuration doesn't "load" defaults or it spends
                // forever loading XML with no useful information
                ((Configurable) codec).setConf(new Configuration(false));
            }
            return codec;
        }
        catch (ReflectiveOperationException e) {
            throw new IllegalArgumentException("Unknown codec: " + codecName, e);
        }
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Verify the codec class name spelling and package against your Hadoop version.
  2. Add the jar providing the codec to the Presto plugin/classpath and restart.
  3. Prefer codecs bundled with the deployment (gzip, snappy via aircompressor).
  4. Re-write the file with a supported codec if the original codec is unavailable.

Example fix

// before: unknown codec
session.getProperties().put("rcfile_compression_codec", "org.apache.hadoop.io.compress.ZStandardCodec");
// after: supported codec
session.getProperties().put("rcfile_compression_codec", "com.facebook.airlift.compress.zstd.ZstdJniCompressor"); // or use gzip/snappy
Defensive patterns

Strategy: validation

Validate before calling

// check the codec class is loadable before opening the file
try {
  Class<?> c = Class.forName(codecClassName);
  if (!org.apache.hadoop.io.compress.CompressionCodec.class.isAssignableFrom(c))
    throw new IllegalStateException(codecClassName + " is not a CompressionCodec");
} catch (ClassNotFoundException e) {
  throw new IllegalStateException("Codec not on classpath: " + codecClassName);
}

Try / catch

try {
  CompressionCodec codec = codecFactory.codec(codecName);
} catch (IllegalArgumentException e) {
  if (String.valueOf(e.getMessage()).startsWith("Unknown codec:")) {
    // fall back to a supported codec or fail fast with a clear config error
  } else throw e;
}

Prevention

When it happens

Trigger: An RCFile session/table is configured with a compression codec class name (e.g. org.apache.hadoop.io.compress.SnappyCodec or a custom codec) that is missing from the classpath or fails to construct.

Common situations: Reading RCFiles compressed with ZSTD/LZO or a vendor codec whose jar is not on the Presto classpath; typo in codec class name; Hadoop version change moving/renaming codec classes.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/b81a94e0d19af5ec. Report an issue: GitHub.