Skip to content

Commit

Permalink
[Fix](Variant) cast from jsonb with string value when enable `jsonb_s…
Browse files Browse the repository at this point in the history
…tring_as_string` should consider others types include date,datateime,array ...
  • Loading branch information
eldenmoon committed Jul 24, 2024
1 parent d1e7dbc commit 0cfd626
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
12 changes: 9 additions & 3 deletions be/src/vec/functions/function_cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -719,14 +719,20 @@ struct ConvertImplGenericFromJsonb {
}
// add string to string column
if (context->jsonb_string_as_string() && is_dst_string && value->isString()) {
auto blob = static_cast<const JsonbBlobVal*>(value);
const auto* blob = static_cast<const JsonbBlobVal*>(value);
assert_cast<ColumnString&>(*col_to).insert_data(blob->getBlob(),
blob->getBlobLen());
(*vec_null_map_to)[i] = 0;
continue;
}
std::string json_str = JsonbToJson::jsonb_to_json_string(val.data, val.size);
ReadBuffer read_buffer((char*)(json_str.data()), json_str.size());
std::string input_str;
if (context->jsonb_string_as_string() && value->isString()) {
const auto* blob = static_cast<const JsonbBlobVal*>(value);
input_str = std::string(blob->getBlob(), blob->getBlobLen());
} else {
std::string input_str = JsonbToJson::jsonb_to_json_string(val.data, val.size);
}
ReadBuffer read_buffer((char*)(input_str.data()), input_str.size());
Status st = data_type_to->from_string(read_buffer, col_to);
// if parsing failed, will return null
(*vec_null_map_to)[i] = !st.ok();
Expand Down
48 changes: 48 additions & 0 deletions regression-test/data/variant_p0/rqg/rqg2.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !rqg2 --
0

-- !rqg2_2 --
500

-- !rqg2_3 --
500

-- !rqg2_4 --
0

-- !rqg2_5 --
0

-- !rqg2_6 --
500

-- !rqg2_7 --
500

-- !rqg2_8 --
2023-12-09
2023-12-10
2023-12-11
2023-12-12
2023-12-13
2023-12-14
2023-12-15
2023-12-16
2023-12-17
2023-12-18
2023-12-19
2023-12-20
2024-01-08
2024-01-09
2024-01-17
2024-01-19
2024-01-31
2024-02-18
2025-02-18
2025-06-18
2026-01-18
2026-02-18
2027-01-09
2027-01-16

8 changes: 8 additions & 0 deletions regression-test/suites/variant_p0/rqg/rqg2.sql

Large diffs are not rendered by default.

0 comments on commit 0cfd626

Please sign in to comment.