Skip to content

Commit

Permalink
chore: make ci happy (#69)
Browse files Browse the repository at this point in the history
* chore: make ci happy

Signed-off-by: Chojan Shang <[email protected]>

* ci: minor update

* chore: minor fix

---------

Signed-off-by: Chojan Shang <[email protected]>
  • Loading branch information
PsiACE authored Sep 19, 2024
1 parent c1d71c9 commit 6cbb806
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 118 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ jobs:
if: ${{ contains(matrix.os, 'macos') }}
run: brew install [email protected]
- run: cargo build
- run: cargo test --lib --bins --tests -- --include-ignored
- run: |
export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"
cargo test --lib --bins --tests -- --include-ignored
pass:
name: All tests passed
Expand Down
9 changes: 7 additions & 2 deletions clickhouse/src/types/column/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,8 +958,13 @@ where
_marker: marker::PhantomData,
};

let iter =
unsafe { T::iter(mem::transmute(&column), self.column_type.clone()) }.unwrap();
let iter = unsafe {
T::iter(
mem::transmute::<&Column<Simple>, &Column<Simple>>(&column),
self.column_type.clone(),
)
}
.unwrap();

self.current = Some(iter);
self.current_index += 1;
Expand Down
5 changes: 4 additions & 1 deletion clickhouse/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl Progress {
}
}

