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 fc2e23eb6859fa..e49100f82a12e5 100644 --- a/be/src/vec/exec/format/json/new_json_reader.cpp +++ b/be/src/vec/exec/format/json/new_json_reader.cpp @@ -1057,6 +1057,17 @@ Status NewJsonReader::_simdjson_write_data_to_column(simdjson::ondemand::value& RETURN_IF_ERROR(data_serde->deserialize_one_cell_from_json(*data_column_ptr, slice, _serde_options)); + } else if (value.type() == simdjson::ondemand::json_type::boolean) { + const char* str_value = nullptr; + // insert "1"/"0" , not "true"/"false". + if (value.get_bool()) { + str_value = (char*)"1"; + } else { + str_value = (char*)"0"; + } + Slice slice {str_value, 1}; + RETURN_IF_ERROR(data_serde->deserialize_one_cell_from_json(*data_column_ptr, slice, + _serde_options)); } else { // Maybe we can `switch (value->GetType()) case: kNumberType`. // Note that `if (value->IsInt())`, but column is FloatColumn. 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 3ef9ecb5be941f..b2cf149e12ba33 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 @@ -267,3 +267,9 @@ test k2_value 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 +-- !select31 -- +1 1 1 1 1.00 +2 0 0 0 0.00 +3 100 100 100 100.00 +4 \N \N \N \N + diff --git a/regression-test/data/load_p0/stream_load/test_read_boolean_to_int.json b/regression-test/data/load_p0/stream_load/test_read_boolean_to_int.json new file mode 100644 index 00000000000000..62ff27be0bfdbf --- /dev/null +++ b/regression-test/data/load_p0/stream_load/test_read_boolean_to_int.json @@ -0,0 +1,6 @@ +[ +{"id":1,"k1":true,"k2":true,"k3":true,"k4":true}, +{"id":2,"k1":false,"k2":false,"k3":false,"k4":false}, +{"id":3,"k1":100,"k2":100,"k3":100,"k4":100}, +{"id":4,"k1":null,"k2":null,"k3":null,"k4":null} +] \ No newline at end of file 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 abe72dcb0b9d1f..9fdfccc9b47177 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 @@ -943,4 +943,33 @@ suite("test_json_load", "p0,nonConcurrent") { } finally { // try_sql("DROP TABLE IF EXISTS ${testTable}") } + + // try to load `boolean` => `tinyint, int , string, decimal` + try { + sql "DROP TABLE IF EXISTS ${testTable}" + sql """CREATE TABLE IF NOT EXISTS ${testTable} + ( + `id` int, + `k1` tinyint NULL, + `k2` int NULL, + `k3` string NULL, + `k4` decimal(10,2) NULL + ) + DUPLICATE KEY(`id`) + COMMENT '' + DISTRIBUTED BY RANDOM BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + );""" + + + load_json_data.call("${testTable}", "${testTable}_case31", 'true', '', 'json', '', '', + '', '', '', 'test_read_boolean_to_int.json') + + sql "sync" + qt_select31 "select * from ${testTable} order by id" + + } finally { + // try_sql("DROP TABLE IF EXISTS ${testTable}") + } }