Merge pull request #27648 from Algunenano/i27620

Disable arrayJoin on partition expressions
This commit is contained in:
alexey-milovidov 2021-08-16 02:53:36 +03:00 committed by GitHub
commit 4a36366925
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 0 deletions

View File

@ -3207,6 +3207,16 @@ 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 &>();
@ -3217,6 +3227,9 @@ 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.

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}