forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from nikvas0/nikvas0/index_creation
Nikvas0/index creation
- Loading branch information
Showing
9 changed files
with
122 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <Storages/MergeTree/MergeTreeIndexes.h> | ||
|
||
namespace DB | ||
{ | ||
|
||
namespace ErrorCodes | ||
{ | ||
extern const int LOGICAL_ERROR; | ||
extern const int INCORRECT_QUERY; | ||
} | ||
|
||
void MergeTreeIndexFactory::registerIndex(const std::string &name, Creator creator) { | ||
if (!indexes.emplace(name, std::move(creator)).second) | ||
throw Exception("MergeTreeIndexFactory: the Index creator name '" + name + "' is not unique", | ||
ErrorCodes::LOGICAL_ERROR); | ||
} | ||
|
||
std::unique_ptr<MergeTreeIndex> MergeTreeIndexFactory::get(std::shared_ptr<ASTIndexDeclaration> node) const { | ||
if (!node->type) | ||
throw Exception( | ||
"for INDEX TYPE is required", | ||
ErrorCodes::INCORRECT_QUERY); | ||
auto it = indexes.find(node->type->name); | ||
if (it == indexes.end()) | ||
throw Exception( | ||
"Unknown Index type '" + node->type->name + "'", | ||
ErrorCodes::INCORRECT_QUERY); | ||
return it->second(node); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <unordered_map> | ||
#include <vector> | ||
#include <memory> | ||
#include <Core/Block.h> | ||
#include <ext/singleton.h> | ||
#include <Interpreters/ExpressionActions.h> | ||
#include <Storages/MergeTree/MergeTreeDataPartChecksum.h> | ||
#include <Parsers/ASTIndexDeclaration.h> | ||
|
||
namespace DB | ||
{ | ||
|
||
|
||
/// Interface for secondary MergeTree indexes | ||
class MergeTreeIndex | ||
{ | ||
public: | ||
virtual ~MergeTreeIndex() {}; | ||
|
||
virtual void load(const String & part_path) = 0; | ||
virtual void store(const String & part_path, MergeTreeDataPartChecksums & checksums) const = 0; | ||
|
||
virtual void update(const Block & block, const Names & column_names) = 0; | ||
virtual void merge(const MergeTreeIndex & other) = 0; | ||
|
||
virtual bool alwaysUnknownOrTrue() const = 0; | ||
virtual bool maybeTrue() const = 0; | ||
|
||
String name; | ||
ExpressionActionsPtr expr; | ||
Block header; | ||
}; | ||
|
||
using MergeTreeIndexPtr = std::unique_ptr<MergeTreeIndex>; | ||
using MergeTreeIndexes = std::vector<MergeTreeIndexPtr>; | ||
|
||
|
||
class MergeTreeIndexFactory : public ext::singleton<MergeTreeIndexFactory> | ||
{ | ||
friend class ext::singleton<MergeTreeIndexFactory>; | ||
|
||
public: | ||
using Creator = std::function<std::unique_ptr<MergeTreeIndex>(std::shared_ptr<ASTIndexDeclaration> node)>; | ||
|
||
std::unique_ptr<MergeTreeIndex> get(std::shared_ptr<ASTIndexDeclaration> node) const; | ||
|
||
void registerIndex(const std::string & name, Creator creator); | ||
|
||
const auto & getAllIndexes() const { | ||
return indexes; | ||
} | ||
|
||
protected: | ||
MergeTreeIndexFactory() {}; | ||
|
||
private: | ||
using Indexes = std::unordered_map<std::string, Creator>; | ||
Indexes indexes; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters