Skip to content

Commit

Permalink
Merge branch 'master' into fix-stale-region
Browse files Browse the repository at this point in the history
  • Loading branch information
YuJuncen committed Mar 12, 2024
2 parents 2584908 + 5a12e2b commit 30e2a78
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions components/tidb_query_expr/src/impl_cast.rs
Expand Up @@ -1385,8 +1385,9 @@ fn cast_string_as_json(
let mut vec;
if typ.tp() == FieldTypeTp::String {
vec = (*val).to_owned();
// the `flen` of string is always greater than zero
vec.resize(typ.flen().try_into().unwrap(), 0);
if typ.flen() > 0 {
vec.resize(typ.flen().try_into().unwrap(), 0);
}
buf = &vec;
}

Expand Down Expand Up @@ -7022,6 +7023,17 @@ mod tests {
Json::from_opaque(FieldTypeTp::String, &[97]).unwrap(),
true,
),
(
FieldTypeBuilder::new()
.tp(FieldTypeTp::VarChar)
.flen(UNSPECIFIED_LENGTH)
.charset(CHARSET_BIN)
.collation(Collation::Binary)
.build(),
"a".to_string(),
Json::from_opaque(FieldTypeTp::String, &[97]).unwrap(),
true,
),
];
for (arg_type, input, expect, parse_to_json) in cs {
let arg_value = ScalarValue::Bytes(Some(input.clone().into_bytes()));
Expand Down

0 comments on commit 30e2a78

Please sign in to comment.