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
30 changes: 22 additions & 8 deletions be/src/vec/data_types/serde/data_type_object_serde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,33 @@ void DataTypeObjectSerDe::write_one_cell_to_jsonb(const IColumn& column, JsonbWr
JsonbParser json_parser;
// encode as jsonb
bool succ = json_parser.parse(value_str.data(), value_str.size());
// maybe more graceful, it is ok to check here since data could be parsed
CHECK(succ);
result.writeStartBinary();
result.writeBinary(json_parser.getWriter().getOutput()->getBuffer(),
json_parser.getWriter().getOutput()->getSize());
result.writeEndBinary();
if (!succ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (succ) {
// write binary
} else {
// write string
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// not a valid json insert raw text
result.writeStartString();
result.writeString(value_str.data(), value_str.size());
result.writeEndString();
} else {
// write a json binary
result.writeStartBinary();
result.writeBinary(json_parser.getWriter().getOutput()->getBuffer(),
json_parser.getWriter().getOutput()->getSize());
result.writeEndBinary();
}
}

void DataTypeObjectSerDe::read_one_cell_from_jsonb(IColumn& column, const JsonbValue* arg) const {
auto& variant = assert_cast<ColumnObject&>(column);
Field field;
auto blob = static_cast<const JsonbBlobVal*>(arg);
field.assign_jsonb(blob->getBlob(), blob->getBlobLen());
if (arg->isBinary()) {
const auto* blob = static_cast<const JsonbBlobVal*>(arg);
field.assign_jsonb(blob->getBlob(), blob->getBlobLen());
} else if (arg->isString()) {
// not a valid jsonb type, insert as string
const auto* str = static_cast<const JsonbStringVal*>(arg);
field.assign_string(str->getBlob(), str->getBlobLen());
} else {
throw doris::Exception(ErrorCode::INTERNAL_ERROR, "Invalid jsonb type");
}
variant.insert(field);
}

Expand Down
3 changes: 3 additions & 0 deletions regression-test/data/variant_p0/variant_with_rowstore.out
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@
-- !point_select --
-1 {"a":1123} {"a":1123}

-- !sql --
1 1|[""]

18 changes: 18 additions & 0 deletions regression-test/suites/variant_p0/variant_with_rowstore.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,22 @@ suite("regression_test_variant_rowstore", "variant_type"){
// stmt.setInt(1, -3)
// qe_point_select stmt
}

sql "DROP TABLE IF EXISTS table_rs_invalid_json"
sql """
CREATE TABLE table_rs_invalid_json
(
col0 BIGINT NOT NULL,
coljson VARIANT NOT NULL, INDEX colvariant_idx(coljson) USING INVERTED
)
UNIQUE KEY(col0)
DISTRIBUTED BY HASH(col0) BUCKETS 4
PROPERTIES (
"enable_unique_key_merge_on_write" = "true",
"store_row_column"="true",
"replication_num" = "1"
);
"""
sql """insert into table_rs_invalid_json values (1, '1|[""]')"""
qt_sql "select * from table_rs_invalid_json where col0 = 1"
}