Class CompressionMethod

java.lang.Object
dev.frostlake.functions.scalar.encoding.CompressionMethod

public final class CompressionMethod extends Object
The method argument of COMPRESS / DECOMPRESS_STRING / DECOMPRESS_BINARY: an algorithm name with an optional compression level in parentheses, e.g. 'zlib', 'ZLIB(1)', ' zstd '.

The accepted shape was live-verified against Snowflake:

  • the name is case-insensitive and surrounding whitespace is ignored (' SNAPPY ', 'snappy\t' both work) — whitespace inside the name is not ('sn appy' is rejected);
  • the level is an optional (n) suffix, whitespace-tolerant inside the parentheses ('zlib( 1 )'), where n is a non-negative decimal integer that fits in a signed 32-bit int — 'zlib(2147483647)' is accepted, 'zlib(2147483648)' is not; leading zeros are fine ('zlib(01)' is level 1);
  • level 0 means "the method's default", identical to omitting the level;
  • a level above the algorithm's maximum clamps rather than erroring ('zlib(10)' behaves as 'zlib(9)');
  • anything else — a negative level, a non-integer level, empty or unbalanced parentheses, an unknown name — is reported as an unknown method, quoting the whole original string lowercased but NOT trimmed: COMPRESS(x, ' DEFLATE ') fails with Unknown compression method ' deflate ' (SQLSTATE 42P19, error 100194).
  • Field Details

    • DEFAULT_LEVEL

      public static final int DEFAULT_LEVEL
      Snowflake's "use the algorithm's default level" sentinel; method(0) means the same.
      See Also:
  • Method Details

    • parse

      public static CompressionMethod parse(String raw)
      Parses the method argument, or throws Snowflake's unknown-method error.
      Parameters:
      raw - the method text exactly as the caller wrote it — it is echoed verbatim in a decompression failure and lowercased in the unknown-method error
    • algorithm

      public CompressionAlgorithm algorithm()
    • level

      public int level()
      The requested level, or DEFAULT_LEVEL when none was given.
    • raw

      public String raw()
      The method text exactly as written, for the decompression-failure message.