Repository navigation
Implement Shannon entropy aggregate function - #4238
Conversation
| #include <AggregateFunctions/FactoryHelpers.h> | ||
|
|
||
| /// These must be exposed in header for the purpose of dynamic compilation. | ||
| #include <AggregateFunctions/QuantileReservoirSampler.h> |
| #include <AggregateFunctions/IAggregateFunction.h> | ||
| #include <AggregateFunctions/QuantilesCommon.h> | ||
| #include <Columns/ColumnArray.h> | ||
| #include <Columns/ColumnDecimal.h> |
There was a problem hiding this comment.
Please remove unneeded includes.
|
|
||
| namespace ErrorCodes | ||
| { | ||
| extern const int ILLEGAL_TYPE_OF_ARGUMENT; |
| using Weight = UInt64; | ||
| using Map = HashMap < | ||
| Value, Weight, | ||
| HashCRC32<Value>, |
There was a problem hiding this comment.
If the value is already hashed (UInt128), we should use TrivialHash instead of HashCRC32.
|
|
||
| Map map; | ||
|
|
||
| void add(const Value &x) |
There was a problem hiding this comment.
We write spaces at both sides of &.
| map.write(buf); | ||
| } | ||
|
|
||
| void deserialize(ReadBuffer &buf) |
There was a problem hiding this comment.
To test serialization, we can write distributed query by select from remote table function with remote('127.0.0.{1,2}'). See examples in other tests.
Note: To run this test on local machine, the server should be configured to accept remote connections (see listen in config.xml).
|
|
||
| Float64 get() const | ||
| { | ||
| Float64 ShannonEntropy = 0; |
There was a problem hiding this comment.
Variables are in snake_case.
| } | ||
| else if (which.isUInt128()) | ||
| { | ||
| return std::make_shared<AggregateFunctionEntropy<UInt128, true>>(); |
There was a problem hiding this comment.
That's not correct.
UInt128 data type is not a hash.
|
It doesn't work for mutual entropy: |
|
Internal documentation ticket: DOCSUP-10111 |
…House#23727) Before this change, `ALTER TABLE dst REPLACE PARTITION X FROM src` silently dropped the destination partition whenever the source table had no parts in partition X. The destination's data was simply removed and nothing was written in its place — an obvious data-loss footgun that has been tracked since 2021 as "easy task" / "unexpected behaviour". The pre-existing `max_partition_size_to_drop` check did not help in practice: its default is 50 GiB, so any reasonably-sized destination partition was silently wiped without any safety prompt. Per the maintainer thread on ClickHouse#23727 (alexey-milovidov 2022, azat 2024), the fix introduces a new query setting `allow_replace_partition_from_empty_source` (default `false`) and rejects the operation by default with `BAD_ARGUMENTS` and a clear remediation message. Users who genuinely depend on the previous "silent clear" semantics can opt in per-query by setting it to `1`, or switch to `ALTER TABLE ... DROP PARTITION` when they actually want to drop data. The check is added to both `StorageMergeTree::replacePartitionFrom` and `StorageReplicatedMergeTree::replacePartitionFromImpl`. The `is_all` branch is excluded because `REPLACE PARTITION ALL` is already rejected with `SUPPORT_IS_DISABLED`. A new stateless regression test (ClickHouse#4238) covers both engines and the opt-in case. The two pre-existing tests that intentionally exercised the silent-clear behavior (`00626_replace_partition_from_table.sql` and `_zookeeper.sh`) are updated to set the opt-in flag, preserving their intent. Closes: ClickHouse#23727
…House#23727) Before this change, `ALTER TABLE dst REPLACE PARTITION X FROM src` silently dropped the destination partition whenever the source table had no parts in partition X. The destination's data was simply removed and nothing was written in its place — an obvious data-loss footgun that has been tracked since 2021 as "easy task" / "unexpected behaviour". The pre-existing `max_partition_size_to_drop` check did not help in practice: its default is 50 GiB, so any reasonably-sized destination partition was silently wiped without any safety prompt. Per the maintainer thread on ClickHouse#23727 (alexey-milovidov 2022, azat 2024), the fix introduces a new query setting `allow_replace_partition_from_empty_source` (default `false`) and rejects the operation by default with `BAD_ARGUMENTS` and a clear remediation message. Users who genuinely depend on the previous "silent clear" semantics can opt in per-query by setting it to `1`, or switch to `ALTER TABLE ... DROP PARTITION` when they actually want to drop data. The check is added to both `StorageMergeTree::replacePartitionFrom` and `StorageReplicatedMergeTree::replacePartitionFromImpl`. The `is_all` branch is excluded because `REPLACE PARTITION ALL` is already rejected with `SUPPORT_IS_DISABLED`. A new stateless regression test (ClickHouse#4238) covers both engines and the opt-in case. The two pre-existing tests that intentionally exercised the silent-clear behavior (`00626_replace_partition_from_table.sql` and `_zookeeper.sh`) are updated to set the opt-in flag, preserving their intent. Closes: ClickHouse#23727
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en
For changelog. Remove if this is non-significant change.
Category (leave one):
Short description (up to few sentences):
Aggregate Function which computes Shannon entropy
...