Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions be/src/vec/data_types/serde/data_type_struct_serde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Status DataTypeStructSerDe::deserialize_one_cell_from_json(IColumn& column, Slic
char quote_char = 0;

auto elem_size = elem_serdes_ptrs.size();
DCHECK_EQ(elem_size, elem_names.size());
int field_pos = 0;

for (; idx < slice_size; ++idx) {
Expand Down Expand Up @@ -138,6 +139,15 @@ Status DataTypeStructSerDe::deserialize_one_cell_from_json(IColumn& column, Slic
next.trim_prefix();
next.trim_quote();
// check field_name
if (field_pos >= elem_size) {
// we should do column revert if error
for (size_t j = 0; j < field_pos; j++) {
struct_column.get_column(j).pop_back(1);
}
return Status::InvalidArgument(
"Actual struct field number is more than schema field number {}.",
field_pos, elem_size);
}
if (elem_names[field_pos] != next) {
// we should do column revert if error
for (size_t j = 0; j < field_pos; j++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@
-- !sql14 --
{"f1":1.0, "f2":"2022-10-10 00:00:00"}

-- !sql15 --
\N

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ suite("test_cast_struct") {
// struct type cast to struct
qt_sql14 "select cast(cast({1,'2022-10-10'} as struct<f1:int,f2:date>) as struct<f1:double,f2:datetime>)"

// struct type cast to struct with different field name
qt_sql15 """select cast('{"a":1,"b":"1","c":"1","d":"1"}' as struct<a:int, b:int>)"""

// basic types except string can not cast to struct
test {
sql "select cast(cast(1 as int) as struct<f1:int>)"
Expand Down
Loading