2015-01-21 11:39:48 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-05-17 14:34:25 +00:00
|
|
|
|
2017-06-05 10:01:47 +00:00
|
|
|
#include <Core/Names.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <DataStreams/IBlockStream_fwd.h>
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <Interpreters/IExternalLoadable.h>
|
2015-01-22 14:32:38 +00:00
|
|
|
#include <Poco/Util/XMLConfiguration.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/PODArray.h>
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <common/StringRef.h>
|
2018-11-28 11:37:12 +00:00
|
|
|
#include "IDictionarySource.h"
|
2015-01-21 11:39:48 +00:00
|
|
|
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <chrono>
|
|
|
|
#include <memory>
|
|
|
|
|
2015-01-21 11:39:48 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2020-02-25 18:10:48 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int NOT_IMPLEMENTED;
|
|
|
|
}
|
2019-05-17 14:34:25 +00:00
|
|
|
|
2016-03-07 04:31:10 +00:00
|
|
|
struct IDictionaryBase;
|
2015-07-13 17:10:16 +00:00
|
|
|
using DictionaryPtr = std::unique_ptr<IDictionaryBase>;
|
2015-01-30 13:43:16 +00:00
|
|
|
|
2016-03-07 04:31:10 +00:00
|
|
|
struct DictionaryStructure;
|
2015-02-19 14:51:39 +00:00
|
|
|
class ColumnString;
|
2015-01-30 15:18:13 +00:00
|
|
|
|
2017-10-06 10:31:06 +00:00
|
|
|
struct IDictionaryBase : public IExternalLoadable
|
2015-01-21 11:39:48 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
using Key = UInt64;
|
2015-01-21 11:39:48 +00:00
|
|
|
|
2019-12-25 23:12:12 +00:00
|
|
|
virtual const std::string & getDatabase() const = 0;
|
|
|
|
virtual const std::string & getName() const = 0;
|
|
|
|
virtual const std::string & getFullName() const = 0;
|
2020-01-24 16:20:36 +00:00
|
|
|
|
2019-12-25 23:12:12 +00:00
|
|
|
const std::string & getLoadableName() const override { return getFullName(); }
|
|
|
|
|
2020-01-24 16:20:36 +00:00
|
|
|
/// Specifies that no database is used.
|
|
|
|
/// Sometimes we cannot simply use an empty string for that because an empty string is
|
|
|
|
/// usually replaced with the current database.
|
|
|
|
static constexpr char NO_DATABASE_TAG[] = "<no_database>";
|
|
|
|
|
|
|
|
std::string_view getDatabaseOrNoDatabaseTag() const
|
|
|
|
{
|
|
|
|
const std::string & database = getDatabase();
|
|
|
|
if (!database.empty())
|
|
|
|
return database;
|
|
|
|
return NO_DATABASE_TAG;
|
|
|
|
}
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
virtual std::string getTypeName() const = 0;
|
2015-01-29 14:46:15 +00:00
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
virtual size_t getBytesAllocated() const = 0;
|
2015-03-24 11:30:16 +00:00
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
virtual size_t getQueryCount() const = 0;
|
2015-05-08 12:31:00 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
virtual double getHitRate() const = 0;
|
2015-03-24 17:02:56 +00:00
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
virtual size_t getElementCount() const = 0;
|
2015-03-24 17:02:56 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
virtual double getLoadFactor() const = 0;
|
2015-03-24 17:02:56 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
virtual const IDictionarySource * getSource() const = 0;
|
2015-01-29 15:47:21 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
virtual const DictionaryStructure & getStructure() const = 0;
|
2015-03-24 13:59:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
virtual bool isInjective(const std::string & attribute_name) const = 0;
|
2015-05-13 16:11:07 +00:00
|
|
|
|
2019-02-18 18:51:46 +00:00
|
|
|
virtual BlockInputStreamPtr getBlockInputStream(const Names & column_names, size_t max_block_size) const = 0;
|
2017-04-27 17:16:24 +00:00
|
|
|
|
2019-12-02 15:56:18 +00:00
|
|
|
bool supportUpdates() const override { return true; }
|
2017-10-06 10:31:06 +00:00
|
|
|
|
2017-10-06 11:10:01 +00:00
|
|
|
bool isModified() const override
|
2017-10-26 12:18:37 +00:00
|
|
|
{
|
|
|
|
auto source = getSource();
|
2017-10-06 11:10:01 +00:00
|
|
|
return source && source->isModified();
|
|
|
|
}
|
|
|
|
|
2019-08-30 09:50:38 +00:00
|
|
|
virtual std::exception_ptr getLastException() const { return {}; }
|
|
|
|
|
2017-10-06 10:31:06 +00:00
|
|
|
std::shared_ptr<IDictionaryBase> shared_from_this()
|
|
|
|
{
|
|
|
|
return std::static_pointer_cast<IDictionaryBase>(IExternalLoadable::shared_from_this());
|
|
|
|
}
|
2017-10-26 18:49:23 +00:00
|
|
|
|
2017-10-06 10:31:06 +00:00
|
|
|
std::shared_ptr<const IDictionaryBase> shared_from_this() const
|
|
|
|
{
|
|
|
|
return std::static_pointer_cast<const IDictionaryBase>(IExternalLoadable::shared_from_this());
|
|
|
|
}
|
2015-07-13 17:10:16 +00:00
|
|
|
};
|
|
|
|
|
2016-12-12 21:37:57 +00:00
|
|
|
|
2015-07-13 17:10:16 +00:00
|
|
|
struct IDictionary : IDictionaryBase
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
virtual bool hasHierarchy() const = 0;
|
2015-01-21 11:39:48 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
virtual void toParent(const PaddedPODArray<Key> & ids, PaddedPODArray<Key> & out) const = 0;
|
2015-11-20 15:53:23 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
virtual void has(const PaddedPODArray<Key> & ids, PaddedPODArray<UInt8> & out) const = 0;
|
2015-11-20 15:53:23 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Methods for hierarchy.
|
2015-07-10 14:43:49 +00:00
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
virtual void isInVectorVector(
|
|
|
|
const PaddedPODArray<Key> & /*child_ids*/, const PaddedPODArray<Key> & /*ancestor_ids*/, PaddedPODArray<UInt8> & /*out*/) const
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
throw Exception("Hierarchy is not supported for " + getName() + " dictionary.", ErrorCodes::NOT_IMPLEMENTED);
|
|
|
|
}
|
2015-07-10 14:43:49 +00:00
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
virtual void
|
|
|
|
isInVectorConstant(const PaddedPODArray<Key> & /*child_ids*/, const Key /*ancestor_id*/, PaddedPODArray<UInt8> & /*out*/) const
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
throw Exception("Hierarchy is not supported for " + getName() + " dictionary.", ErrorCodes::NOT_IMPLEMENTED);
|
|
|
|
}
|
2015-07-10 14:43:49 +00:00
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
virtual void
|
|
|
|
isInConstantVector(const Key /*child_id*/, const PaddedPODArray<Key> & /*ancestor_ids*/, PaddedPODArray<UInt8> & /*out*/) const
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
throw Exception("Hierarchy is not supported for " + getName() + " dictionary.", ErrorCodes::NOT_IMPLEMENTED);
|
|
|
|
}
|
2015-01-28 13:20:20 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void isInConstantConstant(const Key child_id, const Key ancestor_id, UInt8 & out) const
|
|
|
|
{
|
|
|
|
PaddedPODArray<UInt8> out_arr(1);
|
|
|
|
isInVectorConstant(PaddedPODArray<Key>(1, child_id), ancestor_id, out_arr);
|
|
|
|
out = out_arr[0];
|
|
|
|
}
|
2015-01-21 11:39:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|