#pragma once #include #include #include #include #include #include #include #include #include namespace DB { class ICompressionCodec; using CompressionCodecPtr = std::shared_ptr; using CodecNameWithLevel = std::pair>; class IAST; using ASTPtr = std::shared_ptr; /** Creates a codec object by name of compression algorithm family and parameters. */ class CompressionCodecFactory final : public ext::singleton { protected: using Creator = std::function; using CreatorWithType = std::function; using SimpleCreator = std::function; using CompressionCodecsDictionary = std::unordered_map; using CompressionCodecsCodeDictionary = std::unordered_map; public: /// Return default codec (currently LZ4) CompressionCodecPtr getDefaultCodec() const; /// Get codec by AST and possible column_type /// some codecs can use information about type to improve inner settings /// but every codec should be able to work without information about type CompressionCodecPtr get(const ASTPtr & ast, DataTypePtr column_type=nullptr) const; /// Get codec by method byte (no params available) CompressionCodecPtr get(const UInt8 byte_code) const; /// For backward compatibility with config settings CompressionCodecPtr get(const String & family_name, std::optional level) const; CompressionCodecPtr get(const std::vector & codecs) const; /// Register codec with parameters and column type void registerCompressionCodecWithType(const String & family_name, std::optional byte_code, CreatorWithType creator); /// Register codec with parameters void registerCompressionCodec(const String & family_name, std::optional byte_code, Creator creator); /// Register codec without parameters void registerSimpleCompressionCodec(const String & family_name, std::optional byte_code, SimpleCreator creator); protected: CompressionCodecPtr getImpl(const String & family_name, const ASTPtr & arguments, DataTypePtr column_type) const; private: CompressionCodecsDictionary family_name_with_codec; CompressionCodecsCodeDictionary family_code_with_codec; CompressionCodecPtr default_codec; CompressionCodecFactory(); friend class ext::singleton; }; }