Skip to content

Commit fc11788

Browse files
committed
[SQL] Support cast from integer to BINARY
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
1 parent 6f8b43c commit fc11788

File tree

8 files changed

+196
-207
lines changed

8 files changed

+196
-207
lines changed

crates/sqllib/src/binary.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,27 @@ impl ByteArray {
251251
}
252252
}
253253

254+
pub fn with_size_truncate_left(d: &[u8], size: i32, fixed: bool) -> Self {
255+
if size < 0 {
256+
ByteArray::new(d)
257+
} else {
258+
let size = size as usize;
259+
match d.len().cmp(&size) {
260+
Ordering::Equal => ByteArray::new(d),
261+
Ordering::Greater => ByteArray::new(&d[d.len() - size..]),
262+
Ordering::Less => {
263+
if fixed {
264+
let mut data: CompactVec = smallvec![0; size];
265+
data[d.len() - size..].copy_from_slice(d);
266+
ByteArray { data }
267+
} else {
268+
ByteArray::new(d)
269+
}
270+
}
271+
}
272+
}
273+
}
274+
254275
pub fn zero(size: usize) -> Self {
255276
Self {
256277
data: smallvec![0; size],

0 commit comments

Comments
 (0)