ClickHouse/src/Storages/StorageLogSettings.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.3 KiB
C++
Raw Normal View History

#include "StorageLogSettings.h"
#include <Disks/StoragePolicy.h>
#include <Interpreters/Context.h>
#include <Parsers/ASTCreateQuery.h>
#include <Parsers/ASTSetQuery.h>
namespace DB
{
2023-02-11 13:58:19 +00:00
namespace ErrorCodes
{
extern const int INVALID_SETTING_VALUE;
}
String getDiskName(ASTStorage & storage_def, ContextPtr context)
{
if (storage_def.settings)
{
SettingsChanges changes = storage_def.settings->changes;
2023-02-11 13:58:19 +00:00
const auto disk_change
= std::find_if(changes.begin(), changes.end(), [&](const SettingChange & change) { return change.name == "disk"; });
const auto storage_policy_change
= std::find_if(changes.begin(), changes.end(), [&](const SettingChange & change) { return change.name == "storage_policy"; });
if (disk_change != changes.end() && storage_policy_change != changes.end())
throw Exception(
ErrorCodes::INVALID_SETTING_VALUE, "Could not specify `disk` and `storage_policy` at the same time for storage Log Family");
if (disk_change != changes.end())
return disk_change->value.safeGet<String>();
if (storage_policy_change != changes.end())
{
2023-02-11 13:58:19 +00:00
auto policy = context->getStoragePolicy(storage_policy_change->value.safeGet<String>());
return policy->getDisks()[0]->getName();
}
}
2023-02-11 13:58:19 +00:00
return "default";
}
}