Skip to content

Commit 5556274

Browse files
Review
1 parent e8e4f52 commit 5556274

File tree

7 files changed

+18
-20
lines changed

7 files changed

+18
-20
lines changed

src/Common/NamedCollections/NamedCollections.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,6 @@ class NamedCollection::Impl
175175
}
176176
};
177177

178-
String NamedCollection::sourceIdToString(NamedCollection::SourceId id)
179-
{
180-
switch (id)
181-
{
182-
case NamedCollection::SourceId::NONE: return "NONE";
183-
case NamedCollection::SourceId::CONFIG: return "CONFIG";
184-
case NamedCollection::SourceId::SQL: return "SQL";
185-
}
186-
}
187-
188178
NamedCollection::NamedCollection(
189179
ImplPtr pimpl_,
190180
const std::string & collection_name_,
@@ -345,7 +335,7 @@ NamedCollectionFromConfig::NamedCollectionFromConfig(
345335
const std::string & collection_name_,
346336
const std::string & collection_path_,
347337
const Keys & keys_)
348-
: NamedCollection(Impl::create(config_, collection_name_, collection_path_, keys_), collection_name_, false)
338+
: NamedCollection(Impl::create(config_, collection_name_, collection_path_, keys_), collection_name_, /* is_mutable */ false)
349339
{
350340
}
351341

src/Common/NamedCollections/NamedCollections.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ class NamedCollection
2727
using Keys = std::set<Key, std::less<>>;
2828
enum class SourceId : uint8_t
2929
{
30+
/// None source_id is possible only if the object is a
31+
/// duplicate of some named collection. See `duplicate` method.
3032
NONE = 0,
3133
CONFIG = 1,
3234
SQL = 2,
3335
};
3436

35-
static String sourceIdToString(SourceId id);
36-
3737
bool has(const Key & key) const;
3838

3939
bool hasAny(const std::initializer_list<Key> & keys) const;
@@ -76,7 +76,7 @@ class NamedCollection
7676

7777
virtual SourceId getSourceId() const { return SourceId::NONE; }
7878

79-
virtual String getCreateStatement(bool /*show_secrects*/) { return " "; }
79+
virtual String getCreateStatement(bool /*show_secrects*/) { return {}; }
8080

8181
virtual void update(const ASTAlterNamedCollectionQuery & query);
8282

@@ -127,7 +127,7 @@ class NamedCollectionFromConfig final : public NamedCollection
127127
const std::string & collection_path,
128128
const Keys & keys);
129129

130-
String getCreateStatement(bool /*show_secrects*/) override { return " "; }
130+
String getCreateStatement(bool /*show_secrects*/) override { return {}; }
131131

132132
void update(const ASTAlterNamedCollectionQuery & /*query*/) override { NamedCollection::assertMutable(); }
133133

src/Common/NamedCollections/NamedCollectionsFactory.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace ErrorCodes
1515
extern const int NAMED_COLLECTION_DOESNT_EXIST;
1616
extern const int NAMED_COLLECTION_ALREADY_EXISTS;
1717
extern const int NAMED_COLLECTION_IS_IMMUTABLE;
18+
extern const int LOGICAL_ERROR;
1819
}
1920

2021
NamedCollectionFactory & NamedCollectionFactory::instance()
@@ -335,7 +336,13 @@ void NamedCollectionFactory::updateFromSQL(const ASTAlterNamedCollectionQuery &
335336
auto updated_collection_ptr = metadata_storage->update(query);
336337

337338
auto it = loaded_named_collections.find(collection_name);
338-
chassert(it != loaded_named_collections.end());
339+
if (it == loaded_named_collections.end())
340+
{
341+
throw Exception(
342+
ErrorCodes::LOGICAL_ERROR,
343+
"The named collection {} unexpectedly does not exist.",
344+
collection_name);
345+
}
339346

340347
if (!it->second->isMutable())
341348
{

src/Common/NamedCollections/NamedCollectionsMetadataStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ ASTCreateNamedCollectionQuery NamedCollectionsMetadataStorage::readCreateQuery(c
524524
return create_query;
525525
}
526526

527-
void NamedCollectionsMetadataStorage::writeCreateQuery(const String& collection_name, const String& create_statement, bool replace)
527+
void NamedCollectionsMetadataStorage::writeCreateQuery(const String & collection_name, const String & create_statement, bool replace)
528528
{
529529
storage->write(getFileName(collection_name), create_statement, replace);
530530
}

src/Common/NamedCollections/NamedCollectionsMetadataStorage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class NamedCollectionsMetadataStorage : private WithContext
4646

4747
ASTCreateNamedCollectionQuery readCreateQuery(const std::string & collection_name) const;
4848

49-
void writeCreateQuery(const String& collection_name, const String& create_statement, bool replace = false);
49+
void writeCreateQuery(const String & collection_name, const String & create_statement, bool replace = false);
5050
};
5151

5252

src/Storages/System/StorageSystemNamedCollections.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "StorageSystemNamedCollections.h"
22

3+
#include <base/EnumReflection.h>
34
#include <Columns/ColumnArray.h>
45
#include <Columns/ColumnTuple.h>
56
#include <DataTypes/DataTypeString.h>
@@ -67,7 +68,7 @@ void StorageSystemNamedCollections::fillData(MutableColumns & res_columns, Conte
6768

6869
offsets.push_back(offsets.back() + size);
6970

70-
res_columns[2]->insert(NamedCollection::sourceIdToString(collection->getSourceId()));
71+
res_columns[2]->insert(magic_enum::enum_name(collection->getSourceId()));
7172
res_columns[3]->insert(collection->getCreateStatement(access_secrets));
7273
}
7374
}

tests/integration/test_named_collections/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ def validate_named_collection(collection_name, source, key_value):
842842
node.query(
843843
f"SELECT create_query FROM system.named_collections WHERE name='{collection_name}'"
844844
)
845-
== " \n"
845+
== "\n"
846846
)
847847
else:
848848
hidden_str = "\\'[HIDDEN]\\'"

0 commit comments

Comments
 (0)