mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-17 13:13:36 +00:00
Refactor
This commit is contained in:
parent
bdbfa24048
commit
2421cf29de
@ -201,6 +201,39 @@ String ASTTableIdentifier::getDatabaseName() const
|
|||||||
else return {};
|
else return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASTPtr ASTTableIdentifier::getTable() const
|
||||||
|
{
|
||||||
|
if (name_parts.size() == 2)
|
||||||
|
{
|
||||||
|
if (!name_parts[1].empty())
|
||||||
|
return std::make_shared<ASTIdentifier>(name_parts[1]);
|
||||||
|
|
||||||
|
if (name_parts[0].empty())
|
||||||
|
return std::make_shared<ASTIdentifier>("", children[1]->clone());
|
||||||
|
else
|
||||||
|
return std::make_shared<ASTIdentifier>("", children[0]->clone());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (name_parts[0].empty())
|
||||||
|
return std::make_shared<ASTIdentifier>("", children[0]->clone());
|
||||||
|
else
|
||||||
|
return std::make_shared<ASTIdentifier>(name_parts[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ASTPtr ASTTableIdentifier::getDatabase() const
|
||||||
|
{
|
||||||
|
if (name_parts.size() == 2)
|
||||||
|
{
|
||||||
|
if (name_parts[0].empty())
|
||||||
|
return std::make_shared<ASTIdentifier>("", children[0]->clone());
|
||||||
|
else
|
||||||
|
return std::make_shared<ASTIdentifier>(name_parts[0]);
|
||||||
|
}
|
||||||
|
else return {};
|
||||||
|
}
|
||||||
|
|
||||||
void ASTTableIdentifier::resetTable(const String & database_name, const String & table_name)
|
void ASTTableIdentifier::resetTable(const String & database_name, const String & table_name)
|
||||||
{
|
{
|
||||||
auto identifier = std::make_shared<ASTTableIdentifier>(database_name, table_name);
|
auto identifier = std::make_shared<ASTTableIdentifier>(database_name, table_name);
|
||||||
|
@ -61,6 +61,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
using ASTWithAlias::children; /// ASTIdentifier is child free
|
using ASTWithAlias::children; /// ASTIdentifier is child free
|
||||||
|
|
||||||
|
friend class ASTTableIdentifier;
|
||||||
friend class ReplaceQueryParameterVisitor;
|
friend class ReplaceQueryParameterVisitor;
|
||||||
friend struct IdentifierSemantic;
|
friend struct IdentifierSemantic;
|
||||||
friend void setIdentifierSpecial(ASTPtr & ast);
|
friend void setIdentifierSpecial(ASTPtr & ast);
|
||||||
@ -83,6 +84,9 @@ public:
|
|||||||
StorageID getTableId() const;
|
StorageID getTableId() const;
|
||||||
String getDatabaseName() const;
|
String getDatabaseName() const;
|
||||||
|
|
||||||
|
ASTPtr getTable() const;
|
||||||
|
ASTPtr getDatabase() const;
|
||||||
|
|
||||||
// FIXME: used only when it's needed to rewrite distributed table name to real remote table name.
|
// FIXME: used only when it's needed to rewrite distributed table name to real remote table name.
|
||||||
void resetTable(const String & database_name, const String & table_name); // TODO(ilezhankin): get rid of this
|
void resetTable(const String & database_name, const String & table_name); // TODO(ilezhankin): get rid of this
|
||||||
|
|
||||||
|
@ -45,18 +45,6 @@ protected:
|
|||||||
return query_ptr;
|
return query_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
static ASTPtr removeOnClusterSystem(ASTPtr query_ptr, const std::string & new_database)
|
|
||||||
{
|
|
||||||
T & query = static_cast<T &>(*query_ptr);
|
|
||||||
|
|
||||||
query.cluster.clear();
|
|
||||||
if (query.database.empty())
|
|
||||||
query.database = new_database;
|
|
||||||
|
|
||||||
return query_ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static ASTPtr removeOnCluster(ASTPtr query_ptr)
|
static ASTPtr removeOnCluster(ASTPtr query_ptr)
|
||||||
{
|
{
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include <Parsers/ASTIdentifier.h>
|
||||||
#include <Parsers/ASTQueryWithTableAndOutput.h>
|
#include <Parsers/ASTQueryWithTableAndOutput.h>
|
||||||
#include <Common/quoteString.h>
|
#include <Common/quoteString.h>
|
||||||
#include <IO/Operators.h>
|
#include <IO/Operators.h>
|
||||||
@ -6,6 +7,49 @@
|
|||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
|
|
||||||
|
String ASTQueryWithTableAndOutput::getDatabase() const
|
||||||
|
{
|
||||||
|
String name;
|
||||||
|
tryGetIdentifierNameInto(database, name);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
String ASTQueryWithTableAndOutput::getTable() const
|
||||||
|
{
|
||||||
|
String name;
|
||||||
|
tryGetIdentifierNameInto(table, name);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ASTQueryWithTableAndOutput::setDatabase(const String & name)
|
||||||
|
{
|
||||||
|
if (name.empty())
|
||||||
|
database.reset();
|
||||||
|
else
|
||||||
|
database = std::make_shared<ASTIdentifier>(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ASTQueryWithTableAndOutput::setTable(const String & name)
|
||||||
|
{
|
||||||
|
if (name.empty())
|
||||||
|
table.reset();
|
||||||
|
else
|
||||||
|
table = std::make_shared<ASTIdentifier>(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ASTQueryWithTableAndOutput::cloneTableOptions(ASTQueryWithTableAndOutput & cloned) const
|
||||||
|
{
|
||||||
|
if (database)
|
||||||
|
{
|
||||||
|
cloned.database = database->clone();
|
||||||
|
cloned.children.push_back(cloned.database);
|
||||||
|
}
|
||||||
|
if (table)
|
||||||
|
{
|
||||||
|
cloned.table = table->clone();
|
||||||
|
cloned.children.push_back(cloned.table);
|
||||||
|
}
|
||||||
|
}
|
||||||
void ASTQueryWithTableAndOutput::formatHelper(const FormatSettings & settings, const char * name) const
|
void ASTQueryWithTableAndOutput::formatHelper(const FormatSettings & settings, const char * name) const
|
||||||
{
|
{
|
||||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << name << " " << (settings.hilite ? hilite_none : "");
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << name << " " << (settings.hilite ? hilite_none : "");
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include <Parsers/IAST.h>
|
#include <Parsers/IAST.h>
|
||||||
#include <Parsers/ASTQueryWithOutput.h>
|
#include <Parsers/ASTQueryWithOutput.h>
|
||||||
#include <Parsers/ASTIdentifier.h>
|
|
||||||
#include <Core/UUID.h>
|
#include <Core/UUID.h>
|
||||||
|
|
||||||
|
|
||||||
@ -21,50 +20,13 @@ public:
|
|||||||
UUID uuid = UUIDHelpers::Nil;
|
UUID uuid = UUIDHelpers::Nil;
|
||||||
bool temporary{false};
|
bool temporary{false};
|
||||||
|
|
||||||
|
String getDatabase() const;
|
||||||
|
String getTable() const;
|
||||||
|
|
||||||
String getDatabase() const
|
void setDatabase(const String & name);
|
||||||
{
|
void setTable(const String & name);
|
||||||
String name;
|
|
||||||
tryGetIdentifierNameInto(database, name);
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getTable() const
|
void cloneTableOptions(ASTQueryWithTableAndOutput & cloned) const;
|
||||||
{
|
|
||||||
String name;
|
|
||||||
tryGetIdentifierNameInto(table, name);
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDatabase(const String & name)
|
|
||||||
{
|
|
||||||
if (name.empty())
|
|
||||||
database.reset();
|
|
||||||
else
|
|
||||||
database = std::make_shared<ASTIdentifier>(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setTable(const String & name)
|
|
||||||
{
|
|
||||||
if (name.empty())
|
|
||||||
table.reset();
|
|
||||||
else
|
|
||||||
table = std::make_shared<ASTIdentifier>(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cloneTableOptions(ASTQueryWithTableAndOutput & cloned) const
|
|
||||||
{
|
|
||||||
if (database)
|
|
||||||
{
|
|
||||||
cloned.database = database->clone();
|
|
||||||
cloned.children.push_back(cloned.database);
|
|
||||||
}
|
|
||||||
if (table)
|
|
||||||
{
|
|
||||||
cloned.table = table->clone();
|
|
||||||
cloned.children.push_back(cloned.table);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void formatHelper(const FormatSettings & settings, const char * name) const;
|
void formatHelper(const FormatSettings & settings, const char * name) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user