1 | #include <Storages/MergeTree/MergeTreeSettings.h> |
2 | #include <Poco/Util/AbstractConfiguration.h> |
3 | #include <Parsers/ASTCreateQuery.h> |
4 | #include <Parsers/ASTSetQuery.h> |
5 | #include <Parsers/ASTFunction.h> |
6 | #include <Common/Exception.h> |
7 | #include <Core/SettingsCollectionImpl.h> |
8 | |
9 | |
10 | namespace DB |
11 | { |
12 | |
13 | namespace ErrorCodes |
14 | { |
15 | extern const int INVALID_CONFIG_PARAMETER; |
16 | extern const int BAD_ARGUMENTS; |
17 | extern const int UNKNOWN_SETTING; |
18 | } |
19 | |
20 | IMPLEMENT_SETTINGS_COLLECTION(MergeTreeSettings, LIST_OF_MERGE_TREE_SETTINGS) |
21 | |
22 | void MergeTreeSettings::loadFromConfig(const String & config_elem, const Poco::Util::AbstractConfiguration & config) |
23 | { |
24 | if (!config.has(config_elem)) |
25 | return; |
26 | |
27 | Poco::Util::AbstractConfiguration::Keys config_keys; |
28 | config.keys(config_elem, config_keys); |
29 | |
30 | try |
31 | { |
32 | for (const String & key : config_keys) |
33 | set(key, config.getString(config_elem + "." + key)); |
34 | } |
35 | catch (Exception & e) |
36 | { |
37 | if (e.code() == ErrorCodes::UNKNOWN_SETTING) |
38 | throw Exception(e.message() + " in MergeTree config" , ErrorCodes::INVALID_CONFIG_PARAMETER); |
39 | else |
40 | e.rethrow(); |
41 | } |
42 | } |
43 | |
44 | void MergeTreeSettings::loadFromQuery(ASTStorage & storage_def) |
45 | { |
46 | if (storage_def.settings) |
47 | { |
48 | try |
49 | { |
50 | applyChanges(storage_def.settings->changes); |
51 | } |
52 | catch (Exception & e) |
53 | { |
54 | if (e.code() == ErrorCodes::UNKNOWN_SETTING) |
55 | throw Exception(e.message() + " for storage " + storage_def.engine->name, ErrorCodes::BAD_ARGUMENTS); |
56 | else |
57 | e.rethrow(); |
58 | } |
59 | } |
60 | else |
61 | { |
62 | auto settings_ast = std::make_shared<ASTSetQuery>(); |
63 | settings_ast->is_standalone = false; |
64 | storage_def.set(storage_def.settings, settings_ast); |
65 | } |
66 | |
67 | SettingsChanges & changes = storage_def.settings->changes; |
68 | |
69 | #define ADD_IF_ABSENT(NAME) \ |
70 | if (std::find_if(changes.begin(), changes.end(), \ |
71 | [](const SettingChange & c) { return c.name == #NAME; }) \ |
72 | == changes.end()) \ |
73 | changes.push_back(SettingChange{#NAME, NAME.value}); |
74 | |
75 | APPLY_FOR_IMMUTABLE_MERGE_TREE_SETTINGS(ADD_IF_ABSENT) |
76 | #undef ADD_IF_ABSENT |
77 | } |
78 | |
79 | } |
80 | |