Merge pull request #69253 from ClickHouse/restore-replace-to-null-settings-fix

Restore external tables to Null supports no settings
This commit is contained in:
Ilya Yatsishin 2024-09-12 10:40:54 +00:00 committed by GitHub
commit 98ef5f6e10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 0 deletions

View File

@ -1060,6 +1060,11 @@ namespace
void setNullTableEngine(ASTStorage & storage)
{
storage.forEachPointerToChild([](void ** ptr) mutable
{
*ptr = nullptr;
});
auto engine_ast = std::make_shared<ASTFunction>();
engine_ast->name = "Null";
engine_ast->no_empty_args = true;
@ -1146,8 +1151,10 @@ void InterpreterCreateQuery::setEngine(ASTCreateQuery & create) const
else if (getContext()->getSettingsRef().restore_replace_external_engines_to_null)
{
if (StorageFactory::instance().getStorageFeatures(create.storage->engine->name).source_access_type != AccessType::NONE)
{
setNullTableEngine(*create.storage);
}
}
return;
}

View File

@ -70,6 +70,12 @@ def get_mysql_conn(cluster):
def fill_tables(cluster, dbname):
fill_nodes(nodes, dbname)
node1.query(
f"""CREATE TABLE {dbname}.example_s3_engine_table (name String, value UInt32)
ENGINE = S3('https://clickhouse-public-datasets.s3.amazonaws.com/my-test-bucket-768/test-data.csv.gz', 'CSV', 'gzip')
SETTINGS input_format_with_names_use_header = 0"""
)
conn = get_mysql_conn(cluster)
with conn.cursor() as cursor:
@ -136,6 +142,7 @@ def test_restore_table(start_cluster):
node2.query(f"BACKUP DATABASE replicated TO {backup_name}")
node2.query("DROP TABLE replicated.example_s3_engine_table")
node2.query("DROP TABLE replicated.mysql_schema_inference_engine")
node2.query("DROP TABLE replicated.mysql_schema_inference_function")
@ -149,6 +156,13 @@ def test_restore_table(start_cluster):
)
node1.query(f"SYSTEM SYNC DATABASE REPLICA replicated")
assert (
node1.query(
"SELECT engine FROM system.tables where database = 'replicated' and name = 'example_s3_engine_table'"
)
== "S3\n"
)
assert (
node1.query(
"SELECT count(), sum(id) FROM replicated.mysql_schema_inference_engine"
@ -175,6 +189,7 @@ def test_restore_table_null(start_cluster):
node2.query(f"BACKUP DATABASE replicated2 TO {backup_name}")
node2.query("DROP TABLE replicated2.example_s3_engine_table")
node2.query("DROP TABLE replicated2.mysql_schema_inference_engine")
node2.query("DROP TABLE replicated2.mysql_schema_inference_function")
@ -188,6 +203,13 @@ def test_restore_table_null(start_cluster):
)
node1.query(f"SYSTEM SYNC DATABASE REPLICA replicated2")
assert (
node1.query(
"SELECT engine FROM system.tables where database = 'replicated2' and name = 'example_s3_engine_table'"
)
== "Null\n"
)
assert (
node1.query(
"SELECT count(), sum(id) FROM replicated2.mysql_schema_inference_engine"