#[allow(dead_code)]
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq)]
pub(crate) struct ProfileInfo {
pub rows: u64,
Expand Down Expand Up @@ -249,7 +250,9 @@ impl From<SqlType> for &'static SqlType {
let mut guard = TYPES_CACHE.lock().unwrap();
loop {
if let Some(value_ref) = guard.get(&value.clone()) {
return unsafe { mem::transmute(value_ref.as_ref()) };
return unsafe {
mem::transmute::<std::pin::Pin<&SqlType>, &SqlType>(value_ref.as_ref())
};
}
guard.insert(value.clone(), Box::pin(value.clone()));
}
Expand Down
4 changes: 1 addition & 3 deletions clickhouse/tests/it/types/column/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::f64::EPSILON;

use opensrv_clickhouse::types::column::*;
use rand::random;

Expand All @@ -36,7 +34,7 @@ fn test_push_and_get() {
assert_eq!(list.len(), count);

for (i, v) in vs.iter().take(count).enumerate() {
assert!((list.at(i) - *v).abs() < EPSILON);
assert!((list.at(i) - *v).abs() < f64::EPSILON);
}

let k = random();
Expand Down
4 changes: 2 additions & 2 deletions clickhouse/tests/it/types/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ fn test_scale() {
#[test]
fn test_from_f32() {
let value: f32 = Decimal::of(2, 4).into();
assert!((value - 2.0_f32).abs() <= std::f32::EPSILON);
assert!((value - 2.0_f32).abs() <= f32::EPSILON);
}

#[test]
fn test_from_f64() {
let value: f64 = Decimal::of(2, 4).into();
assert!((value - 2.0_f64).abs() < std::f64::EPSILON);
assert!((value - 2.0_f64).abs() < f64::EPSILON);
}

#[test]
Expand Down
3 changes: 1 addition & 2 deletions mysql/src/packet_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ impl<R: Read> PacketReader<R> {
self.bytes = rest.into();
return Ok(Some(p));
}
Err(nom::Err::Incomplete(_)) | Err(nom::Err::Error(_)) => {
}
Err(nom::Err::Incomplete(_)) | Err(nom::Err::Error(_)) => {}
Err(nom::Err::Failure(ctx)) => {
let err = Err(io::Error::new(
io::ErrorKind::InvalidData,
Expand Down
52 changes: 8 additions & 44 deletions mysql/src/tests/value/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,59 +108,23 @@ rt!(i64_one, i64, 1, ColumnType::MYSQL_TYPE_LONGLONG, true);
rt!(f32_one_float, f32, 1.0, ColumnType::MYSQL_TYPE_FLOAT, false);
rt!(f64_one, f64, 1.0, ColumnType::MYSQL_TYPE_DOUBLE, false);

rt!(
u8_max,
u8,
u8::max_value(),
ColumnType::MYSQL_TYPE_TINY,
false
);
rt!(
i8_max,
i8,
i8::max_value(),
ColumnType::MYSQL_TYPE_TINY,
true
);
rt!(
u16_max,
u16,
u16::max_value(),
ColumnType::MYSQL_TYPE_SHORT,
false
);
rt!(
i16_max,
i16,
i16::max_value(),
ColumnType::MYSQL_TYPE_SHORT,
true
);
rt!(
u32_max,
u32,
u32::max_value(),
ColumnType::MYSQL_TYPE_LONG,
false
);
rt!(
i32_max,
i32,
i32::max_value(),
ColumnType::MYSQL_TYPE_LONG,
true
);
rt!(u8_max, u8, u8::MAX, ColumnType::MYSQL_TYPE_TINY, false);
rt!(i8_max, i8, i8::MAX, ColumnType::MYSQL_TYPE_TINY, true);
rt!(u16_max, u16, u16::MAX, ColumnType::MYSQL_TYPE_SHORT, false);
rt!(i16_max, i16, i16::MAX, ColumnType::MYSQL_TYPE_SHORT, true);
rt!(u32_max, u32, u32::MAX, ColumnType::MYSQL_TYPE_LONG, false);
rt!(i32_max, i32, i32::MAX, ColumnType::MYSQL_TYPE_LONG, true);
rt!(
u64_max,
u64,
u64::max_value(),
u64::MAX,
ColumnType::MYSQL_TYPE_LONGLONG,
false
);
rt!(
i64_max,
i64,
i64::max_value(),
i64::MAX,
ColumnType::MYSQL_TYPE_LONGLONG,
true
);
Expand Down
68 changes: 16 additions & 52 deletions mysql/src/tests/value/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ mod roundtrip_text {
rt!(f32_one, f32, 1.0);
rt!(f64_one, f64, 1.0);

rt!(u8_max, u8, u8::max_value());
rt!(i8_max, i8, i8::max_value());
rt!(u16_max, u16, u16::max_value());
rt!(i16_max, i16, i16::max_value());
rt!(u32_max, u32, u32::max_value());
rt!(i32_max, i32, i32::max_value());
rt!(u64_max, u64, u64::max_value());
rt!(i64_max, i64, i64::max_value());
rt!(u8_max, u8, u8::MAX);
rt!(i8_max, i8, i8::MAX);
rt!(u16_max, u16, u16::MAX);
rt!(i16_max, i16, i16::MAX);
rt!(u32_max, u32, u32::MAX);
rt!(i32_max, i32, i32::MAX);
rt!(u64_max, u64, u64::MAX);
rt!(i64_max, i64, i64::MAX);

rt!(opt_none, Option<u8>, None);
rt!(opt_some, Option<u8>, Some(1));
Expand Down Expand Up @@ -198,59 +198,23 @@ mod roundtrip_bin {
rt!(f32_one, f32, 1.0, ColumnType::MYSQL_TYPE_FLOAT, false);
rt!(f64_one, f64, 1.0, ColumnType::MYSQL_TYPE_DOUBLE, false);

rt!(
u8_max,
u8,
u8::max_value(),
ColumnType::MYSQL_TYPE_TINY,
false
);
rt!(
i8_max,
i8,
i8::max_value(),
ColumnType::MYSQL_TYPE_TINY,
true
);
rt!(
u16_max,
u16,
u16::max_value(),
ColumnType::MYSQL_TYPE_SHORT,
false
);
rt!(
i16_max,
i16,
i16::max_value(),
ColumnType::MYSQL_TYPE_SHORT,
true
);
rt!(
u32_max,
u32,
u32::max_value(),
ColumnType::MYSQL_TYPE_LONG,
false
);
rt!(
i32_max,
i32,
i32::max_value(),
ColumnType::MYSQL_TYPE_LONG,
true
);
rt!(u8_max, u8, u8::MAX, ColumnType::MYSQL_TYPE_TINY, false);
rt!(i8_max, i8, i8::MAX, ColumnType::MYSQL_TYPE_TINY, true);
rt!(u16_max, u16, u16::MAX, ColumnType::MYSQL_TYPE_SHORT, false);
rt!(i16_max, i16, i16::MAX, ColumnType::MYSQL_TYPE_SHORT, true);
rt!(u32_max, u32, u32::MAX, ColumnType::MYSQL_TYPE_LONG, false);
rt!(i32_max, i32, i32::MAX, ColumnType::MYSQL_TYPE_LONG, true);
rt!(
u64_max,
u64,
u64::max_value(),
u64::MAX,
ColumnType::MYSQL_TYPE_LONGLONG,
false
);
rt!(
i64_max,
i64,
i64::max_value(),
i64::MAX,
ColumnType::MYSQL_TYPE_LONGLONG,
true
);
Expand Down
22 changes: 11 additions & 11 deletions mysql/src/value/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ where
// NOTE: yes, I know the = / => distinction is ugly
macro_rules! like_try_into {
($self:ident, $source:ty = $target:ty, $w:ident, $m:ident, $c:ident) => {{
let min = <$target>::min_value() as $source;
let max = <$target>::max_value() as $source;
let min = <$target>::MIN as $source;
let max = <$target>::MAX as $source;
if *$self <= max && *$self >= min {
$w.$m(*$self as $target)
} else {
Err(bad($self, $c))
}
}};
($self:ident, $source:ty => $target:ty, $w:ident, $m:ident, $c:ident) => {{
let min = <$target>::min_value() as $source;
let max = <$target>::max_value() as $source;
let min = <$target>::MIN as $source;
let max = <$target>::MAX as $source;
if *$self <= max && *$self >= min {
$w.$m::<LittleEndian>(*$self as $target)
} else {
Expand Down Expand Up @@ -618,25 +618,25 @@ impl ToMysqlValue for myc::value::Value {
// smallest containing type, and then call on that
let signed = !c.colflags.contains(ColumnFlags::UNSIGNED_FLAG);
if signed {
if n >= i64::from(i8::min_value()) && n <= i64::from(i8::max_value()) {
if n >= i64::from(i8::MIN) && n <= i64::from(i8::MAX) {
(n as i8).to_mysql_bin(w, c)
} else if n >= i64::from(i16::min_value()) && n <= i64::from(i16::max_value()) {
} else if n >= i64::from(i16::MIN) && n <= i64::from(i16::MAX) {
(n as i16).to_mysql_bin(w, c)
} else if n >= i64::from(i32::min_value()) && n <= i64::from(i32::max_value()) {
} else if n >= i64::from(i32::MIN) && n <= i64::from(i32::MAX) {
(n as i32).to_mysql_bin(w, c)
} else {
n.to_mysql_bin(w, c)
}
} else if n < 0 {
Err(bad(self, c))
} else if n <= i64::from(u8::max_value()) {
} else if n <= i64::from(u8::MAX) {
(n as u8).to_mysql_bin(w, c)
} else if n <= i64::from(u16::max_value()) {
} else if n <= i64::from(u16::MAX) {
(n as u16).to_mysql_bin(w, c)
} else if n <= i64::from(u32::max_value()) {
} else if n <= i64::from(u32::MAX) {
(n as u32).to_mysql_bin(w, c)
} else {
// must work since u64::max_value() > i64::max_value(), and n >= 0
// must work since u64::MAX > i64::MAX, and n >= 0
(n as u64).to_mysql_bin(w, c)
}
}
Expand Down

0 comments on commit 6cbb806

Please sign in to comment.