Disable arrayJoin on partition expressions

This commit is contained in:
Raúl Marín 2021-08-13 16:18:46 +02:00
parent 93351cd3ee
commit 73cb7d55ec
3 changed files with 17 additions and 0 deletions

View File

@ -3207,6 +3207,16 @@ Pipe MergeTreeData::alterPartition(
return {}; 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 String MergeTreeData::getPartitionIDFromQuery(const ASTPtr & ast, ContextPtr local_context) const
{ {
const auto & partition_ast = ast->as<ASTPartition &>(); const auto & partition_ast = ast->as<ASTPartition &>();
@ -3217,6 +3227,9 @@ String MergeTreeData::getPartitionIDFromQuery(const ASTPtr & ast, ContextPtr loc
return partition_ast.id; return partition_ast.id;
} }
if (const auto * partition_function = partition_ast.value->as<ASTFunction>())
checkPartitionExpressionFunction(ast);
if (format_version < MERGE_TREE_DATA_MIN_FORMAT_VERSION_WITH_CUSTOM_PARTITIONING) if (format_version < MERGE_TREE_DATA_MIN_FORMAT_VERSION_WITH_CUSTOM_PARTITIONING)
{ {
/// Month-partitioning specific - partition ID can be passed in the partition value. /// Month-partitioning specific - partition ID can be passed in the partition value.

View File

@ -0,0 +1,4 @@
CREATE TABLE table_2009_part (`i` Int64, `d` Date, `s` String) ENGINE = MergeTree PARTITION BY toYYYYMM(d) ORDER BY i;
ALTER TABLE table_2009_part ATTACH PARTITION tuple(arrayJoin([0, 1])); -- {serverError 248}
ALTER TABLE table_2009_part ATTACH PARTITION tuple(toYYYYMM(toDate([arrayJoin([arrayJoin([arrayJoin([arrayJoin([3, materialize(NULL), arrayJoin([1025, materialize(NULL), materialize(NULL)]), NULL])])]), materialize(NULL)])], NULL))); -- {serverError 248}