ClickHouse/dbms/src/Compression/CompressionFactory.h

71 lines
2.5 KiB
C++
Raw Normal View History

2018-10-11 02:57:48 +00:00
#pragma once
2019-03-11 14:01:45 +00:00
#include <Compression/CompressionInfo.h>
#include <Compression/ICompressionCodec.h>
#include <DataTypes/IDataType.h>
#include <Parsers/IAST_fwd.h>
#include <Common/IFactoryWithAliases.h>
2018-10-11 02:57:48 +00:00
#include <functional>
2019-03-11 14:01:45 +00:00
#include <memory>
2018-12-24 14:10:37 +00:00
#include <optional>
2018-10-11 02:57:48 +00:00
#include <unordered_map>
namespace DB
{
class ICompressionCodec;
using CompressionCodecPtr = std::shared_ptr<ICompressionCodec>;
2018-12-26 15:01:26 +00:00
using CodecNameWithLevel = std::pair<String, std::optional<int>>;
2018-10-11 02:57:48 +00:00
/** Creates a codec object by name of compression algorithm family and parameters.
*/
class CompressionCodecFactory final : private boost::noncopyable
2018-10-11 02:57:48 +00:00
{
protected:
using Creator = std::function<CompressionCodecPtr(const ASTPtr & parameters)>;
using CreatorWithType = std::function<CompressionCodecPtr(const ASTPtr & parameters, DataTypePtr column_type)>;
2018-10-11 02:57:48 +00:00
using SimpleCreator = std::function<CompressionCodecPtr()>;
using CompressionCodecsDictionary = std::unordered_map<String, CreatorWithType>;
using CompressionCodecsCodeDictionary = std::unordered_map<UInt8, CreatorWithType>;
2018-10-11 02:57:48 +00:00
public:
static CompressionCodecFactory & instance();
/// Return default codec (currently LZ4)
2018-10-11 02:57:48 +00:00
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
2019-03-30 20:52:36 +00:00
CompressionCodecPtr get(const ASTPtr & ast, DataTypePtr column_type = nullptr) const;
2018-10-11 02:57:48 +00:00
/// Get codec by method byte (no params available)
2018-10-11 02:57:48 +00:00
CompressionCodecPtr get(const UInt8 byte_code) const;
2018-12-21 12:17:30 +00:00
/// For backward compatibility with config settings
CompressionCodecPtr get(const String & family_name, std::optional<int> level) const;
2018-12-20 17:37:02 +00:00
/// Register codec with parameters and column type
void registerCompressionCodecWithType(const String & family_name, std::optional<UInt8> byte_code, CreatorWithType creator);
/// Register codec with parameters
2018-12-21 14:03:53 +00:00
void registerCompressionCodec(const String & family_name, std::optional<UInt8> byte_code, Creator creator);
2018-10-11 02:57:48 +00:00
/// Register codec without parameters
2018-12-21 14:03:53 +00:00
void registerSimpleCompressionCodec(const String & family_name, std::optional<UInt8> byte_code, SimpleCreator creator);
2018-10-11 02:57:48 +00:00
protected:
CompressionCodecPtr getImpl(const String & family_name, const ASTPtr & arguments, DataTypePtr column_type) const;
2018-10-11 02:57:48 +00:00
private:
CompressionCodecsDictionary family_name_with_codec;
CompressionCodecsCodeDictionary family_code_with_codec;
CompressionCodecPtr default_codec;
CompressionCodecFactory();
};
2018-12-20 17:37:02 +00:00
}