Merge pull request #70432 from ClickHouse/backport/24.8/70172

Backport #70172 to 24.8: Fix crash in JSON column
This commit is contained in:
robot-clickhouse 2024-10-07 09:25:59 +02:00 committed by GitHub
commit a5bf9e8654
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 34 additions and 0 deletions

View File

@ -87,6 +87,29 @@ ColumnObject::ColumnObject(
shared_data = ColumnArray::create(ColumnTuple::create(std::move(paths_and_values)));
}
ColumnObject::ColumnObject(const ColumnObject & other)
: COWHelper<IColumnHelper<ColumnObject>, ColumnObject>(other)
, typed_paths(other.typed_paths)
, dynamic_paths(other.dynamic_paths)
, dynamic_paths_ptrs(other.dynamic_paths_ptrs)
, shared_data(other.shared_data)
, max_dynamic_paths(other.max_dynamic_paths)
, global_max_dynamic_paths(other.global_max_dynamic_paths)
, max_dynamic_types(other.max_dynamic_types)
, statistics(other.statistics)
{
/// We should update string_view in sorted_typed_paths and sorted_dynamic_paths so they
/// point to the new strings in typed_paths and dynamic_paths.
sorted_typed_paths.clear();
for (const auto & [path, _] : typed_paths)
sorted_typed_paths.emplace_back(path);
std::sort(sorted_typed_paths.begin(), sorted_typed_paths.end());
sorted_dynamic_paths.clear();
for (const auto & [path, _] : dynamic_paths)
sorted_dynamic_paths.emplace(path);
}
ColumnObject::Ptr ColumnObject::create(
const std::unordered_map<String, ColumnPtr> & typed_paths_,
const std::unordered_map<String, ColumnPtr> & dynamic_paths_,

View File

@ -54,6 +54,8 @@ private:
size_t max_dynamic_types_,
const StatisticsPtr & statistics_ = {});
ColumnObject(const ColumnObject & other);
/// Use StringHashForHeterogeneousLookup hash for hash maps to be able to use std::string_view in find() method.
using PathToColumnMap = std::unordered_map<String, WrappedPtr, StringHashForHeterogeneousLookup, StringHashForHeterogeneousLookup::transparent_key_equal>;
using PathToDynamicColumnPtrMap = std::unordered_map<String, ColumnDynamic *, StringHashForHeterogeneousLookup, StringHashForHeterogeneousLookup::transparent_key_equal>;

View File

@ -0,0 +1,9 @@
SET allow_experimental_json_type = 1;
SET allow_experimental_variant_type = 1;
DROP TABLE IF EXISTS t0;
CREATE TABLE t0 (c0 Int) ENGINE = Memory();
INSERT INTO t0 (c0) VALUES (1);
ALTER TABLE t0 (ADD COLUMN c1 JSON(c1 Variant(Int,JSON(c1 Int))));
INSERT INTO t0 (c0, c1) VALUES (2, '{"c1":1}'::JSON);
SELECT kafkaMurmurHash(c1) FROM t0; -- {serverError NOT_IMPLEMENTED}
DROP TABLE t0;