fix: attach table normalizer, add test

This commit is contained in:
liyang830 2022-06-17 16:42:05 +08:00
parent b2e2b4cce7
commit f091c8d1d8
5 changed files with 48 additions and 3 deletions

View File

@ -107,7 +107,6 @@ void DatabaseOrdinary::loadStoredObjects(
const auto & name = name_with_path_and_query.first;
const auto & path = name_with_path_and_query.second.path;
const auto & ast = name_with_path_and_query.second.ast;
FunctionNameNormalizer().visit(ast.get());
const auto & create_query = ast->as<const ASTCreateQuery &>();
if (create_query.is_dictionary)
@ -170,7 +169,6 @@ void DatabaseOrdinary::loadTablesMetadata(ContextPtr local_context, ParsedTables
auto ast = parseQueryFromMetadata(log, getContext(), full_path.string(), /*throw_on_error*/ true, /*remove_empty*/ false);
if (ast)
{
FunctionNameNormalizer().visit(ast.get());
auto * create_query = ast->as<ASTCreateQuery>();
create_query->setDatabase(database_name);
@ -224,7 +222,6 @@ void DatabaseOrdinary::loadTablesMetadata(ContextPtr local_context, ParsedTables
void DatabaseOrdinary::loadTableFromMetadata(ContextMutablePtr local_context, const String & file_path, const QualifiedTableName & name, const ASTPtr & ast, bool force_restore)
{
assert(name.database == database_name);
FunctionNameNormalizer().visit(ast.get());
const auto & create_query = ast->as<const ASTCreateQuery &>();
tryAttachTable(

View File

@ -953,6 +953,7 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create)
// Table SQL definition is available even if the table is detached (even permanently)
auto query = database->getCreateTableQuery(create.getTable(), getContext());
FunctionNameNormalizer().visit(query.get());
auto create_query = query->as<ASTCreateQuery &>();
if (!create.is_dictionary && create_query.is_dictionary)

View File

@ -0,0 +1,4 @@
<clickhouse>
<max_table_size_to_drop>1</max_table_size_to_drop>
<max_partition_size_to_drop>1</max_partition_size_to_drop>
</clickhouse>

View File

@ -0,0 +1,43 @@
import pytest
from helpers.cluster import ClickHouseCluster
cluster = ClickHouseCluster(__file__)
node = cluster.add_instance('node', main_configs=["configs/config.xml"], with_zookeeper=True)
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
def replace_substring_to_substr(node):
node.exec_in_container(["bash", "-c", "sed -i 's/substring/substr/g' /var/lib/clickhouse/metadata/default/file.sql"], user="root")
@pytest.mark.parametrize("engine", ['Ordinary', 'Atomic'])
def test_attach_substr(started_cluster, engine):
# Initialize
node.query("CREATE TABLE default.file(`s` String, `n` UInt8) ENGINE = MergeTree PARTITION BY substring(s, 1, 2) ORDER BY n ")
# Detach table file
node.query("DETACH TABLE file")
# Replace subtring to substr
replace_substring_to_substr(node)
# Attach table file
node.query("ATTACH TABLE file")
@pytest.mark.parametrize("engine", ['Ordinary', 'Atomic'])
def test_attach_substr(started_cluster, engine):
# Initialize
node.query("CREATE TABLE default.file(`s` String, `n` UInt8) ENGINE = MergeTree PARTITION BY substring(s, 1, 2) ORDER BY n ")
# Replace subtring to substr
replace_substring_to_substr(node)
# Restart clickhouse
node.restart_clickhouse(kill=True)