ClickHouse/src/Parsers/ASTCheckQuery.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

96 lines
2.8 KiB
C++
Raw Normal View History

2014-08-05 10:52:06 +00:00
#pragma once
#include <Parsers/ASTQueryWithTableAndOutput.h>
#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. */
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);
res->children.clear();
cloneOutputOptions(*res);
cloneTableOptions(*res);
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{};
}
protected:
2019-07-03 16:00:24 +00:00
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 TABLE " << (settings.hilite ? hilite_none : "");
2021-11-11 13:28:18 +00:00
if (table)
{
2021-11-11 13:28:18 +00:00
if (database)
{
2024-02-19 07:15:28 +00:00
database->formatImpl(settings, state, frame);
settings.ostr << '.';
}
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);
}
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);
}
}
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
}