Skip to content

Commit

Permalink
readyset-data: Fix lookup CHAR/Varchar coerce issue.
Browse files Browse the repository at this point in the history
When trying to coerce a CHAR/VARCHAR column we need to check the value
length in characters, not in bytes. This is because the field length
is declared in characters, not in bytes.

Ref: REA-4383 REA-4366
Change-Id: I0cce0c68370512272bd3da67ca4ce7b08b662c3f
  • Loading branch information
altmannmarcelo committed May 24, 2024
1 parent c25e6a8 commit 713673e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions readyset-data/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,21 +404,21 @@ pub(crate) trait TextCoerce: Sized + Clone + Into<DfValue> {
Ok(DfValue::from_str_and_collation(self.try_str()?, collation))
}

DfType::VarChar(l, ..) if l as usize >= str.len() => {
DfType::VarChar(l, ..) if l as usize >= str.chars().count() => {
// VarChar, but length is sufficient to store current string
Ok(self.clone().into())
}

DfType::Char(l, ..) if l as usize == str.len() => {
DfType::Char(l, ..) if l as usize == str.chars().count() => {
// Char, but length is same as current string
Ok(self.clone().into())
}

DfType::Char(l, ..) if l as usize > str.len() => {
DfType::Char(l, ..) if l as usize > str.chars().count() => {
// Char, but length is greater than the current string, have to pad with whitespace
let mut new_string = String::with_capacity(l as usize);
new_string += str;
new_string.extend(std::iter::repeat(' ').take(l as usize - str.len()));
new_string.extend(std::iter::repeat(' ').take(l as usize - str.chars().count()));
Ok(DfValue::from(new_string))
}

Expand Down

0 comments on commit 713673e

Please sign in to comment.