Storage Log faminy support settings storage policy

This commit is contained in:
flynn 2023-02-04 14:28:31 +00:00
parent 496cacf25e
commit a10f020b2d
6 changed files with 33 additions and 4 deletions

View File

@ -1104,7 +1104,7 @@ void registerStorageLog(StorageFactory & factory)
throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Engine {} doesn't support any arguments ({} given)",
args.engine_name, args.engine_args.size());
String disk_name = getDiskName(*args.storage_def);
String disk_name = getDiskName(*args.storage_def, args.getContext());
DiskPtr disk = args.getContext()->getDisk(disk_name);
return std::make_shared<StorageLog>(

View File

@ -1,17 +1,27 @@
#include "StorageLogSettings.h"
#include <Disks/StoragePolicy.h>
#include <Interpreters/Context.h>
#include <Parsers/ASTCreateQuery.h>
#include <Parsers/ASTSetQuery.h>
namespace DB
{
String getDiskName(ASTStorage & storage_def)
String getDiskName(ASTStorage & storage_def, ContextPtr context)
{
if (storage_def.settings)
{
SettingsChanges changes = storage_def.settings->changes;
for (const auto & change : changes)
{
/// How about both disk and storage_policy are specified?
if (change.name == "disk")
return change.value.safeGet<String>();
if (change.name == "storage_policy")
{
auto policy = context->getStoragePolicy(change.value.safeGet<String>());
return policy->getAnyDisk()->getName();
}
}
}
return "default";
}

View File

@ -5,6 +5,8 @@
namespace DB
{
class ASTStorage;
class Context;
using ContextPtr = std::shared_ptr<const Context>;
String getDiskName(ASTStorage & storage_def);
String getDiskName(ASTStorage & storage_def, ContextPtr context);
}

View File

@ -678,7 +678,7 @@ void registerStorageStripeLog(StorageFactory & factory)
throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Engine {} doesn't support any arguments ({} given)",
args.engine_name, args.engine_args.size());
String disk_name = getDiskName(*args.storage_def);
String disk_name = getDiskName(*args.storage_def, args.getContext());
DiskPtr disk = args.getContext()->getDisk(disk_name);
return std::make_shared<StorageStripeLog>(

View File

@ -0,0 +1,15 @@
DROP TABLE IF EXISTS test_2554_log;
CREATE TABLE test_2554_log (n UInt32) ENGINE = Log SETTINGS storage_policy = 'default';
INSERT INTO test_2554_log SELECT 1;
SELECT * FROM test_2554_log;
DROP TABLE test_2554_log;
DROP TABLE IF EXISTS test_2554_tinylog;
CREATE TABLE test_2554_tinylog (n UInt32) ENGINE = Log SETTINGS storage_policy = 'default';
INSERT INTO test_2554_tinylog SELECT 1;
SELECT * FROM test_2554_tinylog;
DROP TABLE test_2554_tinylog;