Skip to content

Commit

Permalink
remove cast between int16 and int64
Browse files Browse the repository at this point in the history
Signed-off-by: xyz <[email protected]>
  • Loading branch information
xiaoyong-z committed May 9, 2022
1 parent 7cdbe43 commit 3e9a075
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 27 deletions.
4 changes: 0 additions & 4 deletions src/expr/src/expr/expr_unary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,8 @@ macro_rules! gen_cast {
{ varchar, boolean, str_to_bool },

{ boolean, varchar, bool_to_str },
{ boolean, int16, general_cast },
{ boolean, int32, general_cast },
{ boolean, int64, general_cast },
{ int16, boolean, int16_to_bool },
{ int32, boolean, int32_to_bool },
{ int64, boolean, int64_to_bool },

{ int16, int32, general_cast },
{ int16, int64, general_cast },
Expand Down
25 changes: 2 additions & 23 deletions src/expr/src/vector_op/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,22 +213,10 @@ pub fn bool_to_str(input: bool) -> Result<String> {
}
}

macro_rules! integer_to_bool {
($func_name:ident, $type:ty) => {
#[inline(always)]
pub fn $func_name(input: $type) -> Result<bool> {
match input {
0 => Ok(false),
_ => Ok(true),
}
}
};
pub fn int32_to_bool(input: i32) -> Result<bool> {
Ok(input != 0)
}

integer_to_bool!(int16_to_bool, i16);
integer_to_bool!(int32_to_bool, i32);
integer_to_bool!(int64_to_bool, i64);

#[cfg(test)]
mod tests {
#[test]
Expand Down Expand Up @@ -258,17 +246,8 @@ mod tests {
#[test]
fn integer_cast_to_bool() {
use super::*;

assert_eq!(int16_to_bool(16).unwrap(), true);
assert_eq!(int32_to_bool(32).unwrap(), true);
assert_eq!(int64_to_bool(64).unwrap(), true);

assert_eq!(int16_to_bool(-16).unwrap(), true);
assert_eq!(int32_to_bool(-32).unwrap(), true);
assert_eq!(int64_to_bool(-64).unwrap(), true);

assert_eq!(int16_to_bool(0).unwrap(), false);
assert_eq!(int32_to_bool(0).unwrap(), false);
assert_eq!(int64_to_bool(0).unwrap(), false);
}
}

0 comments on commit 3e9a075

Please sign in to comment.