diff --git a/src/Storages/MergeTree/MergeTreeData.cpp b/src/Storages/MergeTree/MergeTreeData.cpp index 4730bf9f47c..ebd961ab428 100644 --- a/src/Storages/MergeTree/MergeTreeData.cpp +++ b/src/Storages/MergeTree/MergeTreeData.cpp @@ -3207,6 +3207,16 @@ Pipe MergeTreeData::alterPartition( return {}; } +void checkPartitionExpressionFunction(const ASTPtr & ast) +{ + if (const auto * func = ast->as()) + 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(); @@ -3217,6 +3227,9 @@ String MergeTreeData::getPartitionIDFromQuery(const ASTPtr & ast, ContextPtr loc return partition_ast.id; } + if (const auto * partition_function = partition_ast.value->as()) + 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. diff --git a/tests/queries/0_stateless/02009_array_join_partition.reference b/tests/queries/0_stateless/02009_array_join_partition.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/02009_array_join_partition.sql b/tests/queries/0_stateless/02009_array_join_partition.sql new file mode 100644 index 00000000000..a78efe96f66 --- /dev/null +++ b/tests/queries/0_stateless/02009_array_join_partition.sql @@ -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}