ClickHouse/src/Interpreters/StorageID.h

99 lines
2.5 KiB
C++
Raw Normal View History

2019-12-05 11:42:13 +00:00
#pragma once
2020-09-15 09:55:57 +00:00
#include <common/types.h>
2019-12-27 19:30:22 +00:00
#include <Core/UUID.h>
2019-12-05 11:42:13 +00:00
#include <tuple>
2020-03-04 20:29:52 +00:00
#include <Parsers/IAST_fwd.h>
#include <Core/QualifiedTableName.h>
2020-03-13 10:30:55 +00:00
#include <Common/Exception.h>
2019-12-05 11:42:13 +00:00
2020-07-14 19:19:17 +00:00
namespace Poco
{
namespace Util
{
class AbstractConfiguration;
}
}
2019-12-05 11:42:13 +00:00
namespace DB
{
2020-03-13 10:30:55 +00:00
namespace ErrorCodes
{
2020-07-17 13:11:44 +00:00
extern const int UNKNOWN_TABLE;
2020-03-13 10:30:55 +00:00
}
2019-12-10 19:48:16 +00:00
static constexpr char const * TABLE_WITH_UUID_NAME_PLACEHOLDER = "_";
2020-02-17 19:28:25 +00:00
class ASTQueryWithTableAndOutput;
2020-03-13 10:30:55 +00:00
class ASTIdentifier;
2020-02-17 19:28:25 +00:00
class Context;
2019-12-05 11:42:13 +00:00
struct StorageID
{
String database_name;
String table_name;
2020-02-17 19:28:25 +00:00
UUID uuid = UUIDHelpers::Nil;
2019-12-05 11:42:13 +00:00
2020-02-17 19:28:25 +00:00
StorageID(const String & database, const String & table, UUID uuid_ = UUIDHelpers::Nil)
2020-03-13 10:30:55 +00:00
: database_name(database), table_name(table), uuid(uuid_)
2019-12-05 11:42:13 +00:00
{
2019-12-30 18:20:43 +00:00
assertNotEmpty();
}
2020-03-13 10:30:55 +00:00
StorageID(const ASTQueryWithTableAndOutput & query);
StorageID(const ASTIdentifier & table_identifier_node);
StorageID(const ASTPtr & node);
2020-03-04 20:29:52 +00:00
2020-03-06 20:38:19 +00:00
String getDatabaseName() const;
2019-12-30 18:20:43 +00:00
2020-03-13 10:30:55 +00:00
String getTableName() const;
2019-12-05 11:42:13 +00:00
2020-03-06 20:38:19 +00:00
String getFullTableName() const;
2020-07-15 19:25:31 +00:00
String getFullNameNotQuoted() const;
2019-12-05 11:42:13 +00:00
2020-02-17 19:28:25 +00:00
String getNameForLogs() const;
2019-12-30 18:20:43 +00:00
2020-03-13 15:41:36 +00:00
operator bool () const
2020-02-12 18:14:12 +00:00
{
return !empty();
}
2019-12-30 18:20:43 +00:00
bool empty() const
{
return table_name.empty() && !hasUUID();
}
bool hasUUID() const
{
2020-03-13 10:30:55 +00:00
return uuid != UUIDHelpers::Nil;
2019-12-05 11:42:13 +00:00
}
2020-02-17 19:28:25 +00:00
bool operator<(const StorageID & rhs) const;
2019-12-10 19:48:16 +00:00
2020-03-13 10:30:55 +00:00
void assertNotEmpty() const
{
2020-07-21 13:53:23 +00:00
// Can be triggered by user input, e.g. SELECT joinGetOrNull('', 'num', 500)
2020-03-13 10:30:55 +00:00
if (empty())
2020-07-17 13:11:44 +00:00
throw Exception("Both table name and UUID are empty", ErrorCodes::UNKNOWN_TABLE);
2020-03-13 10:30:55 +00:00
if (table_name.empty() && !database_name.empty())
2020-07-17 13:11:44 +00:00
throw Exception("Table name is empty, but database name is not", ErrorCodes::UNKNOWN_TABLE);
2020-03-13 10:30:55 +00:00
}
2019-12-27 19:30:22 +00:00
2019-12-30 18:20:43 +00:00
/// Avoid implicit construction of empty StorageID. However, it's needed for deferred initialization.
static StorageID createEmpty() { return {}; }
2020-03-11 19:10:55 +00:00
QualifiedTableName getQualifiedName() const { return {database_name, getTableName()}; }
2020-03-04 20:29:52 +00:00
2020-07-14 19:19:17 +00:00
static StorageID fromDictionaryConfig(const Poco::Util::AbstractConfiguration & config,
const String & config_prefix);
2020-07-17 13:11:44 +00:00
/// If dictionary has UUID, then use it as dictionary name in ExternalLoader to allow dictionary renaming.
/// DatabaseCatalog::resolveDictionaryName(...) should be used to access such dictionaries by name.
2020-07-15 19:25:31 +00:00
String getInternalDictionaryName() const;
2019-12-30 18:20:43 +00:00
private:
StorageID() = default;
2019-12-05 11:42:13 +00:00
};
}