1 | #include <Storages/System/StorageSystemSettings.h> |
2 | #include <DataTypes/DataTypeString.h> |
3 | #include <DataTypes/DataTypeNullable.h> |
4 | #include <DataTypes/DataTypesNumber.h> |
5 | #include <Interpreters/Context.h> |
6 | #include <Access/SettingsConstraints.h> |
7 | |
8 | |
9 | namespace DB |
10 | { |
11 | NamesAndTypesList StorageSystemSettings::getNamesAndTypes() |
12 | { |
13 | return { |
14 | {"name" , std::make_shared<DataTypeString>()}, |
15 | {"value" , std::make_shared<DataTypeString>()}, |
16 | {"changed" , std::make_shared<DataTypeUInt8>()}, |
17 | {"description" , std::make_shared<DataTypeString>()}, |
18 | {"min" , std::make_shared<DataTypeNullable>(std::make_shared<DataTypeString>())}, |
19 | {"max" , std::make_shared<DataTypeNullable>(std::make_shared<DataTypeString>())}, |
20 | {"readonly" , std::make_shared<DataTypeUInt8>()} |
21 | }; |
22 | } |
23 | |
24 | #ifndef __clang__ |
25 | #pragma GCC optimize("-fno-var-tracking-assignments") |
26 | #endif |
27 | |
28 | void StorageSystemSettings::fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo &) const |
29 | { |
30 | const Settings & settings = context.getSettingsRef(); |
31 | auto settings_constraints = context.getSettingsConstraints(); |
32 | for (const auto & setting : settings) |
33 | { |
34 | StringRef setting_name = setting.getName(); |
35 | res_columns[0]->insert(setting_name.toString()); |
36 | res_columns[1]->insert(setting.getValueAsString()); |
37 | res_columns[2]->insert(setting.isChanged()); |
38 | res_columns[3]->insert(setting.getDescription().toString()); |
39 | |
40 | Field min, max; |
41 | bool read_only = false; |
42 | if (settings_constraints) |
43 | settings_constraints->get(setting_name, min, max, read_only); |
44 | |
45 | /// These two columns can accept strings only. |
46 | if (!min.isNull()) |
47 | min = Settings::valueToString(setting_name, min); |
48 | if (!max.isNull()) |
49 | max = Settings::valueToString(setting_name, max); |
50 | |
51 | if (!read_only) |
52 | { |
53 | if ((settings.readonly == 1) |
54 | || ((settings.readonly > 1) && (setting_name == "readonly" )) |
55 | || ((!settings.allow_ddl) && (setting_name == "allow_ddl" ))) |
56 | read_only = true; |
57 | } |
58 | |
59 | res_columns[4]->insert(min); |
60 | res_columns[5]->insert(max); |
61 | res_columns[6]->insert(read_only); |
62 | } |
63 | } |
64 | |
65 | } |
66 | |