2019-12-05 11:42:13 +00:00
|
|
|
#pragma once
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/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-10-26 15:49:00 +00:00
|
|
|
class ASTTableIdentifier;
|
2020-02-17 19:28:25 +00:00
|
|
|
class Context;
|
|
|
|
|
2020-12-04 02:15:44 +00:00
|
|
|
// TODO(ilezhankin): refactor and merge |ASTTableIdentifier|
|
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);
|
2020-10-26 15:49:00 +00:00
|
|
|
StorageID(const ASTTableIdentifier & table_identifier_node);
|
2020-03-13 10:30:55 +00:00
|
|
|
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
|
|
|
|
2021-06-06 22:52:36 +00:00
|
|
|
explicit 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;
|
2021-06-06 22:55:37 +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.
|
2021-03-19 12:47:27 +00:00
|
|
|
/// ExternalDictnariesLoader::resolveDictionaryName(...) should be used to access such dictionaries by name.
|
2021-10-13 20:47:28 +00:00
|
|
|
String getInternalDictionaryName() const { return getShortName(); }
|
|
|
|
/// Get short, but unique, name.
|
|
|
|
String getShortName() const;
|
2020-07-15 19:25:31 +00:00
|
|
|
|
2019-12-30 18:20:43 +00:00
|
|
|
private:
|
|
|
|
StorageID() = default;
|
2019-12-05 11:42:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|