Skip to content

Commit e59bb63

Browse files
Backport ClickHouse#70172 to 24.8: Fix crash in JSON column
1 parent fa3d99b commit e59bb63

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

src/Columns/ColumnObject.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,29 @@ ColumnObject::ColumnObject(
8787
shared_data = ColumnArray::create(ColumnTuple::create(std::move(paths_and_values)));
8888
}
8989

90+
ColumnObject::ColumnObject(const ColumnObject & other)
91+
: COWHelper<IColumnHelper<ColumnObject>, ColumnObject>(other)
92+
, typed_paths(other.typed_paths)
93+
, dynamic_paths(other.dynamic_paths)
94+
, dynamic_paths_ptrs(other.dynamic_paths_ptrs)
95+
, shared_data(other.shared_data)
96+
, max_dynamic_paths(other.max_dynamic_paths)
97+
, global_max_dynamic_paths(other.global_max_dynamic_paths)
98+
, max_dynamic_types(other.max_dynamic_types)
99+
, statistics(other.statistics)
100+
{
101+
/// We should update string_view in sorted_typed_paths and sorted_dynamic_paths so they
102+
/// point to the new strings in typed_paths and dynamic_paths.
103+
sorted_typed_paths.clear();
104+
for (const auto & [path, _] : typed_paths)
105+
sorted_typed_paths.emplace_back(path);
106+
std::sort(sorted_typed_paths.begin(), sorted_typed_paths.end());
107+
108+
sorted_dynamic_paths.clear();
109+
for (const auto & [path, _] : dynamic_paths)
110+
sorted_dynamic_paths.emplace(path);
111+
}
112+
90113
ColumnObject::Ptr ColumnObject::create(
91114
const std::unordered_map<String, ColumnPtr> & typed_paths_,
92115
const std::unordered_map<String, ColumnPtr> & dynamic_paths_,

src/Columns/ColumnObject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class ColumnObject final : public COWHelper<IColumnHelper<ColumnObject>, ColumnO
5454
size_t max_dynamic_types_,
5555
const StatisticsPtr & statistics_ = {});
5656

57+
ColumnObject(const ColumnObject & other);
58+
5759
/// Use StringHashForHeterogeneousLookup hash for hash maps to be able to use std::string_view in find() method.
5860
using PathToColumnMap = std::unordered_map<String, WrappedPtr, StringHashForHeterogeneousLookup, StringHashForHeterogeneousLookup::transparent_key_equal>;
5961
using PathToDynamicColumnPtrMap = std::unordered_map<String, ColumnDynamic *, StringHashForHeterogeneousLookup, StringHashForHeterogeneousLookup::transparent_key_equal>;

tests/queries/0_stateless/03247_object_column_copy.reference

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SET allow_experimental_json_type = 1;
2+
SET allow_experimental_variant_type = 1;
3+
DROP TABLE IF EXISTS t0;
4+
CREATE TABLE t0 (c0 Int) ENGINE = Memory();
5+
INSERT INTO t0 (c0) VALUES (1);
6+
ALTER TABLE t0 (ADD COLUMN c1 JSON(c1 Variant(Int,JSON(c1 Int))));
7+
INSERT INTO t0 (c0, c1) VALUES (2, '{"c1":1}'::JSON);
8+
SELECT kafkaMurmurHash(c1) FROM t0; -- {serverError NOT_IMPLEMENTED}
9+
DROP TABLE t0;

0 commit comments

Comments
 (0)