Merge pull request #27733 from Algunenano/i27620_take2

Refactor arrayJoin check on partition expressions
This commit is contained in:
Nikita Mikhaylov 2021-08-17 15:57:16 +03:00 committed by GitHub
commit cc8ad0a4e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 13 deletions

View File

@ -3207,16 +3207,6 @@ Pipe MergeTreeData::alterPartition(
return {};
}
void checkPartitionExpressionFunction(const ASTPtr & ast)
{
if (const auto * func = ast->as<ASTFunction>())
if (func->name == "arrayJoin")
throw Exception("The partition expression cannot contain array joins", ErrorCodes::INVALID_PARTITION_VALUE);
for (const auto & child : ast->children)
checkPartitionExpressionFunction(child);
}
String MergeTreeData::getPartitionIDFromQuery(const ASTPtr & ast, ContextPtr local_context) const
{
const auto & partition_ast = ast->as<ASTPartition &>();
@ -3227,9 +3217,6 @@ String MergeTreeData::getPartitionIDFromQuery(const ASTPtr & ast, ContextPtr loc
return partition_ast.id;
}
if (partition_ast.value->as<ASTFunction>())
checkPartitionExpressionFunction(ast);
if (format_version < MERGE_TREE_DATA_MIN_FORMAT_VERSION_WITH_CUSTOM_PARTITIONING)
{
/// Month-partitioning specific - partition ID can be passed in the partition value.
@ -3252,6 +3239,21 @@ String MergeTreeData::getPartitionIDFromQuery(const ASTPtr & ast, ContextPtr loc
", must be: " + toString(fields_count),
ErrorCodes::INVALID_PARTITION_VALUE);
if (auto * f = partition_ast.value->as<ASTFunction>())
{
assert(f->name == "tuple");
if (f->arguments && !f->arguments->as<ASTExpressionList>()->children.empty())
{
ASTPtr query = partition_ast.value->clone();
auto syntax_analyzer_result
= TreeRewriter(local_context)
.analyze(query, metadata_snapshot->getPartitionKey().sample_block.getNamesAndTypesList(), {}, {}, false, false);
auto actions = ExpressionAnalyzer(query, syntax_analyzer_result, local_context).getActions(true);
if (actions->hasArrayJoin())
throw Exception("The partition expression cannot contain array joins", ErrorCodes::INVALID_PARTITION_VALUE);
}
}
const FormatSettings format_settings;
Row partition_row(fields_count);

View File

@ -160,6 +160,7 @@
"01781_merge_tree_deduplication",
"00980_zookeeper_merge_tree_alter_settings",
"00980_merge_alter_settings",
"02009_array_join_partition",
/// Old syntax is not allowed
"01062_alter_on_mutataion_zookeeper",
"00925_zookeeper_empty_replicated_merge_tree_optimize_final",