forked from pingcap/tiflash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c8b3a0
commit b963dd0
Showing
32 changed files
with
3,201 additions
and
9 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
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,42 @@ | ||
#include <Interpreters/Context.h> | ||
#include <Interpreters/InterpreterManageQuery.h> | ||
#include <Parsers/ASTManageQuery.h> | ||
#include <Storages/IStorage.h> | ||
#include <Common/typeid_cast.h> | ||
|
||
#include <Storages/StorageDeltaMerge.h> | ||
|
||
namespace DB | ||
{ | ||
BlockIO InterpreterManageQuery::execute() | ||
{ | ||
const ASTManageQuery & ast = typeid_cast<const ASTManageQuery &>(*query_ptr); | ||
|
||
StoragePtr table = context.getTable(ast.database, ast.table); | ||
if (table->getName() != "DeltaMerge") | ||
{ | ||
throw Exception("Manage operation can only be applied to DeltaMerge engine tables"); | ||
} | ||
auto & dm_table = static_cast<StorageDeltaMerge &>(*table); | ||
switch (ast.operation) | ||
{ | ||
case ManageOperation::Enum::Flush: | ||
{ | ||
dm_table.flushDelta(); | ||
return {}; | ||
} | ||
case ManageOperation::Enum::Status: | ||
{ | ||
BlockIO res; | ||
res.in = dm_table.status(); | ||
return res; | ||
} | ||
case ManageOperation::Enum::Check: | ||
{ | ||
dm_table.check(); | ||
return {}; | ||
} | ||
} | ||
return {}; | ||
} | ||
} |
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,29 @@ | ||
#pragma once | ||
|
||
#include <Interpreters/IInterpreter.h> | ||
|
||
|
||
namespace DB | ||
{ | ||
|
||
class Context; | ||
class IAST; | ||
using ASTPtr = std::shared_ptr<IAST>; | ||
|
||
class InterpreterManageQuery : public IInterpreter | ||
{ | ||
public: | ||
InterpreterManageQuery(const ASTPtr & query_ptr_, Context & context_) | ||
: query_ptr(query_ptr_), context(context_) | ||
{ | ||
} | ||
|
||
BlockIO execute() override; | ||
|
||
private: | ||
ASTPtr query_ptr; | ||
Context & context; | ||
}; | ||
|
||
|
||
} |
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,56 @@ | ||
#pragma once | ||
|
||
#include <Parsers/IAST.h> | ||
|
||
|
||
namespace DB | ||
{ | ||
namespace ManageOperation | ||
{ | ||
enum Enum | ||
{ | ||
Flush, | ||
Status, | ||
Check, | ||
}; | ||
|
||
inline const char * toString(UInt64 op) | ||
{ | ||
static const char * data[] = {"Flush", "Status", "Check"}; | ||
return op < 3 ? data[op] : "Unknown operation"; | ||
} | ||
} | ||
|
||
/** Manage query | ||
*/ | ||
class ASTManageQuery : public IAST | ||
{ | ||
public: | ||
String database; | ||
String table; | ||
|
||
ManageOperation::Enum operation; | ||
|
||
/** Get the text that identifies this element. */ | ||
String getID() const override | ||
{ | ||
return "ManageQuery_" + database + "_" + table + "_" + ManageOperation::toString(operation); | ||
}; | ||
|
||
ASTPtr clone() const override | ||
{ | ||
auto res = std::make_shared<ASTManageQuery>(*this); | ||
res->children.clear(); | ||
return res; | ||
} | ||
|
||
protected: | ||
void formatImpl(const FormatSettings & settings, FormatState & /*state*/, FormatStateStacked /*frame*/) const override | ||
{ | ||
settings.ostr << (settings.hilite ? hilite_keyword : "") << "MANAGE TABLE " << (settings.hilite ? hilite_none : "") | ||
<< (!database.empty() ? backQuoteIfNeed(database) + "." : "") << backQuoteIfNeed(table) << " " | ||
<< (settings.hilite ? hilite_keyword : "") << ManageOperation::toString(operation) | ||
<< (settings.hilite ? hilite_none : ""); | ||
} | ||
}; | ||
} |
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,61 @@ | ||
#include <Parsers/CommonParsers.h> | ||
#include <Parsers/ParserManageQuery.h> | ||
#include <Parsers/ParserPartition.h> | ||
|
||
#include <Parsers/ASTIdentifier.h> | ||
#include <Parsers/ASTLiteral.h> | ||
#include <Parsers/ASTManageQuery.h> | ||
|
||
#include <Common/typeid_cast.h> | ||
|
||
|
||
namespace DB | ||
{ | ||
bool ParserManageQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) | ||
{ | ||
ParserKeyword s_manage_table("MANAGE TABLE"); | ||
ParserKeyword s_flush("FLUSH"); | ||
ParserKeyword s_status("STATUS"); | ||
ParserKeyword s_check("CHECK"); | ||
|
||
ParserToken s_dot(TokenType::Dot); | ||
ParserIdentifier name_p; | ||
ASTPtr database; | ||
ASTPtr table; | ||
ManageOperation::Enum operation; | ||
|
||
if (!s_manage_table.ignore(pos, expected)) | ||
return false; | ||
|
||
if (!name_p.parse(pos, table, expected)) | ||
return false; | ||
|
||
if (s_dot.ignore(pos, expected)) | ||
{ | ||
database = table; | ||
if (!name_p.parse(pos, table, expected)) | ||
return false; | ||
} | ||
|
||
if (s_flush.ignore(pos, expected)) | ||
operation = ManageOperation::Enum::Flush; | ||
else if (s_status.ignore(pos, expected)) | ||
operation = ManageOperation::Enum::Status; | ||
else if (s_check.ignore(pos, expected)) | ||
operation = ManageOperation::Enum::Check; | ||
else | ||
return false; | ||
|
||
auto query = std::make_shared<ASTManageQuery>(); | ||
node = query; | ||
|
||
if (database) | ||
query->database = typeid_cast<const ASTIdentifier &>(*database).name; | ||
if (table) | ||
query->table = typeid_cast<const ASTIdentifier &>(*table).name; | ||
|
||
query->operation = operation; | ||
|
||
return true; | ||
} | ||
} |
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,17 @@ | ||
#pragma once | ||
|
||
#include <Parsers/IParserBase.h> | ||
#include <Parsers/ExpressionElementParsers.h> | ||
|
||
|
||
namespace DB | ||
{ | ||
|
||
class ParserManageQuery : public IParserBase | ||
{ | ||
protected: | ||
const char * getName() const { return "MANAGE query"; } | ||
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected); | ||
}; | ||
|
||
} |
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
Oops, something went wrong.