mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Backport #70172 to 24.8: Fix crash in JSON column
This commit is contained in:
parent
fa3d99b00a
commit
e59bb63efb
@ -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_,
|
||||
|
@ -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>;
|
||||
|
9
tests/queries/0_stateless/03247_object_column_copy.sql
Normal file
9
tests/queries/0_stateless/03247_object_column_copy.sql
Normal 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;
|
Loading…
Reference in New Issue
Block a user