From ddf1dbf0c7d6dbfbe0e20371f9e176040bb6329c Mon Sep 17 00:00:00 2001 From: lihangyu Date: Wed, 25 Jun 2025 10:42:18 +0800 Subject: [PATCH] =?UTF-8?q?[Fix](JsonReader)=20Fix=20the=20issue=20where?= =?UTF-8?q?=20the=20null=20bitmap=20of=20the=20JSON=20reader=20was=20not?= =?UTF-8?q?=20initialized=20when=20the=20JSON=20path=20is=20specified=20as?= =?UTF-8?q?=20'$.=E2=80=99=20(#52211)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The null bitmap of the related json path should be inited --- .../vec/exec/format/json/new_json_reader.cpp | 1 + .../load_p0/stream_load/test_json_load.out | 9 ++++++- .../load_p0/stream_load/test_json_load.groovy | 27 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/be/src/vec/exec/format/json/new_json_reader.cpp b/be/src/vec/exec/format/json/new_json_reader.cpp index 37ab5041216f9f..c8969c6d4c314e 100644 --- a/be/src/vec/exec/format/json/new_json_reader.cpp +++ b/be/src/vec/exec/format/json/new_json_reader.cpp @@ -2018,6 +2018,7 @@ Status NewJsonReader::_simdjson_write_columns_by_jsonpath( if (slot_desc->is_nullable()) { nullable_column = assert_cast(column_ptr); target_column_ptr = &nullable_column->get_nested_column(); + nullable_column->get_null_map_data().push_back(0); } auto* column_string = assert_cast(target_column_ptr); column_string->insert_data(_simdjson_ondemand_padding_buffer.data(), diff --git a/regression-test/data/load_p0/stream_load/test_json_load.out b/regression-test/data/load_p0/stream_load/test_json_load.out index 1d6777bb21e7ab..3ef9ecb5be941f 100644 --- a/regression-test/data/load_p0/stream_load/test_json_load.out +++ b/regression-test/data/load_p0/stream_load/test_json_load.out @@ -259,4 +259,11 @@ test k2_value -- !select31 -- 789 beijing haidian -1111 \N \N \ No newline at end of file +1111 \N \N + +-- !select30 -- +12345 {"k1":12345,"k2":"11111","k3":111111,"k4":[11111]} {"k1":12345,"k2":"11111","k3":111111,"k4":[11111]} 111111 +12346 {"k1":12346,"k2":"22222","k4":[22222]} {"k1":12346,"k2":"22222","k4":[22222]} \N +12347 {"k1":12347,"k3":"33333","k4":[22222]} {"k1":12347,"k3":"33333","k4":[22222]} 33333 +12348 {"k1":12348,"k3":"33333","k5":{"k51":1024,"xxxx":[11111]}} {"k1":12348,"k3":"33333","k5":{"k51":1024,"xxxx":[11111]}} 33333 + diff --git a/regression-test/suites/load_p0/stream_load/test_json_load.groovy b/regression-test/suites/load_p0/stream_load/test_json_load.groovy index 1042b5a3d71cdd..cbecb831cfcad7 100644 --- a/regression-test/suites/load_p0/stream_load/test_json_load.groovy +++ b/regression-test/suites/load_p0/stream_load/test_json_load.groovy @@ -932,4 +932,31 @@ suite("test_json_load", "p0,nonConcurrent") { } finally { // try_sql("DROP TABLE IF EXISTS ${testTable}") } + + // support read "$." as root with json type + try { + sql "DROP TABLE IF EXISTS ${testTable}" + sql """CREATE TABLE IF NOT EXISTS ${testTable} + ( + `k1` varchar(1024) NULL, + `k2` json NULL, + `k3` json NULL, + `k4` json NULL + ) + DUPLICATE KEY(`k1`) + COMMENT '' + DISTRIBUTED BY RANDOM BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + );""" + + load_json_data.call("${testTable}", "${testTable}_case30", 'false', 'true', 'json', '', '[\"$.k1\",\"$.\", \"$.\", \"$.k3\"]', + '', '', '', 'test_read_root_path.json') + + sql "sync" + qt_select30 "select * from ${testTable} order by k1" + + } finally { + // try_sql("DROP TABLE IF EXISTS ${testTable}") + } }