2018-10-11 02:57:48 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <functional>
|
2018-12-24 14:10:37 +00:00
|
|
|
#include <optional>
|
2018-10-11 02:57:48 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <ext/singleton.h>
|
|
|
|
#include <Common/IFactoryWithAliases.h>
|
|
|
|
#include <Compression/ICompressionCodec.h>
|
2018-12-21 13:25:39 +00:00
|
|
|
#include <Compression/CompressionInfo.h>
|
2018-10-11 02:57:48 +00:00
|
|
|
|
|
|
|
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
|
|
|
class IAST;
|
|
|
|
|
|
|
|
using ASTPtr = std::shared_ptr<IAST>;
|
|
|
|
|
|
|
|
/** Creates a codec object by name of compression algorithm family and parameters.
|
|
|
|
*/
|
|
|
|
class CompressionCodecFactory final : public ext::singleton<CompressionCodecFactory>
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
using Creator = std::function<CompressionCodecPtr(const ASTPtr & parameters)>;
|
|
|
|
using SimpleCreator = std::function<CompressionCodecPtr()>;
|
|
|
|
using CompressionCodecsDictionary = std::unordered_map<String, Creator>;
|
|
|
|
using CompressionCodecsCodeDictionary = std::unordered_map<UInt8, Creator>;
|
|
|
|
public:
|
|
|
|
|
2018-12-25 10:04:38 +00:00
|
|
|
/// Return default codec (currently LZ4)
|
2018-10-11 02:57:48 +00:00
|
|
|
CompressionCodecPtr getDefaultCodec() const;
|
|
|
|
|
2018-12-25 10:04:38 +00:00
|
|
|
/// Get codec by AST
|
2018-10-11 02:57:48 +00:00
|
|
|
CompressionCodecPtr get(const ASTPtr & ast) const;
|
|
|
|
|
2018-12-25 10:04:38 +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
|
|
|
|
2018-12-26 15:01:26 +00:00
|
|
|
CompressionCodecPtr get(const std::vector<CodecNameWithLevel> & codecs) const;
|
2018-12-25 10:04:38 +00:00
|
|
|
/// 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
|
|
|
|
2018-12-25 10:04:38 +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) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
CompressionCodecsDictionary family_name_with_codec;
|
|
|
|
CompressionCodecsCodeDictionary family_code_with_codec;
|
|
|
|
CompressionCodecPtr default_codec;
|
|
|
|
|
|
|
|
CompressionCodecFactory();
|
|
|
|
|
|
|
|
friend class ext::singleton<CompressionCodecFactory>;
|
|
|
|
};
|
|
|
|
|
2018-12-20 17:37:02 +00:00
|
|
|
}
|