1#pragma once
2
3
4#include <Core/Names.h>
5#include <DataStreams/IBlockStream_fwd.h>
6#include <Interpreters/IExternalLoadable.h>
7#include <Poco/Util/XMLConfiguration.h>
8#include <Common/PODArray.h>
9#include <common/StringRef.h>
10#include "IDictionarySource.h"
11
12#include <chrono>
13#include <memory>
14
15namespace DB
16{
17
18struct IDictionaryBase;
19using DictionaryPtr = std::unique_ptr<IDictionaryBase>;
20
21struct DictionaryStructure;
22class ColumnString;
23
24struct IDictionaryBase : public IExternalLoadable
25{
26 using Key = UInt64;
27
28 virtual const std::string & getDatabase() const = 0;
29 virtual const std::string & getName() const = 0;
30 virtual const std::string & getFullName() const = 0;
31 const std::string & getLoadableName() const override { return getFullName(); }
32
33 virtual std::string getTypeName() const = 0;
34
35 virtual size_t getBytesAllocated() const = 0;
36
37 virtual size_t getQueryCount() const = 0;
38
39 virtual double getHitRate() const = 0;
40
41 virtual size_t getElementCount() const = 0;
42
43 virtual double getLoadFactor() const = 0;
44
45 virtual const IDictionarySource * getSource() const = 0;
46
47 virtual const DictionaryStructure & getStructure() const = 0;
48
49 virtual bool isInjective(const std::string & attribute_name) const = 0;
50
51 virtual BlockInputStreamPtr getBlockInputStream(const Names & column_names, size_t max_block_size) const = 0;
52
53 bool supportUpdates() const override { return true; }
54
55 bool isModified() const override
56 {
57 auto source = getSource();
58 return source && source->isModified();
59 }
60
61 virtual std::exception_ptr getLastException() const { return {}; }
62
63 std::shared_ptr<IDictionaryBase> shared_from_this()
64 {
65 return std::static_pointer_cast<IDictionaryBase>(IExternalLoadable::shared_from_this());
66 }
67
68 std::shared_ptr<const IDictionaryBase> shared_from_this() const
69 {
70 return std::static_pointer_cast<const IDictionaryBase>(IExternalLoadable::shared_from_this());
71 }
72};
73
74
75struct IDictionary : IDictionaryBase
76{
77 virtual bool hasHierarchy() const = 0;
78
79 virtual void toParent(const PaddedPODArray<Key> & ids, PaddedPODArray<Key> & out) const = 0;
80
81 virtual void has(const PaddedPODArray<Key> & ids, PaddedPODArray<UInt8> & out) const = 0;
82
83 /// Methods for hierarchy.
84
85 virtual void isInVectorVector(
86 const PaddedPODArray<Key> & /*child_ids*/, const PaddedPODArray<Key> & /*ancestor_ids*/, PaddedPODArray<UInt8> & /*out*/) const
87 {
88 throw Exception("Hierarchy is not supported for " + getName() + " dictionary.", ErrorCodes::NOT_IMPLEMENTED);
89 }
90
91 virtual void
92 isInVectorConstant(const PaddedPODArray<Key> & /*child_ids*/, const Key /*ancestor_id*/, PaddedPODArray<UInt8> & /*out*/) const
93 {
94 throw Exception("Hierarchy is not supported for " + getName() + " dictionary.", ErrorCodes::NOT_IMPLEMENTED);
95 }
96
97 virtual void
98 isInConstantVector(const Key /*child_id*/, const PaddedPODArray<Key> & /*ancestor_ids*/, PaddedPODArray<UInt8> & /*out*/) const
99 {
100 throw Exception("Hierarchy is not supported for " + getName() + " dictionary.", ErrorCodes::NOT_IMPLEMENTED);
101 }
102
103 void isInConstantConstant(const Key child_id, const Key ancestor_id, UInt8 & out) const
104 {
105 PaddedPODArray<UInt8> out_arr(1);
106 isInVectorConstant(PaddedPODArray<Key>(1, child_id), ancestor_id, out_arr);
107 out = out_arr[0];
108 }
109};
110
111}
112