From e94b89ef5f35fc971fd80d0d7200af9c28627241 Mon Sep 17 00:00:00 2001 From: muzarski Date: Wed, 3 Jan 2024 08:34:38 +0100 Subject: [PATCH 01/14] value: introduce `CqlVarint` type Added a `CqlVarint` type which represents the native cql varint type. Varint value is represented as a signed binary in big-endian order. --- scylla-cql/src/frame/value.rs | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/scylla-cql/src/frame/value.rs b/scylla-cql/src/frame/value.rs index 22a66f6732..00d0fb0a5b 100644 --- a/scylla-cql/src/frame/value.rs +++ b/scylla-cql/src/frame/value.rs @@ -215,6 +215,70 @@ impl std::hash::Hash for CqlTimeuuid { } } +/// Native CQL `varint` representation. +/// +/// Represented as two's-complement binary in big-endian order. +/// +/// This type is a raw representation in bytes. It's the default +/// implementation of `varint` type - independent of any +/// external crates and crate features. +/// +/// # DB data format +/// Notice that [constructors](CqlVarint#impl-CqlVarint) +/// don't perform any normalization on the provided data. +/// This means that underlying bytes may contain leading zeros. +/// +/// Currently, Scylla and Cassandra support non-normalized `varint` values. +/// Bytes provided by the user via constructor are passed to DB as is. +#[derive(Clone, Debug)] +pub struct CqlVarint(Vec); + +/// Constructors from bytes +impl CqlVarint { + /// Creates a [`CqlVarint`] from an array of bytes in + /// two's complement big-endian binary representation. + /// + /// See: disclaimer about [non-normalized values](CqlVarint#db-data-format). + pub fn from_signed_bytes_be(digits: Vec) -> Self { + Self(digits) + } + + /// Creates a [`CqlVarint`] from a slice of bytes in + /// two's complement binary big-endian representation. + /// + /// See: disclaimer about [non-normalized values](CqlVarint#db-data-format). + pub fn from_signed_bytes_be_slice(digits: &[u8]) -> Self { + Self::from_signed_bytes_be(digits.to_vec()) + } +} + +/// Conversion to bytes +impl CqlVarint { + /// Converts [`CqlVarint`] to an array of bytes in two's + /// complement binary big-endian representation. + pub fn into_signed_bytes_be(self) -> Vec { + self.0 + } + + /// Returns a slice of bytes in two's complement + /// binary big-endian representation. + pub fn as_signed_bytes_be_slice(&self) -> &[u8] { + &self.0 + } +} + +impl From for CqlVarint { + fn from(value: BigInt) -> Self { + Self(value.to_signed_bytes_be()) + } +} + +impl From for BigInt { + fn from(val: CqlVarint) -> Self { + BigInt::from_signed_bytes_be(&val.0) + } +} + /// Native CQL date representation that allows for a bigger range of dates (-262145-1-1 to 262143-12-31). /// /// Represented as number of days since -5877641-06-23 i.e. 2^31 days before unix epoch. From 65146eb1a5797841b9ecda27c187214a61d3f0b4 Mon Sep 17 00:00:00 2001 From: muzarski Date: Thu, 25 Jan 2024 15:46:38 +0100 Subject: [PATCH 02/14] varint: implement PartialEq for CqlVarint --- scylla-cql/src/frame/value.rs | 60 ++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/scylla-cql/src/frame/value.rs b/scylla-cql/src/frame/value.rs index 00d0fb0a5b..44eb254129 100644 --- a/scylla-cql/src/frame/value.rs +++ b/scylla-cql/src/frame/value.rs @@ -230,7 +230,10 @@ impl std::hash::Hash for CqlTimeuuid { /// /// Currently, Scylla and Cassandra support non-normalized `varint` values. /// Bytes provided by the user via constructor are passed to DB as is. -#[derive(Clone, Debug)] +/// +/// The implementation of [`PartialEq`], however, normalizes the underlying bytes +/// before comparison. For details, check [examples](#impl-PartialEq-for-CqlVarint). +#[derive(Clone, Eq, Debug)] pub struct CqlVarint(Vec); /// Constructors from bytes @@ -267,6 +270,42 @@ impl CqlVarint { } } +impl CqlVarint { + fn as_normalized_slice(&self) -> &[u8] { + let digits = self.0.as_slice(); + if digits.is_empty() { + // num-bigint crate normalizes empty vector to 0. + // We will follow the same approach. + return &[0]; + } + + let non_zero_position = match digits.iter().position(|b| *b != 0) { + Some(pos) => pos, + None => { + // Vector is filled with zeros. Represent it as 0. + return &[0]; + } + }; + + if non_zero_position > 0 { + // There were some leading zeros. + // Now, there are two cases: + let zeros_to_remove = if digits[non_zero_position] > 0x7f { + // Most significant bit is 1, so we need to include one of the leading + // zeros as originally it represented a positive number. + non_zero_position - 1 + } else { + // Most significant bit is 0 - positive number with no leading zeros. + non_zero_position + }; + return &digits[zeros_to_remove..]; + } + + // There were no leading zeros at all - leave as is. + digits + } +} + impl From for CqlVarint { fn from(value: BigInt) -> Self { Self(value.to_signed_bytes_be()) @@ -279,6 +318,25 @@ impl From for BigInt { } } +/// Compares two [`CqlVarint`] values after normalization. +/// +/// # Example +/// +/// ```rust +/// # use scylla_cql::frame::value::CqlVarint; +/// let non_normalized_bytes = vec![0x00, 0x01]; +/// let normalized_bytes = vec![0x01]; +/// assert_eq!( +/// CqlVarint::from_signed_bytes_be(non_normalized_bytes), +/// CqlVarint::from_signed_bytes_be(normalized_bytes) +/// ); +/// ``` +impl PartialEq for CqlVarint { + fn eq(&self, other: &Self) -> bool { + self.as_normalized_slice() == other.as_normalized_slice() + } +} + /// Native CQL date representation that allows for a bigger range of dates (-262145-1-1 to 262143-12-31). /// /// Represented as number of days since -5877641-06-23 i.e. 2^31 days before unix epoch. From 9ddaedf7b9be6eb3412370e29b464b700ba63232 Mon Sep 17 00:00:00 2001 From: muzarski Date: Fri, 26 Jan 2024 12:27:29 +0100 Subject: [PATCH 03/14] varint: implement std::hash::Hash for CqlVarint --- scylla-cql/src/frame/value.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scylla-cql/src/frame/value.rs b/scylla-cql/src/frame/value.rs index 44eb254129..7f82299dab 100644 --- a/scylla-cql/src/frame/value.rs +++ b/scylla-cql/src/frame/value.rs @@ -337,6 +337,13 @@ impl PartialEq for CqlVarint { } } +/// Computes the hash of normalized [`CqlVarint`]. +impl std::hash::Hash for CqlVarint { + fn hash(&self, state: &mut H) { + self.as_normalized_slice().hash(state) + } +} + /// Native CQL date representation that allows for a bigger range of dates (-262145-1-1 to 262143-12-31). /// /// Represented as number of days since -5877641-06-23 i.e. 2^31 days before unix epoch. From 62acc159a4ce3923aa883f2bbce9cdc1eff46c5c Mon Sep 17 00:00:00 2001 From: muzarski Date: Fri, 26 Jan 2024 12:38:36 +0100 Subject: [PATCH 04/14] value_tests: add compute_hash util function --- scylla-cql/src/frame/value_tests.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scylla-cql/src/frame/value_tests.rs b/scylla-cql/src/frame/value_tests.rs index e168e8c4fb..2e3db0c7e9 100644 --- a/scylla-cql/src/frame/value_tests.rs +++ b/scylla-cql/src/frame/value_tests.rs @@ -44,6 +44,12 @@ fn serialized_only_new(val: T, typ: ColumnType) -> Vec { result } +fn compute_hash(x: &T) -> u64 { + let mut hasher = DefaultHasher::new(); + x.hash(&mut hasher); + hasher.finish() +} + #[test] fn boolean_serialization() { assert_eq!(serialized(true, ColumnType::Boolean), vec![0, 0, 0, 1, 1]); @@ -550,12 +556,6 @@ fn timeuuid_ordering_properties() { assert_eq!(std::cmp::Ordering::Equal, cmp_res); assert_eq!(x, y); - - let compute_hash = |x: &CqlTimeuuid| { - let mut hasher = DefaultHasher::new(); - x.hash(&mut hasher); - hasher.finish() - }; assert_eq!(compute_hash(&x), compute_hash(&y)); } From f701d8fe8fcf0c4059ae339aa5693406100fbe8b Mon Sep 17 00:00:00 2001 From: muzarski Date: Fri, 12 Jan 2024 16:01:20 +0100 Subject: [PATCH 05/14] value_tests: add tests for CqlVarint normalization --- scylla-cql/src/frame/value_tests.rs | 45 +++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/scylla-cql/src/frame/value_tests.rs b/scylla-cql/src/frame/value_tests.rs index 2e3db0c7e9..65ee254b3c 100644 --- a/scylla-cql/src/frame/value_tests.rs +++ b/scylla-cql/src/frame/value_tests.rs @@ -7,8 +7,8 @@ use crate::types::serialize::{CellWriter, RowWriter}; use super::response::result::{ColumnSpec, ColumnType, TableSpec}; use super::value::{ - CqlDate, CqlDuration, CqlTime, CqlTimestamp, LegacyBatchValues, LegacySerializedValues, - MaybeUnset, SerializeValuesError, Unset, Value, ValueList, ValueTooBig, + CqlDate, CqlDuration, CqlTime, CqlTimestamp, CqlVarint, LegacyBatchValues, + LegacySerializedValues, MaybeUnset, SerializeValuesError, Unset, Value, ValueList, ValueTooBig, }; use bigdecimal::BigDecimal; use bytes::BufMut; @@ -81,6 +81,47 @@ fn counter_serialization() { ); } +fn cql_varint_normalization_test_cases() -> [(Vec, Vec); 11] { + [ + (vec![], vec![0x00]), // 0 + (vec![0x00], vec![0x00]), // 0 + (vec![0x00, 0x00], vec![0x00]), // 0 + (vec![0x01], vec![0x01]), // 1 + (vec![0x00, 0x01], vec![0x01]), // 1 + (vec![0x7f], vec![0x7f]), // 127 + (vec![0x00, 0x7f], vec![0x7f]), // 127 + (vec![0x80], vec![0x80]), // -128 + (vec![0x00, 0x80], vec![0x00, 0x80]), // 128 + (vec![0xff], vec![0xff]), // -1 + (vec![0x00, 0xff], vec![0x00, 0xff]), // 255 + ] +} + +#[test] +fn cql_varint_normalization() { + let test_cases = cql_varint_normalization_test_cases(); + + for test in test_cases { + let non_normalized = CqlVarint::from_signed_bytes_be(test.0); + let normalized = CqlVarint::from_signed_bytes_be(test.1); + + assert_eq!(non_normalized, normalized); + assert_eq!(compute_hash(&non_normalized), compute_hash(&normalized)); + } +} + +#[test] +fn cql_varint_normalization_with_bigint() { + let test_cases = cql_varint_normalization_test_cases(); + + for test in test_cases { + let non_normalized: BigInt = CqlVarint::from_signed_bytes_be(test.0).into(); + let normalized: BigInt = CqlVarint::from_signed_bytes_be(test.1).into(); + + assert_eq!(non_normalized, normalized); + } +} + #[test] fn bigint_serialization() { let cases_from_the_spec: &[(i64, Vec)] = &[ From 53cf06c586a4cfa3c33f4572f1a9eea99f2e3cbc Mon Sep 17 00:00:00 2001 From: muzarski Date: Wed, 3 Jan 2024 09:16:29 +0100 Subject: [PATCH 06/14] cql: wrap `CqlVarint` with `CqlValue::Varint` --- scylla-cql/src/frame/response/cql_to_rust.rs | 17 ++++++++++++++--- scylla-cql/src/frame/response/result.rs | 13 +++++++------ scylla-cql/src/frame/value.rs | 12 ++++++++++++ scylla-cql/src/types/serialize/value.rs | 11 ++++++++++- scylla/src/utils/pretty.rs | 6 +++++- 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/scylla-cql/src/frame/response/cql_to_rust.rs b/scylla-cql/src/frame/response/cql_to_rust.rs index fb9b5bf249..e473cc4956 100644 --- a/scylla-cql/src/frame/response/cql_to_rust.rs +++ b/scylla-cql/src/frame/response/cql_to_rust.rs @@ -1,5 +1,7 @@ use super::result::{CqlValue, Row}; -use crate::frame::value::{Counter, CqlDate, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid}; +use crate::frame::value::{ + Counter, CqlDate, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid, CqlVarint, +}; use bigdecimal::BigDecimal; use num_bigint::BigInt; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; @@ -125,7 +127,7 @@ impl_from_cql_value_from_method!(i32, as_int); // i32::from_cql impl_from_cql_value_from_method!(i64, as_bigint); // i64::from_cql impl_from_cql_value_from_method!(Counter, as_counter); // Counter::from_cql impl_from_cql_value_from_method!(i16, as_smallint); // i16::from_cql -impl_from_cql_value_from_method!(BigInt, into_varint); // BigInt::from_cql +impl_from_cql_value_from_method!(CqlVarint, into_cql_varint); // CqlVarint::from_cql impl_from_cql_value_from_method!(i8, as_tinyint); // i8::from_cql impl_from_cql_value_from_method!(f32, as_float); // f32::from_cql impl_from_cql_value_from_method!(f64, as_double); // f64::from_cql @@ -148,6 +150,15 @@ impl FromCqlVal for [u8; N] { } } +impl FromCqlVal for BigInt { + fn from_cql(cql_val: CqlValue) -> Result { + match cql_val { + CqlValue::Varint(cql_varint) => Ok(cql_varint.into()), + _ => Err(FromCqlValError::BadCqlType), + } + } +} + #[cfg(feature = "chrono")] impl FromCqlVal for NaiveDate { fn from_cql(cql_val: CqlValue) -> Result { @@ -463,7 +474,7 @@ mod tests { let big_int = 0.to_bigint().unwrap(); assert_eq!( Ok(big_int), - BigInt::from_cql(CqlValue::Varint(0.to_bigint().unwrap())) + BigInt::from_cql(CqlValue::Varint(0.to_bigint().unwrap().into())) ); } diff --git a/scylla-cql/src/frame/response/result.rs b/scylla-cql/src/frame/response/result.rs index 0833cda62a..938f917a73 100644 --- a/scylla-cql/src/frame/response/result.rs +++ b/scylla-cql/src/frame/response/result.rs @@ -1,12 +1,13 @@ use crate::cql_to_rust::{FromRow, FromRowError}; use crate::frame::response::event::SchemaChangeEvent; use crate::frame::types::vint_decode; -use crate::frame::value::{Counter, CqlDate, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid}; +use crate::frame::value::{ + Counter, CqlDate, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid, CqlVarint, +}; use crate::frame::{frame_errors::ParseError, types}; use bigdecimal::BigDecimal; use byteorder::{BigEndian, ReadBytesExt}; use bytes::{Buf, Bytes}; -use num_bigint::BigInt; use std::{ convert::{TryFrom, TryInto}, net::IpAddr, @@ -113,7 +114,7 @@ pub enum CqlValue { Timeuuid(CqlTimeuuid), Tuple(Vec>), Uuid(Uuid), - Varint(BigInt), + Varint(CqlVarint), } impl ColumnType { @@ -363,7 +364,7 @@ impl CqlValue { } } - pub fn into_varint(self) -> Option { + pub fn into_cql_varint(self) -> Option { match self { Self::Varint(i) => Some(i), _ => None, @@ -810,7 +811,7 @@ pub fn deser_cql_value(typ: &ColumnType, buf: &mut &[u8]) -> StdResult CqlValue::Varint(num_bigint::BigInt::from_signed_bytes_be(buf)), + Varint => CqlValue::Varint(CqlVarint::from_signed_bytes_be(buf.to_vec())), List(type_name) => { let len: usize = types::read_int(buf)?.try_into()?; let mut res = Vec::with_capacity(len); @@ -1086,7 +1087,7 @@ mod tests { for t in tests.iter() { let value = super::deser_cql_value(&ColumnType::Varint, &mut &*t.encoding).unwrap(); - assert_eq!(CqlValue::Varint(t.value.clone()), value); + assert_eq!(CqlValue::Varint(t.value.clone().into()), value); } } diff --git a/scylla-cql/src/frame/value.rs b/scylla-cql/src/frame/value.rs index 7f82299dab..7349ca1a5c 100644 --- a/scylla-cql/src/frame/value.rs +++ b/scylla-cql/src/frame/value.rs @@ -995,6 +995,18 @@ impl Value for CqlTimeuuid { } } +impl Value for CqlVarint { + fn serialize(&self, buf: &mut Vec) -> Result<(), ValueTooBig> { + let serialized = &self.0; + let serialized_len: i32 = serialized.len().try_into().map_err(|_| ValueTooBig)?; + + buf.put_i32(serialized_len); + buf.extend_from_slice(serialized); + + Ok(()) + } +} + impl Value for BigInt { fn serialize(&self, buf: &mut Vec) -> Result<(), ValueTooBig> { let serialized = self.to_signed_bytes_be(); diff --git a/scylla-cql/src/types/serialize/value.rs b/scylla-cql/src/types/serialize/value.rs index 8abe509585..f83957f214 100644 --- a/scylla-cql/src/types/serialize/value.rs +++ b/scylla-cql/src/types/serialize/value.rs @@ -20,7 +20,8 @@ use secrecy::{ExposeSecret, Secret, Zeroize}; use crate::frame::response::result::{ColumnType, CqlValue}; use crate::frame::types::vint_encode; use crate::frame::value::{ - Counter, CqlDate, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid, MaybeUnset, Unset, Value, + Counter, CqlDate, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid, CqlVarint, MaybeUnset, + Unset, Value, }; #[cfg(feature = "chrono")] @@ -233,6 +234,14 @@ impl SerializeCql for CqlTimeuuid { writer.set_value(me.as_bytes().as_ref()).unwrap() }); } +impl SerializeCql for CqlVarint { + impl_serialize_via_writer!(|me, typ, writer| { + exact_type_check!(typ, Varint); + writer + .set_value(me.as_signed_bytes_be_slice()) + .map_err(|_| mk_ser_err::(typ, BuiltinSerializationErrorKind::SizeOverflow))? + }); +} impl SerializeCql for BigInt { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Varint); diff --git a/scylla/src/utils/pretty.rs b/scylla/src/utils/pretty.rs index c3e6fb71fa..56d0c78514 100644 --- a/scylla/src/utils/pretty.rs +++ b/scylla/src/utils/pretty.rs @@ -51,7 +51,11 @@ where CqlValue::Inet(i) => write!(f, "'{}'", i)?, CqlValue::SmallInt(si) => write!(f, "{}", si)?, CqlValue::TinyInt(ti) => write!(f, "{}", ti)?, - CqlValue::Varint(vi) => write!(f, "{}", vi)?, + CqlValue::Varint(vi) => write!( + f, + "blobAsVarint(0x{:x})", + HexBytes(vi.as_signed_bytes_be_slice()) + )?, CqlValue::Counter(c) => write!(f, "{}", c.0)?, CqlValue::Date(CqlDate(d)) => { let days_since_epoch = chrono::Duration::days(*d as i64 - (1 << 31)); From ae623b01ba17bd9e88dfd075cead5f1d5a3a4db2 Mon Sep 17 00:00:00 2001 From: muzarski Date: Wed, 3 Jan 2024 10:47:40 +0100 Subject: [PATCH 07/14] tests: add tests for `CqlVarint` --- scylla-cql/src/frame/value_tests.rs | 31 +++++++++- scylla/src/transport/cql_types_test.rs | 84 +++++++++++++++++++++++++- 2 files changed, 111 insertions(+), 4 deletions(-) diff --git a/scylla-cql/src/frame/value_tests.rs b/scylla-cql/src/frame/value_tests.rs index 65ee254b3c..38a7336789 100644 --- a/scylla-cql/src/frame/value_tests.rs +++ b/scylla-cql/src/frame/value_tests.rs @@ -1,4 +1,4 @@ -use crate::frame::value::CqlTimeuuid; +use crate::frame::value::{CqlTimeuuid, CqlVarint}; use crate::frame::{response::result::CqlValue, types::RawValue, value::LegacyBatchValuesIterator}; use crate::types::serialize::batch::{BatchValues, BatchValuesIterator, LegacyBatchValuesAdapter}; use crate::types::serialize::row::{RowSerializationContext, SerializeRow}; @@ -7,8 +7,8 @@ use crate::types::serialize::{CellWriter, RowWriter}; use super::response::result::{ColumnSpec, ColumnType, TableSpec}; use super::value::{ - CqlDate, CqlDuration, CqlTime, CqlTimestamp, CqlVarint, LegacyBatchValues, - LegacySerializedValues, MaybeUnset, SerializeValuesError, Unset, Value, ValueList, ValueTooBig, + CqlDate, CqlDuration, CqlTime, CqlTimestamp, LegacyBatchValues, LegacySerializedValues, + MaybeUnset, SerializeValuesError, Unset, Value, ValueList, ValueTooBig, }; use bigdecimal::BigDecimal; use bytes::BufMut; @@ -122,6 +122,31 @@ fn cql_varint_normalization_with_bigint() { } } +#[test] +fn cql_varint_serialization() { + let cases_from_the_spec: &[Vec] = &[ + vec![0x00], + vec![0x01], + vec![0x7F], + vec![0x00, 0x80], + vec![0x00, 0x81], + vec![0xFF], + vec![0x80], + vec![0xFF, 0x7F], + ]; + + for b in cases_from_the_spec { + let x = CqlVarint::from_signed_bytes_be_slice(b); + let b_with_len = (b.len() as i32) + .to_be_bytes() + .iter() + .chain(b) + .cloned() + .collect::>(); + assert_eq!(serialized(x, ColumnType::Varint), b_with_len); + } +} + #[test] fn bigint_serialization() { let cases_from_the_spec: &[(i64, Vec)] = &[ diff --git a/scylla/src/transport/cql_types_test.rs b/scylla/src/transport/cql_types_test.rs index 0efe56b5c9..d895974076 100644 --- a/scylla/src/transport/cql_types_test.rs +++ b/scylla/src/transport/cql_types_test.rs @@ -10,7 +10,7 @@ use crate::utils::test_utils::unique_keyspace_name; use bigdecimal::BigDecimal; use itertools::Itertools; use num_bigint::BigInt; -use scylla_cql::frame::value::CqlTimeuuid; +use scylla_cql::frame::value::{CqlTimeuuid, CqlVarint}; use scylla_cql::types::serialize::value::SerializeCql; use scylla_macros::SerializeCql; use std::cmp::PartialEq; @@ -122,6 +122,88 @@ async fn test_varint() { run_tests::(&tests, "varint").await; } +#[tokio::test] +async fn test_cql_varint() { + let tests = [ + vec![0x00], // 0 + vec![0x01], // 1 + vec![0x00, 0x01], // 1 (with leading zeros) + vec![0x7F], // 127 + vec![0x00, 0x80], // 128 + vec![0x00, 0x81], // 129 + vec![0xFF], // -1 + vec![0x80], // -128 + vec![0xFF, 0x7F], // -129 + vec![ + 0x01, 0x8E, 0xE9, 0x0F, 0xF6, 0xC3, 0x73, 0xE0, 0xEE, 0x4E, 0x3F, 0x0A, 0xD2, + ], // 123456789012345678901234567890 + vec![ + 0xFE, 0x71, 0x16, 0xF0, 0x09, 0x3C, 0x8C, 0x1F, 0x11, 0xB1, 0xC0, 0xF5, 0x2E, + ], // -123456789012345678901234567890 + ]; + + let table_name = "cql_varint_tests"; + let session: Session = create_new_session_builder().build().await.unwrap(); + let ks = unique_keyspace_name(); + + session + .query( + format!( + "CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = \ + {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", + ks + ), + &[], + ) + .await + .unwrap(); + session.use_keyspace(ks, false).await.unwrap(); + + session + .query( + format!( + "CREATE TABLE IF NOT EXISTS {} (id int PRIMARY KEY, val varint)", + table_name + ), + &[], + ) + .await + .unwrap(); + + let prepared_insert = session + .prepare(format!( + "INSERT INTO {} (id, val) VALUES (0, ?)", + table_name + )) + .await + .unwrap(); + let prepared_select = session + .prepare(format!("SELECT val FROM {} WHERE id = 0", table_name)) + .await + .unwrap(); + + for test in tests { + let cql_varint = CqlVarint::from_signed_bytes_be_slice(&test); + session + .execute(&prepared_insert, (&cql_varint,)) + .await + .unwrap(); + + let read_values: Vec = session + .execute(&prepared_select, &[]) + .await + .unwrap() + .rows + .unwrap() + .into_typed::<(CqlVarint,)>() + .map(Result::unwrap) + .map(|row| row.0) + .collect::>(); + + assert_eq!(read_values, vec![cql_varint]) + } +} + #[tokio::test] async fn test_decimal() { let tests = [ From a851069539383b0181cd6b0b743b5c55d459a3a8 Mon Sep 17 00:00:00 2001 From: muzarski Date: Wed, 3 Jan 2024 11:27:21 +0100 Subject: [PATCH 08/14] cargo: hide `num_bigint` v0.3 behind feature flag Hidden public usages of the `num_bigint::BigInt` (version 0.3) behind `num-bigint-03` feature flag. --- examples/Cargo.toml | 2 +- scylla-cql/Cargo.toml | 5 +++-- scylla-cql/src/frame/response/cql_to_rust.rs | 10 ++++++---- scylla-cql/src/frame/response/result.rs | 9 +++++---- scylla-cql/src/frame/value.rs | 14 ++++++++------ scylla-cql/src/frame/value_tests.rs | 15 ++++++++------- scylla-cql/src/types/serialize/value.rs | 6 +++--- scylla/Cargo.toml | 5 +++-- scylla/src/transport/cql_types_test.rs | 4 ++-- 9 files changed, 39 insertions(+), 31 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 88a7dbda62..d6cf6e356d 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -10,7 +10,7 @@ futures = "0.3.6" openssl = "0.10.32" rustyline = "9" rustyline-derive = "0.6" -scylla = {path = "../scylla", features = ["ssl", "cloud", "chrono", "time"]} +scylla = {path = "../scylla", features = ["ssl", "cloud", "chrono", "time", "num-bigint-03"]} tokio = {version = "1.1.0", features = ["full"]} tracing = "0.1.25" tracing-subscriber = { version = "0.3.14", features = ["env-filter"] } diff --git a/scylla-cql/Cargo.toml b/scylla-cql/Cargo.toml index c919ec4787..a298888164 100644 --- a/scylla-cql/Cargo.toml +++ b/scylla-cql/Cargo.toml @@ -20,7 +20,7 @@ snap = "1.0" uuid = "1.0" thiserror = "1.0" bigdecimal = "0.2.0" -num-bigint = "0.3" +num-bigint-03 = { package = "num-bigint", version = "0.3", optional = true } chrono = { version = "0.4.27", default-features = false, optional = true } lz4_flex = { version = "0.11.1" } async-trait = "0.1.57" @@ -40,4 +40,5 @@ harness = false secret = ["secrecy"] time = ["dep:time"] chrono = ["dep:chrono"] -full-serialization = ["chrono", "time", "secret"] +num-bigint-03 = ["dep:num-bigint-03"] +full-serialization = ["chrono", "time", "secret", "num-bigint-03"] diff --git a/scylla-cql/src/frame/response/cql_to_rust.rs b/scylla-cql/src/frame/response/cql_to_rust.rs index e473cc4956..2392be8e41 100644 --- a/scylla-cql/src/frame/response/cql_to_rust.rs +++ b/scylla-cql/src/frame/response/cql_to_rust.rs @@ -3,7 +3,6 @@ use crate::frame::value::{ Counter, CqlDate, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid, CqlVarint, }; use bigdecimal::BigDecimal; -use num_bigint::BigInt; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use std::hash::{BuildHasher, Hash}; use std::net::IpAddr; @@ -150,7 +149,8 @@ impl FromCqlVal for [u8; N] { } } -impl FromCqlVal for BigInt { +#[cfg(feature = "num-bigint-03")] +impl FromCqlVal for num_bigint_03::BigInt { fn from_cql(cql_val: CqlValue) -> Result { match cql_val { CqlValue::Varint(cql_varint) => Ok(cql_varint.into()), @@ -405,7 +405,6 @@ mod tests { use crate::frame::value::{Counter, CqlDate, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid}; use crate::macros::FromRow; use bigdecimal::BigDecimal; - use num_bigint::{BigInt, ToBigInt}; use std::collections::HashSet; use std::net::{IpAddr, Ipv4Addr}; use std::str::FromStr; @@ -469,12 +468,15 @@ mod tests { assert_eq!(Ok(ip_addr), IpAddr::from_cql(CqlValue::Inet(ip_addr))); } + #[cfg(feature = "num-bigint-03")] #[test] fn varint_from_cql() { + use num_bigint_03::ToBigInt; + let big_int = 0.to_bigint().unwrap(); assert_eq!( Ok(big_int), - BigInt::from_cql(CqlValue::Varint(0.to_bigint().unwrap().into())) + num_bigint_03::BigInt::from_cql(CqlValue::Varint(0.to_bigint().unwrap().into())) ); } diff --git a/scylla-cql/src/frame/response/result.rs b/scylla-cql/src/frame/response/result.rs index 938f917a73..96efc0a0d9 100644 --- a/scylla-cql/src/frame/response/result.rs +++ b/scylla-cql/src/frame/response/result.rs @@ -672,7 +672,7 @@ pub fn deser_cql_value(typ: &ColumnType, buf: &mut &[u8]) -> StdResult { let scale = types::read_int(buf)? as i64; - let int_value = num_bigint::BigInt::from_signed_bytes_be(buf); + let int_value = bigdecimal::num_bigint::BigInt::from_signed_bytes_be(buf); let big_decimal: BigDecimal = BigDecimal::from((int_value, scale)); CqlValue::Decimal(big_decimal) @@ -968,8 +968,6 @@ mod tests { use crate as scylla; use crate::frame::value::{Counter, CqlDate, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid}; use bigdecimal::BigDecimal; - use num_bigint::BigInt; - use num_bigint::ToBigInt; use scylla::frame::response::result::{ColumnType, CqlValue}; use std::str::FromStr; use uuid::Uuid; @@ -1029,10 +1027,13 @@ mod tests { assert_eq!(double_serialize, CqlValue::Double(double)); } + #[cfg(feature = "num-bigint-03")] #[test] fn test_varint() { + use num_bigint_03::ToBigInt; + struct Test<'a> { - value: BigInt, + value: num_bigint_03::BigInt, encoding: &'a [u8], } diff --git a/scylla-cql/src/frame/value.rs b/scylla-cql/src/frame/value.rs index 7349ca1a5c..3626de87ae 100644 --- a/scylla-cql/src/frame/value.rs +++ b/scylla-cql/src/frame/value.rs @@ -2,7 +2,6 @@ use crate::frame::frame_errors::ParseError; use crate::frame::types; use bigdecimal::BigDecimal; use bytes::BufMut; -use num_bigint::BigInt; use std::borrow::Cow; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use std::convert::TryInto; @@ -306,15 +305,17 @@ impl CqlVarint { } } -impl From for CqlVarint { - fn from(value: BigInt) -> Self { +#[cfg(feature = "num-bigint-03")] +impl From for CqlVarint { + fn from(value: num_bigint_03::BigInt) -> Self { Self(value.to_signed_bytes_be()) } } -impl From for BigInt { +#[cfg(feature = "num-bigint-03")] +impl From for num_bigint_03::BigInt { fn from(val: CqlVarint) -> Self { - BigInt::from_signed_bytes_be(&val.0) + num_bigint_03::BigInt::from_signed_bytes_be(&val.0) } } @@ -1007,7 +1008,8 @@ impl Value for CqlVarint { } } -impl Value for BigInt { +#[cfg(feature = "num-bigint-03")] +impl Value for num_bigint_03::BigInt { fn serialize(&self, buf: &mut Vec) -> Result<(), ValueTooBig> { let serialized = self.to_signed_bytes_be(); let serialized_len: i32 = serialized.len().try_into().map_err(|_| ValueTooBig)?; diff --git a/scylla-cql/src/frame/value_tests.rs b/scylla-cql/src/frame/value_tests.rs index 38a7336789..53f8a65bd4 100644 --- a/scylla-cql/src/frame/value_tests.rs +++ b/scylla-cql/src/frame/value_tests.rs @@ -12,7 +12,6 @@ use super::value::{ }; use bigdecimal::BigDecimal; use bytes::BufMut; -use num_bigint::BigInt; use std::collections::hash_map::DefaultHasher; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use std::hash::{BuildHasherDefault, Hash, Hasher}; @@ -110,13 +109,14 @@ fn cql_varint_normalization() { } } +#[cfg(feature = "num-bigint-03")] #[test] -fn cql_varint_normalization_with_bigint() { +fn cql_varint_normalization_with_bigint03() { let test_cases = cql_varint_normalization_test_cases(); for test in test_cases { - let non_normalized: BigInt = CqlVarint::from_signed_bytes_be(test.0).into(); - let normalized: BigInt = CqlVarint::from_signed_bytes_be(test.1).into(); + let non_normalized: num_bigint_03::BigInt = CqlVarint::from_signed_bytes_be(test.0).into(); + let normalized: num_bigint_03::BigInt = CqlVarint::from_signed_bytes_be(test.1).into(); assert_eq!(non_normalized, normalized); } @@ -147,8 +147,9 @@ fn cql_varint_serialization() { } } +#[cfg(feature = "num-bigint-03")] #[test] -fn bigint_serialization() { +fn bigint03_serialization() { let cases_from_the_spec: &[(i64, Vec)] = &[ (0, vec![0x00]), (1, vec![0x01]), @@ -161,7 +162,7 @@ fn bigint_serialization() { ]; for (i, b) in cases_from_the_spec { - let x = BigInt::from(*i); + let x = num_bigint_03::BigInt::from(*i); let b_with_len = (b.len() as i32) .to_be_bytes() .iter() @@ -195,7 +196,7 @@ fn bigdecimal_serialization() { .chain(serialized_digits) .cloned() .collect::>(); - let digits = BigInt::from(*digits); + let digits = bigdecimal::num_bigint::BigInt::from(*digits); let x = BigDecimal::new(digits, exponent as i64); assert_eq!(serialized(x, ColumnType::Decimal), repr); } diff --git a/scylla-cql/src/types/serialize/value.rs b/scylla-cql/src/types/serialize/value.rs index f83957f214..aac38d48f3 100644 --- a/scylla-cql/src/types/serialize/value.rs +++ b/scylla-cql/src/types/serialize/value.rs @@ -7,7 +7,6 @@ use std::net::IpAddr; use std::sync::Arc; use bigdecimal::BigDecimal; -use num_bigint::BigInt; use thiserror::Error; use uuid::Uuid; @@ -242,7 +241,8 @@ impl SerializeCql for CqlVarint { .map_err(|_| mk_ser_err::(typ, BuiltinSerializationErrorKind::SizeOverflow))? }); } -impl SerializeCql for BigInt { +#[cfg(feature = "num-bigint-03")] +impl SerializeCql for num_bigint_03::BigInt { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Varint); // TODO: The allocation here can be avoided and we can reimplement @@ -1514,8 +1514,8 @@ mod tests { }; use crate::types::serialize::{CellWriter, SerializationError}; + use bigdecimal::num_bigint::BigInt; use bigdecimal::BigDecimal; - use num_bigint::BigInt; use scylla_macros::SerializeCql; use super::{SerializeCql, UdtSerializationErrorKind, UdtTypeCheckErrorKind}; diff --git a/scylla/Cargo.toml b/scylla/Cargo.toml index adbb51f04a..81d33bcac1 100644 --- a/scylla/Cargo.toml +++ b/scylla/Cargo.toml @@ -20,7 +20,8 @@ cloud = ["ssl", "scylla-cql/serde", "dep:serde_yaml", "dep:serde", "dep:url", "d secret = ["scylla-cql/secret"] chrono = ["scylla-cql/chrono"] time = ["scylla-cql/time"] -full-serialization = ["chrono", "time", "secret"] +num-bigint-03 = ["scylla-cql/num-bigint-03"] +full-serialization = ["chrono", "time", "secret", "num-bigint-03"] [dependencies] scylla-macros = { version = "0.3.0", path = "../scylla-macros" } @@ -37,7 +38,6 @@ rand = "0.8.3" thiserror = "1.0" itertools = "0.11.0" bigdecimal = "0.2.0" -num-bigint = "0.3" tracing = "0.1.36" chrono = { version = "0.4.20", default-features = false, features = ["clock"] } openssl = { version = "0.10.32", optional = true } @@ -57,6 +57,7 @@ rand_pcg = "0.3.1" socket2 = { version = "0.5.3", features = ["all"] } [dev-dependencies] +num-bigint-03 = { package = "num-bigint", version = "0.3" } scylla-proxy = { version = "0.0.3", path = "../scylla-proxy" } ntest = "0.9.0" criterion = "0.4" # Note: v0.5 needs at least rust 1.70.0 diff --git a/scylla/src/transport/cql_types_test.rs b/scylla/src/transport/cql_types_test.rs index d895974076..2c49926df9 100644 --- a/scylla/src/transport/cql_types_test.rs +++ b/scylla/src/transport/cql_types_test.rs @@ -9,7 +9,6 @@ use crate::transport::session::Session; use crate::utils::test_utils::unique_keyspace_name; use bigdecimal::BigDecimal; use itertools::Itertools; -use num_bigint::BigInt; use scylla_cql::frame::value::{CqlTimeuuid, CqlVarint}; use scylla_cql::types::serialize::value::SerializeCql; use scylla_macros::SerializeCql; @@ -104,6 +103,7 @@ where } } +#[cfg(feature = "num-bigint-03")] #[tokio::test] async fn test_varint() { let tests = [ @@ -119,7 +119,7 @@ async fn test_varint() { "-123456789012345678901234567890", ]; - run_tests::(&tests, "varint").await; + run_tests::(&tests, "varint").await; } #[tokio::test] From 5d4bb9dcab62b475e27f047e7e359e9a4c4cafe7 Mon Sep 17 00:00:00 2001 From: muzarski Date: Wed, 3 Jan 2024 11:57:11 +0100 Subject: [PATCH 09/14] cargo: add feature flag for num-bigint v0.4 --- examples/Cargo.toml | 2 +- scylla-cql/Cargo.toml | 4 +- scylla-cql/src/frame/response/cql_to_rust.rs | 24 +++++- scylla-cql/src/frame/response/result.rs | 91 ++++++++++++-------- scylla-cql/src/frame/value.rs | 27 ++++++ scylla-cql/src/frame/value_tests.rs | 41 +++++---- scylla-cql/src/types/serialize/value.rs | 10 +++ scylla/Cargo.toml | 4 +- scylla/src/transport/cql_types_test.rs | 21 +++-- 9 files changed, 163 insertions(+), 61 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index d6cf6e356d..66e1e2d47e 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -10,7 +10,7 @@ futures = "0.3.6" openssl = "0.10.32" rustyline = "9" rustyline-derive = "0.6" -scylla = {path = "../scylla", features = ["ssl", "cloud", "chrono", "time", "num-bigint-03"]} +scylla = {path = "../scylla", features = ["ssl", "cloud", "chrono", "time", "num-bigint-03", "num-bigint-04"]} tokio = {version = "1.1.0", features = ["full"]} tracing = "0.1.25" tracing-subscriber = { version = "0.3.14", features = ["env-filter"] } diff --git a/scylla-cql/Cargo.toml b/scylla-cql/Cargo.toml index a298888164..76adedcb91 100644 --- a/scylla-cql/Cargo.toml +++ b/scylla-cql/Cargo.toml @@ -21,6 +21,7 @@ uuid = "1.0" thiserror = "1.0" bigdecimal = "0.2.0" num-bigint-03 = { package = "num-bigint", version = "0.3", optional = true } +num-bigint-04 = { package = "num-bigint", version = "0.4", optional = true } chrono = { version = "0.4.27", default-features = false, optional = true } lz4_flex = { version = "0.11.1" } async-trait = "0.1.57" @@ -41,4 +42,5 @@ secret = ["secrecy"] time = ["dep:time"] chrono = ["dep:chrono"] num-bigint-03 = ["dep:num-bigint-03"] -full-serialization = ["chrono", "time", "secret", "num-bigint-03"] +num-bigint-04 = ["dep:num-bigint-04"] +full-serialization = ["chrono", "time", "secret", "num-bigint-03", "num-bigint-04"] diff --git a/scylla-cql/src/frame/response/cql_to_rust.rs b/scylla-cql/src/frame/response/cql_to_rust.rs index 2392be8e41..9030e8d9e9 100644 --- a/scylla-cql/src/frame/response/cql_to_rust.rs +++ b/scylla-cql/src/frame/response/cql_to_rust.rs @@ -159,6 +159,16 @@ impl FromCqlVal for num_bigint_03::BigInt { } } +#[cfg(feature = "num-bigint-04")] +impl FromCqlVal for num_bigint_04::BigInt { + fn from_cql(cql_val: CqlValue) -> Result { + match cql_val { + CqlValue::Varint(cql_varint) => Ok(cql_varint.into()), + _ => Err(FromCqlValError::BadCqlType), + } + } +} + #[cfg(feature = "chrono")] impl FromCqlVal for NaiveDate { fn from_cql(cql_val: CqlValue) -> Result { @@ -470,7 +480,7 @@ mod tests { #[cfg(feature = "num-bigint-03")] #[test] - fn varint_from_cql() { + fn varint03_from_cql() { use num_bigint_03::ToBigInt; let big_int = 0.to_bigint().unwrap(); @@ -480,6 +490,18 @@ mod tests { ); } + #[cfg(feature = "num-bigint-04")] + #[test] + fn varint04_from_cql() { + use num_bigint_04::ToBigInt; + + let big_int = 0.to_bigint().unwrap(); + assert_eq!( + Ok(big_int), + num_bigint_04::BigInt::from_cql(CqlValue::Varint(0.to_bigint().unwrap().into())) + ); + } + #[test] fn decimal_from_cql() { let decimal = BigDecimal::from_str("123.4").unwrap(); diff --git a/scylla-cql/src/frame/response/result.rs b/scylla-cql/src/frame/response/result.rs index 96efc0a0d9..ffcd35543b 100644 --- a/scylla-cql/src/frame/response/result.rs +++ b/scylla-cql/src/frame/response/result.rs @@ -1027,16 +1027,14 @@ mod tests { assert_eq!(double_serialize, CqlValue::Double(double)); } - #[cfg(feature = "num-bigint-03")] - #[test] - fn test_varint() { - use num_bigint_03::ToBigInt; - - struct Test<'a> { - value: num_bigint_03::BigInt, - encoding: &'a [u8], - } + #[cfg(any(feature = "num-bigint-03", feature = "num-bigint-04"))] + struct VarintTestCase { + value: i32, + encoding: Vec, + } + #[cfg(any(feature = "num-bigint-03", feature = "num-bigint-04"))] + fn varint_test_cases_from_spec() -> Vec { /* Table taken from CQL Binary Protocol v4 spec @@ -1051,44 +1049,65 @@ mod tests { -128 | 0x80 -129 | 0xFF7F */ - let tests = [ - Test { - value: 0.to_bigint().unwrap(), - encoding: &[0x00], + vec![ + VarintTestCase { + value: 0, + encoding: vec![0x00], }, - Test { - value: 1.to_bigint().unwrap(), - encoding: &[0x01], + VarintTestCase { + value: 1, + encoding: vec![0x01], }, - Test { - value: 127.to_bigint().unwrap(), - encoding: &[0x7F], + VarintTestCase { + value: 127, + encoding: vec![0x7F], }, - Test { - value: 128.to_bigint().unwrap(), - encoding: &[0x00, 0x80], + VarintTestCase { + value: 128, + encoding: vec![0x00, 0x80], }, - Test { - value: 129.to_bigint().unwrap(), - encoding: &[0x00, 0x81], + VarintTestCase { + value: 129, + encoding: vec![0x00, 0x81], }, - Test { - value: (-1).to_bigint().unwrap(), - encoding: &[0xFF], + VarintTestCase { + value: -1, + encoding: vec![0xFF], }, - Test { - value: (-128).to_bigint().unwrap(), - encoding: &[0x80], + VarintTestCase { + value: -128, + encoding: vec![0x80], }, - Test { - value: (-129).to_bigint().unwrap(), - encoding: &[0xFF, 0x7F], + VarintTestCase { + value: -129, + encoding: vec![0xFF, 0x7F], }, - ]; + ] + } + + #[cfg(feature = "num-bigint-03")] + #[test] + fn test_bigint03() { + use num_bigint_03::ToBigInt; + + let tests = varint_test_cases_from_spec(); + + for t in tests.iter() { + let value = super::deser_cql_value(&ColumnType::Varint, &mut &*t.encoding).unwrap(); + assert_eq!(CqlValue::Varint(t.value.to_bigint().unwrap().into()), value); + } + } + + #[cfg(feature = "num-bigint-04")] + #[test] + fn test_bigint04() { + use num_bigint_04::ToBigInt; + + let tests = varint_test_cases_from_spec(); for t in tests.iter() { let value = super::deser_cql_value(&ColumnType::Varint, &mut &*t.encoding).unwrap(); - assert_eq!(CqlValue::Varint(t.value.clone().into()), value); + assert_eq!(CqlValue::Varint(t.value.to_bigint().unwrap().into()), value); } } diff --git a/scylla-cql/src/frame/value.rs b/scylla-cql/src/frame/value.rs index 3626de87ae..cde521269e 100644 --- a/scylla-cql/src/frame/value.rs +++ b/scylla-cql/src/frame/value.rs @@ -319,6 +319,20 @@ impl From for num_bigint_03::BigInt { } } +#[cfg(feature = "num-bigint-04")] +impl From for CqlVarint { + fn from(value: num_bigint_04::BigInt) -> Self { + Self(value.to_signed_bytes_be()) + } +} + +#[cfg(feature = "num-bigint-04")] +impl From for num_bigint_04::BigInt { + fn from(val: CqlVarint) -> Self { + num_bigint_04::BigInt::from_signed_bytes_be(&val.0) + } +} + /// Compares two [`CqlVarint`] values after normalization. /// /// # Example @@ -1021,6 +1035,19 @@ impl Value for num_bigint_03::BigInt { } } +#[cfg(feature = "num-bigint-04")] +impl Value for num_bigint_04::BigInt { + fn serialize(&self, buf: &mut Vec) -> Result<(), ValueTooBig> { + let serialized = self.to_signed_bytes_be(); + let serialized_len: i32 = serialized.len().try_into().map_err(|_| ValueTooBig)?; + + buf.put_i32(serialized_len); + buf.extend_from_slice(&serialized); + + Ok(()) + } +} + impl Value for &str { fn serialize(&self, buf: &mut Vec) -> Result<(), ValueTooBig> { let str_bytes: &[u8] = self.as_bytes(); diff --git a/scylla-cql/src/frame/value_tests.rs b/scylla-cql/src/frame/value_tests.rs index 53f8a65bd4..978c7a6db0 100644 --- a/scylla-cql/src/frame/value_tests.rs +++ b/scylla-cql/src/frame/value_tests.rs @@ -147,10 +147,8 @@ fn cql_varint_serialization() { } } -#[cfg(feature = "num-bigint-03")] -#[test] -fn bigint03_serialization() { - let cases_from_the_spec: &[(i64, Vec)] = &[ +fn varint_test_cases_from_spec() -> Vec<(i64, Vec)> { + vec![ (0, vec![0x00]), (1, vec![0x01]), (127, vec![0x7F]), @@ -159,10 +157,18 @@ fn bigint03_serialization() { (-1, vec![0xFF]), (-128, vec![0x80]), (-129, vec![0xFF, 0x7F]), - ]; + ] +} + +#[cfg(any(feature = "num-bigint-03", feature = "num-bigint-04"))] +fn generic_num_bigint_serialization() +where + B: From + Value + SerializeCql, +{ + let cases_from_the_spec: &[(i64, Vec)] = &varint_test_cases_from_spec(); for (i, b) in cases_from_the_spec { - let x = num_bigint_03::BigInt::from(*i); + let x = B::from(*i); let b_with_len = (b.len() as i32) .to_be_bytes() .iter() @@ -173,19 +179,22 @@ fn bigint03_serialization() { } } +#[cfg(feature = "num-bigint-03")] +#[test] +fn bigint03_serialization() { + generic_num_bigint_serialization::() +} + +#[cfg(feature = "num-bigint-04")] +#[test] +fn bigint04_serialization() { + generic_num_bigint_serialization::() +} + #[test] fn bigdecimal_serialization() { // Bigint cases - let cases_from_the_spec: &[(i64, Vec)] = &[ - (0, vec![0x00]), - (1, vec![0x01]), - (127, vec![0x7F]), - (128, vec![0x00, 0x80]), - (129, vec![0x00, 0x81]), - (-1, vec![0xFF]), - (-128, vec![0x80]), - (-129, vec![0xFF, 0x7F]), - ]; + let cases_from_the_spec: &[(i64, Vec)] = &varint_test_cases_from_spec(); for exponent in -10_i32..10_i32 { for (digits, serialized_digits) in cases_from_the_spec { diff --git a/scylla-cql/src/types/serialize/value.rs b/scylla-cql/src/types/serialize/value.rs index aac38d48f3..a50dc23d21 100644 --- a/scylla-cql/src/types/serialize/value.rs +++ b/scylla-cql/src/types/serialize/value.rs @@ -253,6 +253,16 @@ impl SerializeCql for num_bigint_03::BigInt { .map_err(|_| mk_ser_err::(typ, BuiltinSerializationErrorKind::SizeOverflow))? }); } +#[cfg(feature = "num-bigint-04")] +impl SerializeCql for num_bigint_04::BigInt { + impl_serialize_via_writer!(|me, typ, writer| { + exact_type_check!(typ, Varint); + // TODO: See above comment for num-bigint-03. + writer + .set_value(me.to_signed_bytes_be().as_slice()) + .map_err(|_| mk_ser_err::(typ, BuiltinSerializationErrorKind::SizeOverflow))? + }); +} impl SerializeCql for &str { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Ascii, Text); diff --git a/scylla/Cargo.toml b/scylla/Cargo.toml index 81d33bcac1..2d59482296 100644 --- a/scylla/Cargo.toml +++ b/scylla/Cargo.toml @@ -21,7 +21,8 @@ secret = ["scylla-cql/secret"] chrono = ["scylla-cql/chrono"] time = ["scylla-cql/time"] num-bigint-03 = ["scylla-cql/num-bigint-03"] -full-serialization = ["chrono", "time", "secret", "num-bigint-03"] +num-bigint-04 = ["scylla-cql/num-bigint-04"] +full-serialization = ["chrono", "time", "secret", "num-bigint-03", "num-bigint-04"] [dependencies] scylla-macros = { version = "0.3.0", path = "../scylla-macros" } @@ -58,6 +59,7 @@ socket2 = { version = "0.5.3", features = ["all"] } [dev-dependencies] num-bigint-03 = { package = "num-bigint", version = "0.3" } +num-bigint-04 = { package = "num-bigint", version = "0.4" } scylla-proxy = { version = "0.0.3", path = "../scylla-proxy" } ntest = "0.9.0" criterion = "0.4" # Note: v0.5 needs at least rust 1.70.0 diff --git a/scylla/src/transport/cql_types_test.rs b/scylla/src/transport/cql_types_test.rs index 2c49926df9..e7052f0f1b 100644 --- a/scylla/src/transport/cql_types_test.rs +++ b/scylla/src/transport/cql_types_test.rs @@ -103,10 +103,9 @@ where } } -#[cfg(feature = "num-bigint-03")] -#[tokio::test] -async fn test_varint() { - let tests = [ +#[cfg(any(feature = "num-bigint-03", feature = "num-bigint-04"))] +fn varint_test_cases() -> Vec<&'static str> { + vec![ "0", "1", "127", @@ -117,11 +116,23 @@ async fn test_varint() { "-129", "123456789012345678901234567890", "-123456789012345678901234567890", - ]; + ] +} +#[cfg(feature = "num-bigint-03")] +#[tokio::test] +async fn test_varint03() { + let tests = varint_test_cases(); run_tests::(&tests, "varint").await; } +#[cfg(feature = "num-bigint-04")] +#[tokio::test] +async fn test_varint04() { + let tests = varint_test_cases(); + run_tests::(&tests, "varint").await; +} + #[tokio::test] async fn test_cql_varint() { let tests = [ From 9be7d9f18a9ce0d90f50ed6fe5b1ee673c9f6f43 Mon Sep 17 00:00:00 2001 From: muzarski Date: Fri, 26 Jan 2024 13:20:08 +0100 Subject: [PATCH 10/14] docstrings: add info about num_bigint features --- scylla-cql/src/frame/value.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scylla-cql/src/frame/value.rs b/scylla-cql/src/frame/value.rs index cde521269e..3630bfa630 100644 --- a/scylla-cql/src/frame/value.rs +++ b/scylla-cql/src/frame/value.rs @@ -222,6 +222,12 @@ impl std::hash::Hash for CqlTimeuuid { /// implementation of `varint` type - independent of any /// external crates and crate features. /// +/// The type is not very useful in most use cases. +/// However, users can make use of more complex types +/// such as `num_bigint::BigInt` (v0.3/v0.4). +/// The library support (e.g. conversion from [`CqlValue`]) for these types is +/// enabled via `num-bigint-03` and `num-bigint-04` crate features. +/// /// # DB data format /// Notice that [constructors](CqlVarint#impl-CqlVarint) /// don't perform any normalization on the provided data. From 81c5867b20956ee5696cd90ee64fa8aa588e2225 Mon Sep 17 00:00:00 2001 From: muzarski Date: Fri, 19 Jan 2024 05:00:27 +0100 Subject: [PATCH 11/14] types_test: test cases for big varints Added test cases for varints that can't be contained in any primitive. --- scylla/src/transport/cql_types_test.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scylla/src/transport/cql_types_test.rs b/scylla/src/transport/cql_types_test.rs index e7052f0f1b..aac8561d8c 100644 --- a/scylla/src/transport/cql_types_test.rs +++ b/scylla/src/transport/cql_types_test.rs @@ -116,6 +116,9 @@ fn varint_test_cases() -> Vec<&'static str> { "-129", "123456789012345678901234567890", "-123456789012345678901234567890", + // Test cases for numbers that can't be contained in u/i128. + "1234567890123456789012345678901234567890", + "-1234567890123456789012345678901234567890", ] } From 358814cbfae3e27e39cef020dccdd5d2c0505739 Mon Sep 17 00:00:00 2001 From: muzarski Date: Wed, 3 Jan 2024 12:26:19 +0100 Subject: [PATCH 12/14] docs: update info about varint native data type --- docs/source/data-types/data-types.md | 2 +- docs/source/data-types/varint.md | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/source/data-types/data-types.md b/docs/source/data-types/data-types.md index f9fae6cedf..e03c82233e 100644 --- a/docs/source/data-types/data-types.md +++ b/docs/source/data-types/data-types.md @@ -27,7 +27,7 @@ Database types and their Rust equivalents: * `Timestamp` <----> `value::CqlTimestamp`, `chrono::DateTime`, `time::OffsetDateTime` * `Duration` <----> `value::CqlDuration` * `Decimal` <----> `bigdecimal::Decimal` -* `Varint` <----> `num_bigint::BigInt` +* `Varint` <----> `value::CqlVarint`, `num_bigint::BigInt` (v0.3 and v0.4) * `List` <----> `Vec` * `Set` <----> `Vec` * `Map` <----> `std::collections::HashMap` diff --git a/docs/source/data-types/varint.md b/docs/source/data-types/varint.md index b90c9a5ccb..745520e66f 100644 --- a/docs/source/data-types/varint.md +++ b/docs/source/data-types/varint.md @@ -1,5 +1,16 @@ # Varint -`Varint` is represented as [`num_bigint::BigInt`](https://docs.rs/num-bigint/0.4.0/num_bigint/struct.BigInt.html) +`Varint` is represented as `value::CqlVarint` or [`num_bigint::BigInt`](https://docs.rs/num-bigint/0.4.0/num_bigint/struct.BigInt.html). + +## num_bigint::BigInt + +To make use of `num_bigint::BigInt` type, user should enable one of the available feature flags (`num-bigint-03` or `num-bigint-04`). They enable support for `num_bigint::BigInt` v0.3 and v0.4 accordingly. + +## value::CqlVarint + +Without any feature flags, the user can interact with `Varint` type by making use of `value::CqlVarint` which +is a very simple wrapper representing the value as signed binary number in big-endian order. + +## Example ```rust # extern crate scylla; From d30a9be1880b32ef4361b12702c0fdb11e105fb1 Mon Sep 17 00:00:00 2001 From: muzarski Date: Fri, 12 Jan 2024 11:34:22 +0100 Subject: [PATCH 13/14] cargo: update Cargo.lock.msrv file --- Cargo.lock.msrv | 299 +++++++++++++++++++++++++++--------------------- 1 file changed, 168 insertions(+), 131 deletions(-) diff --git a/Cargo.lock.msrv b/Cargo.lock.msrv index b013de3de5..84b515fccc 100644 --- a/Cargo.lock.msrv +++ b/Cargo.lock.msrv @@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aho-corasick" -version = "1.1.2" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" dependencies = [ "memchr", ] @@ -67,13 +67,13 @@ checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" [[package]] name = "async-trait" -version = "0.1.74" +version = "0.1.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" +checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.32", ] [[package]] @@ -110,9 +110,9 @@ dependencies = [ [[package]] name = "base64" -version = "0.21.5" +version = "0.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" [[package]] name = "bigdecimal" @@ -120,7 +120,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d1e50562e37200edf7c6c43e54a08e64a5553bfb59d9c297d5572512aa517256" dependencies = [ - "num-bigint", + "num-bigint 0.3.3", "num-integer", "num-traits", ] @@ -133,21 +133,21 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" [[package]] name = "bumpalo" -version = "3.14.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" [[package]] name = "byteorder" -version = "1.5.0" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" @@ -178,9 +178,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.31" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +checksum = "defd4e7873dbddba6c7c91e199c7fcb946abc4a6a4ac3195400bcfb01b5de877" dependencies = [ "android-tzdata", "iana-time-zone", @@ -307,6 +307,16 @@ dependencies = [ "itertools 0.10.5", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + [[package]] name = "crossbeam-deque" version = "0.8.3" @@ -361,7 +371,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.38", + "syn 2.0.32", ] [[package]] @@ -372,7 +382,7 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core", "quote", - "syn 2.0.38", + "syn 2.0.32", ] [[package]] @@ -382,7 +392,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if", - "hashbrown 0.14.2", + "hashbrown 0.14.0", "lock_api", "once_cell", "parking_lot_core", @@ -429,14 +439,25 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.5" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" +checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" dependencies = [ + "errno-dragonfly", "libc", "windows-sys", ] +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "error-code" version = "2.3.1" @@ -565,7 +586,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.32", ] [[package]] @@ -629,9 +650,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.14.2" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" +checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" [[package]] name = "heck" @@ -659,9 +680,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.3" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" [[package]] name = "histogram" @@ -671,16 +692,16 @@ checksum = "12cb882ccb290b8646e554b157ab0b71e64e8d5bef775cd66b6531e52d302669" [[package]] name = "iana-time-zone" -version = "0.1.58" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows", ] [[package]] @@ -720,12 +741,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" +checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" dependencies = [ "equivalent", - "hashbrown 0.14.2", + "hashbrown 0.14.0", ] [[package]] @@ -769,21 +790,21 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.149" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "linux-raw-sys" -version = "0.4.10" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" +checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" dependencies = [ "autocfg", "scopeguard", @@ -815,9 +836,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.6.4" +version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" [[package]] name = "memoffset" @@ -848,9 +869,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.9" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" +checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", "wasi", @@ -933,6 +954,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-bigint" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -945,9 +977,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" dependencies = [ "autocfg", ] @@ -958,7 +990,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.3", + "hermit-abi 0.3.2", "libc", ] @@ -1001,7 +1033,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.32", ] [[package]] @@ -1031,7 +1063,7 @@ version = "0.10.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.4.0", "cfg-if", "foreign-types", "libc", @@ -1048,7 +1080,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.32", ] [[package]] @@ -1065,9 +1097,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.6.1" +version = "6.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" +checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" [[package]] name = "overload" @@ -1087,13 +1119,13 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.4.1", + "redox_syscall 0.3.5", "smallvec", "windows-targets", ] @@ -1192,9 +1224,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] @@ -1259,9 +1291,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.8.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" +checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" dependencies = [ "either", "rayon-core", @@ -1269,12 +1301,14 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.12.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" +checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" dependencies = [ + "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", + "num_cpus", ] [[package]] @@ -1288,9 +1322,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ "bitflags 1.3.2", ] @@ -1308,14 +1342,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.2" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.3", - "regex-syntax 0.8.2", + "regex-automata 0.3.8", + "regex-syntax 0.7.5", ] [[package]] @@ -1329,13 +1363,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.3" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.2", + "regex-syntax 0.7.5", ] [[package]] @@ -1346,9 +1380,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "rustc-demangle" @@ -1358,11 +1392,11 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.38.20" +version = "0.38.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67ce50cb2e16c2903e30d1cbccfd8387a74b9d4c938b6a4c5ec6cc7556f7a8a0" +checksum = "d7db8590df6dfcd144d22afd1b83b36c21a18d7cbc1dc4bb5295a8712e9eb662" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.4.0", "errno", "libc", "linux-raw-sys", @@ -1449,7 +1483,8 @@ dependencies = [ "itertools 0.11.0", "lz4_flex", "ntest", - "num-bigint", + "num-bigint 0.3.3", + "num-bigint 0.4.4", "num_enum 0.6.1", "openssl", "rand", @@ -1486,7 +1521,8 @@ dependencies = [ "chrono", "criterion", "lz4_flex", - "num-bigint", + "num-bigint 0.3.3", + "num-bigint 0.4.4", "num_enum 0.6.1", "scylla-macros", "secrecy", @@ -1505,7 +1541,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.32", ] [[package]] @@ -1519,7 +1555,7 @@ dependencies = [ "chrono", "futures", "ntest", - "num-bigint", + "num-bigint 0.3.3", "num_enum 0.5.11", "rand", "scylla-cql", @@ -1541,29 +1577,29 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.190" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.190" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.32", ] [[package]] name = "serde_json" -version = "1.0.107" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" +checksum = "2cc66a619ed80bf7a0f6b17dd063a84b88f6dea1813737cf469aef1d081142c2" dependencies = [ "itoa", "ryu", @@ -1572,11 +1608,11 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.9.27" +version = "0.9.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cc7a1570e38322cfe4154732e5110f887ea57e22b76f4bfd32b5bdd3368666c" +checksum = "1a49e178e4452f45cb61d0cd8cebc1b0fafd3e41929e996cef79aa3aca91f574" dependencies = [ - "indexmap 2.0.2", + "indexmap 2.0.0", "itoa", "ryu", "serde", @@ -1585,9 +1621,9 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.7" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" dependencies = [ "lazy_static", ] @@ -1612,9 +1648,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.1" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "snap" @@ -1624,9 +1660,9 @@ checksum = "5e9f0ab6ef7eb7353d9119c170a436d1bf248eea575ac42d19d12f4e34130831" [[package]] name = "socket2" -version = "0.5.5" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" dependencies = [ "libc", "windows-sys", @@ -1688,9 +1724,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.38" +version = "2.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +checksum = "239814284fd6f1a4ffe4ca893952cdd93c224b6a1571c9a9eadd670295c0c9e2" dependencies = [ "proc-macro2", "quote", @@ -1699,9 +1735,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.3.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" dependencies = [ "winapi-util", ] @@ -1714,22 +1750,22 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.32", ] [[package]] @@ -1795,9 +1831,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.33.0" +version = "1.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653" +checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" dependencies = [ "backtrace", "bytes", @@ -1820,7 +1856,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.32", ] [[package]] @@ -1847,7 +1883,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.0.2", + "indexmap 2.0.0", "toml_datetime", "winnow", ] @@ -1877,10 +1913,11 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.40" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ + "cfg-if", "log", "pin-project-lite", "tracing-attributes", @@ -1889,20 +1926,20 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.27" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.32", ] [[package]] name = "tracing-core" -version = "0.1.32" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" dependencies = [ "once_cell", "valuable", @@ -1910,12 +1947,12 @@ dependencies = [ [[package]] name = "tracing-log" -version = "0.1.4" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f751112709b4e791d8ce53e32c4ed2d353565a795ce84da2285393f41557bdf2" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" dependencies = [ + "lazy_static", "log", - "once_cell", "tracing-core", ] @@ -1955,9 +1992,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" [[package]] name = "unicode-normalization" @@ -1976,9 +2013,9 @@ checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" -version = "0.1.11" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "unsafe-libyaml" @@ -2005,9 +2042,9 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "uuid" -version = "1.5.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc" +checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" dependencies = [ "getrandom", ] @@ -2067,7 +2104,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.32", "wasm-bindgen-shared", ] @@ -2089,7 +2126,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.32", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2128,9 +2165,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.6" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ "winapi", ] @@ -2142,10 +2179,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "windows-core" -version = "0.51.1" +name = "windows" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" dependencies = [ "windows-targets", ] @@ -2218,9 +2255,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winnow" -version = "0.5.17" +version = "0.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c" +checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" dependencies = [ "memchr", ] From 21988ebc3b64f14d4ee43f12a6b23c4fc3a85bba Mon Sep 17 00:00:00 2001 From: muzarski Date: Fri, 26 Jan 2024 12:46:36 +0100 Subject: [PATCH 14/14] CI: add cargo checks with num_bigint features --- .github/workflows/rust.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 845ac87a2e..9415c63b0f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -40,6 +40,10 @@ jobs: run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "chrono" - name: Cargo check with time feature run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "time" + - name: Cargo check with num-bigint-03 feature + run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "num-bigint-03" + - name: Cargo check with num-bigint-04 feature + run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "num-bigint-04" - name: Build scylla-cql run: cargo build --verbose --all-targets --manifest-path "scylla-cql/Cargo.toml" --features "full-serialization" - name: Build