Skip to content

Commit

Permalink
Merge pull request #1166 from Lorak-mmk/new_column_type
Browse files Browse the repository at this point in the history
Remove CqlType in favor of ColumnType
  • Loading branch information
Lorak-mmk authored Jan 29, 2025
2 parents b6a3e01 + cfeb8b9 commit 9441b05
Show file tree
Hide file tree
Showing 27 changed files with 2,368 additions and 1,436 deletions.
10 changes: 5 additions & 5 deletions scylla-cql/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};

use scylla_cql::frame::request::query::PagingState;
use scylla_cql::frame::request::SerializableRequest;
use scylla_cql::frame::response::result::ColumnType;
use scylla_cql::frame::response::result::{ColumnType, NativeType};
use scylla_cql::frame::{request::query, Compression, SerializedRequest};
use scylla_cql::serialize::row::SerializedValues;

Expand All @@ -28,18 +28,18 @@ fn serialized_request_make_bench(c: &mut Criterion) {
let mut group = c.benchmark_group("LZ4Compression.SerializedRequest");
let query_args = [
("INSERT foo INTO ks.table_name (?)", {
values.add_value(&1234, &ColumnType::Int).unwrap();
values.add_value(&1234, &ColumnType::Native(NativeType::Int)).unwrap();
values.clone()
}),
("INSERT foo, bar, baz INTO ks.table_name (?, ?, ?)", {
values.add_value(&"a value", &ColumnType::Text).unwrap();
values.add_value(&"i am storing a string", &ColumnType::Text).unwrap();
values.add_value(&"a value", &ColumnType::Native(NativeType::Text)).unwrap();
values.add_value(&"i am storing a string", &ColumnType::Native(NativeType::Text)).unwrap();
values.clone()
}),
(
"INSERT foo, bar, baz, boop, blah INTO longer_keyspace.a_big_table_name (?, ?, ?, ?, 1000)",
{
values.add_value(&"dc0c8cd7-d954-47c1-8722-a857941c43fb", &ColumnType::Text).unwrap();
values.add_value(&"dc0c8cd7-d954-47c1-8722-a857941c43fb", &ColumnType::Native(NativeType::Text)).unwrap();
values.clone()
}
),
Expand Down
12 changes: 6 additions & 6 deletions scylla-cql/src/deserialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
//! the respective trait for _all_ lifetimes, i.e.:
//!
//! ```rust
//! # use scylla_cql::frame::response::result::ColumnType;
//! # use scylla_cql::frame::response::result::{NativeType, ColumnType};
//! # use scylla_cql::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
//! # use scylla_cql::deserialize::value::DeserializeValue;
//! use thiserror::Error;
Expand All @@ -101,7 +101,7 @@
//! }
//! impl<'frame, 'metadata> DeserializeValue<'frame, 'metadata> for MyVec {
//! fn type_check(typ: &ColumnType) -> Result<(), TypeCheckError> {
//! if let ColumnType::Blob = typ {
//! if let ColumnType::Native(NativeType::Blob) = typ {
//! return Ok(());
//! }
//! Err(TypeCheckError::new(MyDeserError::ExpectedBytes))
Expand All @@ -128,7 +128,7 @@
//! For example:
//!
//! ```rust
//! # use scylla_cql::frame::response::result::ColumnType;
//! # use scylla_cql::frame::response::result::{NativeType, ColumnType};
//! # use scylla_cql::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
//! # use scylla_cql::deserialize::value::DeserializeValue;
//! use thiserror::Error;
Expand All @@ -145,7 +145,7 @@
//! 'frame: 'a,
//! {
//! fn type_check(typ: &ColumnType) -> Result<(), TypeCheckError> {
//! if let ColumnType::Blob = typ {
//! if let ColumnType::Native(NativeType::Blob) = typ {
//! return Ok(());
//! }
//! Err(TypeCheckError::new(MyDeserError::ExpectedBytes))
Expand Down Expand Up @@ -179,7 +179,7 @@
//! Example:
//!
//! ```rust
//! # use scylla_cql::frame::response::result::ColumnType;
//! # use scylla_cql::frame::response::result::{NativeType, ColumnType};
//! # use scylla_cql::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
//! # use scylla_cql::deserialize::value::DeserializeValue;
//! # use bytes::Bytes;
Expand All @@ -194,7 +194,7 @@
//! }
//! impl<'frame, 'metadata> DeserializeValue<'frame, 'metadata> for MyBytes {
//! fn type_check(typ: &ColumnType) -> Result<(), TypeCheckError> {
//! if let ColumnType::Blob = typ {
//! if let ColumnType::Native(NativeType::Blob) = typ {
//! return Ok(());
//! }
//! Err(TypeCheckError::new(MyDeserError::ExpectedBytes))
Expand Down
24 changes: 17 additions & 7 deletions scylla-cql/src/deserialize/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ mod tests {
use std::ops::Deref;

use crate::frame::response::result::{
ColumnSpec, ColumnType, DeserializedMetadataAndRawRows, ResultMetadata,
ColumnSpec, ColumnType, DeserializedMetadataAndRawRows, NativeType, ResultMetadata,
};

use super::super::tests::{serialize_cells, spec, CELL1, CELL2};
Expand Down Expand Up @@ -291,8 +291,10 @@ mod tests {
// `std::sync::LazyLock` is stable since 1.80, so once we bump MSRV enough,
// we will be able to replace `lazy_static` with `LazyLock`.

static SPECS: &[ColumnSpec<'static>] =
&[spec("b1", ColumnType::Blob), spec("b2", ColumnType::Blob)];
static SPECS: &[ColumnSpec<'static>] = &[
spec("b1", ColumnType::Native(NativeType::Blob)),
spec("b2", ColumnType::Native(NativeType::Blob)),
];
lazy_static::lazy_static! {
static ref RAW_DATA: Bytes = serialize_cells([Some(CELL1), Some(CELL2), Some(CELL2), Some(CELL1)]);
}
Expand Down Expand Up @@ -333,8 +335,10 @@ mod tests {

#[test]
fn test_row_iterators_too_few_rows() {
static SPECS: &[ColumnSpec<'static>] =
&[spec("b1", ColumnType::Blob), spec("b2", ColumnType::Blob)];
static SPECS: &[ColumnSpec<'static>] = &[
spec("b1", ColumnType::Native(NativeType::Blob)),
spec("b2", ColumnType::Native(NativeType::Blob)),
];
lazy_static::lazy_static! {
static ref RAW_DATA: Bytes = serialize_cells([Some(CELL1), Some(CELL2)]);
}
Expand Down Expand Up @@ -363,7 +367,10 @@ mod tests {
#[test]
fn test_typed_row_iterator_basic_parse() {
let raw_data = serialize_cells([Some(CELL1), Some(CELL2), Some(CELL2), Some(CELL1)]);
let specs = [spec("b1", ColumnType::Blob), spec("b2", ColumnType::Blob)];
let specs = [
spec("b1", ColumnType::Native(NativeType::Blob)),
spec("b2", ColumnType::Native(NativeType::Blob)),
];
let iter = RawRowIterator::new(2, &specs, FrameSlice::new(&raw_data));
let mut iter = TypedRowIterator::<'_, '_, (&[u8], Vec<u8>)>::new(iter).unwrap();

Expand All @@ -381,7 +388,10 @@ mod tests {
#[test]
fn test_typed_row_iterator_wrong_type() {
let raw_data = Bytes::new();
let specs = [spec("b1", ColumnType::Blob), spec("b2", ColumnType::Blob)];
let specs = [
spec("b1", ColumnType::Native(NativeType::Blob)),
spec("b2", ColumnType::Native(NativeType::Blob)),
];
let iter = RawRowIterator::new(0, &specs, FrameSlice::new(&raw_data));
assert!(TypedRowIterator::<'_, '_, (i32, i64)>::new(iter).is_err());
}
Expand Down
Loading

0 comments on commit 9441b05

Please sign in to comment.