2014-08-05 10:52:06 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-18 15:03:14 +00:00
|
|
|
#include <Parsers/ASTQueryWithTableAndOutput.h>
|
2019-10-08 18:42:22 +00:00
|
|
|
#include <Common/quoteString.h>
|
2019-07-08 19:55:54 +00:00
|
|
|
|
2014-08-05 10:52:06 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2023-10-24 12:50:24 +00:00
|
|
|
struct ASTCheckTableQuery : public ASTQueryWithTableAndOutput
|
2014-08-05 10:52:06 +00:00
|
|
|
{
|
2019-07-03 13:17:19 +00:00
|
|
|
ASTPtr partition;
|
2023-10-23 12:13:36 +00:00
|
|
|
String part_name;
|
2019-07-03 13:17:19 +00:00
|
|
|
|
2017-05-27 17:27:16 +00:00
|
|
|
/** Get the text that identifies this element. */
|
2021-09-06 22:13:54 +00:00
|
|
|
String getID(char delim) const override { return "CheckQuery" + (delim + getDatabase()) + delim + getTable(); }
|
2014-08-05 10:52:06 +00:00
|
|
|
|
2014-12-17 15:26:24 +00:00
|
|
|
ASTPtr clone() const override
|
2014-08-05 10:52:06 +00:00
|
|
|
{
|
2023-10-24 12:50:24 +00:00
|
|
|
auto res = std::make_shared<ASTCheckTableQuery>(*this);
|
2017-01-11 19:05:46 +00:00
|
|
|
res->children.clear();
|
|
|
|
cloneOutputOptions(*res);
|
2021-09-06 22:13:54 +00:00
|
|
|
cloneTableOptions(*res);
|
2017-01-11 19:05:46 +00:00
|
|
|
return res;
|
2014-08-05 10:52:06 +00:00
|
|
|
}
|
|
|
|
|
2023-02-02 01:11:16 +00:00
|
|
|
QueryKind getQueryKind() const override { return QueryKind::Check; }
|
|
|
|
|
2023-10-24 12:50:24 +00:00
|
|
|
std::variant<std::monostate, ASTPtr, String> getPartitionOrPartitionID() const
|
|
|
|
{
|
|
|
|
if (partition)
|
|
|
|
return partition;
|
|
|
|
if (!part_name.empty())
|
|
|
|
return part_name;
|
|
|
|
return std::monostate{};
|
|
|
|
}
|
|
|
|
|
2015-08-05 21:38:31 +00:00
|
|
|
protected:
|
2019-07-03 16:00:24 +00:00
|
|
|
void formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
|
2015-08-05 21:38:31 +00:00
|
|
|
{
|
|
|
|
std::string nl_or_nothing = settings.one_line ? "" : "\n";
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-08-05 21:38:31 +00:00
|
|
|
std::string indent_str = settings.one_line ? "" : std::string(4 * frame.indent, ' ');
|
|
|
|
std::string nl_or_ws = settings.one_line ? " " : "\n";
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-08-05 21:38:31 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << "CHECK TABLE " << (settings.hilite ? hilite_none : "");
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-11-11 13:28:18 +00:00
|
|
|
if (table)
|
2015-08-05 21:38:31 +00:00
|
|
|
{
|
2021-11-11 13:28:18 +00:00
|
|
|
if (database)
|
2015-08-05 21:38:31 +00:00
|
|
|
{
|
2024-02-19 07:15:28 +00:00
|
|
|
database->formatImpl(settings, state, frame);
|
|
|
|
settings.ostr << '.';
|
2015-08-05 21:38:31 +00:00
|
|
|
}
|
2024-02-19 07:15:28 +00:00
|
|
|
|
2024-03-08 20:27:56 +00:00
|
|
|
chassert(table);
|
2024-02-19 07:15:28 +00:00
|
|
|
table->formatImpl(settings, state, frame);
|
2015-08-05 21:38:31 +00:00
|
|
|
}
|
2019-07-03 16:00:24 +00:00
|
|
|
|
|
|
|
if (partition)
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << " PARTITION " << (settings.hilite ? hilite_none : "");
|
|
|
|
partition->formatImpl(settings, state, frame);
|
|
|
|
}
|
2015-08-05 21:38:31 +00:00
|
|
|
}
|
2014-08-05 10:52:06 +00:00
|
|
|
};
|
|
|
|
|
2023-10-24 12:50:24 +00:00
|
|
|
struct ASTCheckAllTablesQuery : public ASTQueryWithOutput
|
|
|
|
{
|
|
|
|
|
|
|
|
String getID(char /* delim */) const override { return "CheckAllQuery"; }
|
|
|
|
|
|
|
|
ASTPtr clone() const override
|
|
|
|
{
|
|
|
|
auto res = std::make_shared<ASTCheckAllTablesQuery>(*this);
|
|
|
|
res->children.clear();
|
|
|
|
cloneOutputOptions(*res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
QueryKind getQueryKind() const override { return QueryKind::Check; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void formatQueryImpl(const FormatSettings & settings, FormatState & /* state */, FormatStateStacked frame) const override
|
|
|
|
{
|
|
|
|
std::string nl_or_nothing = settings.one_line ? "" : "\n";
|
|
|
|
|
|
|
|
std::string indent_str = settings.one_line ? "" : std::string(4 * frame.indent, ' ');
|
|
|
|
std::string nl_or_ws = settings.one_line ? " " : "\n";
|
|
|
|
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << "CHECK ALL TABLES" << (settings.hilite ? hilite_none : "");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-05 10:52:06 +00:00
|
|
|
}
|