mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 23:52:03 +00:00
Merge pull request #54895 from amosbird/allow-nullable-primary-keys-for-projections
Always allow nullable keys for projections
This commit is contained in:
commit
cf40723179
@ -481,6 +481,7 @@ void MergeTreeData::checkProperties(
|
||||
const StorageInMemoryMetadata & old_metadata,
|
||||
bool attach,
|
||||
bool allow_empty_sorting_key,
|
||||
bool allow_nullable_key_,
|
||||
ContextPtr local_context) const
|
||||
{
|
||||
if (!new_metadata.sorting_key.definition_ast && !allow_empty_sorting_key)
|
||||
@ -598,12 +599,12 @@ void MergeTreeData::checkProperties(
|
||||
|
||||
/// We cannot alter a projection so far. So here we do not try to find a projection in old metadata.
|
||||
bool is_aggregate = projection.type == ProjectionDescription::Type::Aggregate;
|
||||
checkProperties(*projection.metadata, *projection.metadata, attach, is_aggregate, local_context);
|
||||
checkProperties(*projection.metadata, *projection.metadata, attach, is_aggregate, true /* allow_nullable_key */, local_context);
|
||||
projections_names.insert(projection.name);
|
||||
}
|
||||
}
|
||||
|
||||
checkKeyExpression(*new_sorting_key.expression, new_sorting_key.sample_block, "Sorting", allow_nullable_key);
|
||||
checkKeyExpression(*new_sorting_key.expression, new_sorting_key.sample_block, "Sorting", allow_nullable_key_);
|
||||
}
|
||||
|
||||
void MergeTreeData::setProperties(
|
||||
@ -612,7 +613,7 @@ void MergeTreeData::setProperties(
|
||||
bool attach,
|
||||
ContextPtr local_context)
|
||||
{
|
||||
checkProperties(new_metadata, old_metadata, attach, false, local_context);
|
||||
checkProperties(new_metadata, old_metadata, attach, false, allow_nullable_key, local_context);
|
||||
setInMemoryMetadata(new_metadata);
|
||||
}
|
||||
|
||||
@ -3350,7 +3351,7 @@ void MergeTreeData::checkAlterIsPossible(const AlterCommands & commands, Context
|
||||
}
|
||||
}
|
||||
|
||||
checkProperties(new_metadata, old_metadata, false, false, local_context);
|
||||
checkProperties(new_metadata, old_metadata, false, false, allow_nullable_key, local_context);
|
||||
checkTTLExpressions(new_metadata, old_metadata);
|
||||
|
||||
if (!columns_to_check_conversion.empty())
|
||||
|
@ -1247,9 +1247,19 @@ protected:
|
||||
/// The same for clearOldTemporaryDirectories.
|
||||
std::mutex clear_old_temporary_directories_mutex;
|
||||
|
||||
void checkProperties(const StorageInMemoryMetadata & new_metadata, const StorageInMemoryMetadata & old_metadata, bool attach, bool allow_empty_sorting_key, ContextPtr local_context) const;
|
||||
void checkProperties(
|
||||
const StorageInMemoryMetadata & new_metadata,
|
||||
const StorageInMemoryMetadata & old_metadata,
|
||||
bool attach,
|
||||
bool allow_empty_sorting_key,
|
||||
bool allow_nullable_key_,
|
||||
ContextPtr local_context) const;
|
||||
|
||||
void setProperties(const StorageInMemoryMetadata & new_metadata, const StorageInMemoryMetadata & old_metadata, bool attach = false, ContextPtr local_context = nullptr);
|
||||
void setProperties(
|
||||
const StorageInMemoryMetadata & new_metadata,
|
||||
const StorageInMemoryMetadata & old_metadata,
|
||||
bool attach = false,
|
||||
ContextPtr local_context = nullptr);
|
||||
|
||||
void checkPartitionKeyAndInitMinMax(const KeyDescription & new_partition_key);
|
||||
|
||||
|
@ -0,0 +1 @@
|
||||
CREATE TABLE default.sales\n(\n `DATE_SOLD` DateTime64(3, \'UTC\'),\n `PRODUCT_ID` Nullable(String),\n PROJECTION test\n (\n SELECT toInt64(count(*))\n GROUP BY \n PRODUCT_ID,\n DATE_SOLD\n )\n)\nENGINE = MergeTree\nPARTITION BY toYYYYMM(DATE_SOLD)\nORDER BY DATE_SOLD\nSETTINGS index_granularity = 8192
|
@ -0,0 +1,9 @@
|
||||
DROP TABLE IF EXISTS sales;
|
||||
|
||||
CREATE TABLE sales (DATE_SOLD DateTime64(3, 'UTC'), PRODUCT_ID Nullable(String)) Engine MergeTree() PARTITION BY toYYYYMM(DATE_SOLD) ORDER BY DATE_SOLD;
|
||||
|
||||
ALTER TABLE sales ADD PROJECTION test (SELECT toInt64(COUNT(*)) GROUP BY PRODUCT_ID, DATE_SOLD);
|
||||
|
||||
SHOW CREATE sales;
|
||||
|
||||
DROP TABLE sales;
|
Loading…
Reference in New Issue
Block a user