mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Fix filling table system.settings_profile_elements.
This commit is contained in:
parent
30c98adde4
commit
9e31800ebb
@ -67,15 +67,74 @@ void StorageSystemSettingsProfileElements::fillData(MutableColumns & res_columns
|
||||
auto & column_inherit_profile_null_map = assert_cast<ColumnNullable &>(*res_columns[i++]).getNullMapData();
|
||||
|
||||
auto add_rows_for_single_element = [&](const String & owner_name, EntityType owner_type, const SettingsProfileElement & element, size_t & index)
|
||||
{
|
||||
size_t old_num_rows = column_profile_name.size();
|
||||
size_t new_num_rows = old_num_rows + 1;
|
||||
size_t current_index = index++;
|
||||
|
||||
bool inserted_value = false;
|
||||
if (!element.value.isNull() && !element.setting_name.empty())
|
||||
{
|
||||
String str = Settings::valueToStringUtil(element.setting_name, element.value);
|
||||
column_value.insertData(str.data(), str.length());
|
||||
column_value_null_map.push_back(false);
|
||||
inserted_value = true;
|
||||
}
|
||||
|
||||
bool inserted_min = false;
|
||||
if (!element.min_value.isNull() && !element.setting_name.empty())
|
||||
{
|
||||
String str = Settings::valueToStringUtil(element.setting_name, element.min_value);
|
||||
column_min.insertData(str.data(), str.length());
|
||||
column_min_null_map.push_back(false);
|
||||
inserted_min = true;
|
||||
}
|
||||
|
||||
bool inserted_max = false;
|
||||
if (!element.max_value.isNull() && !element.setting_name.empty())
|
||||
{
|
||||
String str = Settings::valueToStringUtil(element.setting_name, element.max_value);
|
||||
column_max.insertData(str.data(), str.length());
|
||||
column_max_null_map.push_back(false);
|
||||
inserted_max = true;
|
||||
}
|
||||
|
||||
bool inserted_readonly = false;
|
||||
if (element.readonly && !element.setting_name.empty())
|
||||
{
|
||||
column_readonly.push_back(*element.readonly);
|
||||
column_readonly_null_map.push_back(false);
|
||||
inserted_readonly = true;
|
||||
}
|
||||
|
||||
bool inserted_setting_name = false;
|
||||
if (inserted_value || inserted_min || inserted_max || inserted_readonly)
|
||||
{
|
||||
const auto & setting_name = element.setting_name;
|
||||
column_setting_name.insertData(setting_name.data(), setting_name.size());
|
||||
column_setting_name_null_map.push_back(false);
|
||||
inserted_setting_name = true;
|
||||
}
|
||||
|
||||
bool inserted_inherit_profile = false;
|
||||
if (element.parent_profile)
|
||||
{
|
||||
auto parent_profile = access_control.tryReadName(*element.parent_profile);
|
||||
if (parent_profile)
|
||||
{
|
||||
const String & parent_profile_str = *parent_profile;
|
||||
column_inherit_profile.insertData(parent_profile_str.data(), parent_profile_str.length());
|
||||
column_inherit_profile_null_map.push_back(false);
|
||||
inserted_inherit_profile = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (inserted_setting_name || inserted_inherit_profile)
|
||||
{
|
||||
switch (owner_type)
|
||||
{
|
||||
case EntityType::SETTINGS_PROFILE:
|
||||
{
|
||||
column_user_name.insertDefault();
|
||||
column_user_name_null_map.push_back(true);
|
||||
column_role_name.insertDefault();
|
||||
column_role_name_null_map.push_back(true);
|
||||
column_profile_name.insertData(owner_name.data(), owner_name.length());
|
||||
column_profile_name_null_map.push_back(false);
|
||||
break;
|
||||
@ -84,105 +143,22 @@ void StorageSystemSettingsProfileElements::fillData(MutableColumns & res_columns
|
||||
{
|
||||
column_user_name.insertData(owner_name.data(), owner_name.length());
|
||||
column_user_name_null_map.push_back(false);
|
||||
column_profile_name.insertDefault();
|
||||
column_profile_name_null_map.push_back(true);
|
||||
column_role_name.insertDefault();
|
||||
column_role_name_null_map.push_back(true);
|
||||
break;
|
||||
}
|
||||
case EntityType::ROLE:
|
||||
{
|
||||
column_user_name.insertDefault();
|
||||
column_user_name_null_map.push_back(true);
|
||||
column_role_name.insertData(owner_name.data(), owner_name.length());
|
||||
column_role_name_null_map.push_back(false);
|
||||
column_profile_name.insertDefault();
|
||||
column_profile_name_null_map.push_back(true);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
if (element.parent_profile)
|
||||
{
|
||||
auto parent_profile = access_control.tryReadName(*element.parent_profile);
|
||||
if (parent_profile)
|
||||
{
|
||||
column_index.push_back(index++);
|
||||
column_setting_name.insertDefault();
|
||||
column_setting_name_null_map.push_back(true);
|
||||
column_value.insertDefault();
|
||||
column_value_null_map.push_back(true);
|
||||
column_min.insertDefault();
|
||||
column_min_null_map.push_back(true);
|
||||
column_max.insertDefault();
|
||||
column_max_null_map.push_back(true);
|
||||
column_readonly.push_back(0);
|
||||
column_readonly_null_map.push_back(true);
|
||||
const String & parent_profile_str = *parent_profile;
|
||||
column_inherit_profile.insertData(parent_profile_str.data(), parent_profile_str.length());
|
||||
column_inherit_profile_null_map.push_back(false);
|
||||
}
|
||||
}
|
||||
column_index.push_back(current_index);
|
||||
|
||||
if (!element.setting_name.empty()
|
||||
&& (!element.value.isNull() || !element.min_value.isNull() || !element.max_value.isNull() || element.readonly))
|
||||
{
|
||||
const auto & setting_name = element.setting_name;
|
||||
column_index.push_back(index++);
|
||||
column_setting_name.insertData(setting_name.data(), setting_name.size());
|
||||
column_setting_name_null_map.push_back(false);
|
||||
|
||||
if (element.value.isNull())
|
||||
{
|
||||
column_value.insertDefault();
|
||||
column_value_null_map.push_back(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
String str = Settings::valueToStringUtil(setting_name, element.value);
|
||||
column_value.insertData(str.data(), str.length());
|
||||
column_value_null_map.push_back(false);
|
||||
}
|
||||
|
||||
if (element.min_value.isNull())
|
||||
{
|
||||
column_min.insertDefault();
|
||||
column_min_null_map.push_back(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
String str = Settings::valueToStringUtil(setting_name, element.min_value);
|
||||
column_min.insertData(str.data(), str.length());
|
||||
column_min_null_map.push_back(false);
|
||||
}
|
||||
|
||||
if (element.max_value.isNull())
|
||||
{
|
||||
column_max.insertDefault();
|
||||
column_max_null_map.push_back(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
String str = Settings::valueToStringUtil(setting_name, element.max_value);
|
||||
column_max.insertData(str.data(), str.length());
|
||||
column_max_null_map.push_back(false);
|
||||
}
|
||||
|
||||
if (element.readonly)
|
||||
{
|
||||
column_readonly.push_back(*element.readonly);
|
||||
column_readonly_null_map.push_back(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
column_readonly.push_back(0);
|
||||
column_readonly_null_map.push_back(true);
|
||||
}
|
||||
|
||||
column_inherit_profile.insertDefault();
|
||||
column_inherit_profile_null_map.push_back(true);
|
||||
for (auto & res_column : res_columns)
|
||||
res_column->insertManyDefaults(new_num_rows - res_column->size());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -0,0 +1,2 @@
|
||||
\N test_01605 \N 0 \N \N \N \N \N test_01605
|
||||
PROFILE DROPPED
|
@ -0,0 +1,8 @@
|
||||
CREATE USER OR REPLACE 'test_01605';
|
||||
CREATE SETTINGS PROFILE OR REPLACE 'test_01605';
|
||||
ALTER USER 'test_01605' SETTINGS PROFILE 'test_01605';
|
||||
SELECT * FROM system.settings_profile_elements WHERE user_name='test_01605' OR profile_name='test_01605';
|
||||
DROP SETTINGS PROFILE 'test_01605';
|
||||
SELECT 'PROFILE DROPPED';
|
||||
SELECT * FROM system.settings_profile_elements WHERE user_name='test_01605' OR profile_name='test_01605';
|
||||
DROP USER 'test_01605';
|
Loading…
Reference in New Issue
Block a user