diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 07c2f7c..e97462b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: include: - - { rust: stable, os: ubuntu-22.04 } + - { rust: stable, os: ubuntu-24.04 } services: clickhouse: image: clickhouse/clickhouse-server:25.8.4 @@ -28,7 +28,7 @@ jobs: --ulimit nofile=262144:262144 steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 - uses: dtolnay/rust-toolchain@stable with: toolchain: ${{ matrix.rust }} @@ -49,7 +49,7 @@ jobs: fail-fast: false matrix: include: - - { rust: 1.75.0, os: ubuntu-22.04 } + - { rust: 1.85.0, os: ubuntu-24.04 } services: clickhouse: image: clickhouse/clickhouse-server:25.8.4 @@ -61,7 +61,7 @@ jobs: --ulimit nofile=262144:262144 steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: submodules: true - uses: dtolnay/rust-toolchain@stable @@ -84,10 +84,10 @@ jobs: fail-fast: false matrix: include: - - { rust: nightly-2024-03-31, os: ubuntu-22.04 } + - { rust: nightly-2026-03-10, os: ubuntu-24.04 } steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: submodules: true - uses: dtolnay/rust-toolchain@stable @@ -108,10 +108,10 @@ jobs: fail-fast: false matrix: include: - - { rust: stable, os: ubuntu-22.04 } + - { rust: stable, os: ubuntu-24.04 } steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: submodules: true - uses: dtolnay/rust-toolchain@stable @@ -129,10 +129,10 @@ jobs: # fail-fast: false # matrix: # include: - # - { rust: stable, os: ubuntu-22.04 } + # - { rust: stable, os: ubuntu-24.04 } # steps: # - name: Checkout - # uses: actions/checkout@v4 + # uses: actions/checkout@v6 # with: # submodules: true # - uses: dtolnay/rust-toolchain@stable diff --git a/klickhouse/Cargo.toml b/klickhouse/Cargo.toml index c864003..da67136 100644 --- a/klickhouse/Cargo.toml +++ b/klickhouse/Cargo.toml @@ -2,14 +2,14 @@ name = "klickhouse" version = "0.14.0" authors = ["Protryon "] -edition = "2021" +edition = "2024" license = "MIT OR Apache-2.0" repository = "https://github.com/Protryon/klickhouse" description = "Klickhouse is a pure Rust SDK for working with Clickhouse with the native protocol in async environments with minimal boilerplate and maximal performance." keywords = ["clickhouse", "database", "tokio", "sql"] readme = "../README.md" autotests = false -rust-version = "1.75.0" +rust-version = "1.85.0" [package.metadata.docs.rs] all-features = true diff --git a/klickhouse/build.rs b/klickhouse/build.rs index 6658602..3dda88b 100644 --- a/klickhouse/build.rs +++ b/klickhouse/build.rs @@ -1,4 +1,4 @@ -use rustc_version::{version, Version}; +use rustc_version::{Version, version}; fn main() { if version().unwrap() >= Version::parse("1.51.0").unwrap() { diff --git a/klickhouse/examples/basic.rs b/klickhouse/examples/basic.rs index 43e29b3..b2b18d1 100644 --- a/klickhouse/examples/basic.rs +++ b/klickhouse/examples/basic.rs @@ -1,6 +1,7 @@ use chrono::Utc; use futures_util::StreamExt; use klickhouse::*; +use tokio::sync::oneshot; #[derive(Row, Debug, Default)] pub struct MyUserData { @@ -18,25 +19,38 @@ async fn main() { .await .unwrap(); + let (tx, mut rx) = oneshot::channel::<()>(); + // Retrieve and display query progress events let mut progress = client.subscribe_progress(); let progress_task = tokio::task::spawn(async move { let mut current_query = Uuid::nil(); let mut progress_total = Progress::default(); - while let Ok((query, progress)) = progress.recv().await { - if query != current_query { - progress_total = Progress::default(); - current_query = query; + + loop { + tokio::select! { + // Stop task + _ = &mut rx => { + break + } + + // Progress loop + Ok((query, progress)) = progress.recv() => { + if query != current_query { + progress_total = Progress::default(); + current_query = query; + } + progress_total += progress; + println!( + "Progress on query {}: {}/{} {:.2}%", + query, + progress_total.read_rows, + progress_total.new_total_rows_to_read, + 100.0 * progress_total.read_rows as f64 + / progress_total.new_total_rows_to_read as f64 + ); + } } - progress_total += progress; - println!( - "Progress on query {}: {}/{} {:.2}%", - query, - progress_total.read_rows, - progress_total.new_total_rows_to_read, - 100.0 * progress_total.read_rows as f64 - / progress_total.new_total_rows_to_read as f64 - ); } }); @@ -81,7 +95,7 @@ async fn main() { println!("row received '{}': {:?}", row.id, row); } - // Drop the client so that the progress task finishes. - drop(client); + // Send signal so that the progress task finishes. + tx.send(()).unwrap(); progress_task.await.unwrap(); } diff --git a/klickhouse/examples/pool.rs b/klickhouse/examples/pool.rs index f60a9e7..6973f72 100644 --- a/klickhouse/examples/pool.rs +++ b/klickhouse/examples/pool.rs @@ -1,6 +1,7 @@ use chrono::Utc; use futures_util::StreamExt; use klickhouse::*; +use tokio::sync::oneshot; #[derive(Row, Debug, Default)] pub struct MyUserData { @@ -26,25 +27,38 @@ async fn main() { let client = pool.get().await.unwrap(); + let (tx, mut rx) = oneshot::channel::<()>(); + // Retrieve and display query progress events let mut progress = client.subscribe_progress(); let progress_task = tokio::task::spawn(async move { let mut current_query = Uuid::nil(); let mut progress_total = Progress::default(); - while let Ok((query, progress)) = progress.recv().await { - if query != current_query { - progress_total = Progress::default(); - current_query = query; + + loop { + tokio::select! { + // Stop task + _ = &mut rx => { + break + } + + // Progress loop + Ok((query, progress)) = progress.recv() => { + if query != current_query { + progress_total = Progress::default(); + current_query = query; + } + progress_total += progress; + println!( + "Progress on query {}: {}/{} {:.2}%", + query, + progress_total.read_rows, + progress_total.new_total_rows_to_read, + 100.0 * progress_total.read_rows as f64 + / progress_total.new_total_rows_to_read as f64 + ); + } } - progress_total += progress; - println!( - "Progress on query {}: {}/{} {:.2}%", - query, - progress_total.read_rows, - progress_total.new_total_rows_to_read, - 100.0 * progress_total.read_rows as f64 - / progress_total.new_total_rows_to_read as f64 - ); } }); @@ -89,7 +103,7 @@ async fn main() { println!("row received '{}': {:?}", row.id, row); } - // Drop the client so that the progress task finishes. - drop(client); + // Send signal so that the progress task finishes. + tx.send(()).unwrap(); progress_task.await.unwrap(); } diff --git a/klickhouse/rustfmt.toml b/klickhouse/rustfmt.toml index 3a26366..f216078 100644 --- a/klickhouse/rustfmt.toml +++ b/klickhouse/rustfmt.toml @@ -1 +1 @@ -edition = "2021" +edition = "2024" diff --git a/klickhouse/src/block.rs b/klickhouse/src/block.rs index 688c6f3..cca8226 100644 --- a/klickhouse/src/block.rs +++ b/klickhouse/src/block.rs @@ -5,10 +5,10 @@ use indexmap::IndexMap; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use crate::{ + KlickhouseError, io::{ClickhouseRead, ClickhouseWrite}, types::{DeserializerState, SerializerState, Type}, values::Value, - KlickhouseError, }; /// Metadata about a block diff --git a/klickhouse/src/client.rs b/klickhouse/src/client.rs index c1d9bcf..638c5e5 100644 --- a/klickhouse/src/client.rs +++ b/klickhouse/src/client.rs @@ -1,6 +1,6 @@ use std::collections::VecDeque; -use futures_util::{stream, Stream, StreamExt}; +use futures_util::{Stream, StreamExt, stream}; use indexmap::IndexMap; use protocol::CompressionMethod; use tokio::{ @@ -17,6 +17,7 @@ use tokio_stream::wrappers::ReceiverStream; use uuid::Uuid; use crate::{ + KlickhouseError, ParsedQuery, RawRow, Result, block::{Block, BlockInfo}, convert::Row, internal_client_in::InternalClientIn, @@ -26,7 +27,6 @@ use crate::{ io::{ClickhouseRead, ClickhouseWrite}, progress::Progress, protocol::{self, ServerPacket}, - KlickhouseError, ParsedQuery, RawRow, Result, }; use log::*; @@ -130,7 +130,7 @@ impl InnerClient { ServerPacket::Hello(_) => { return Err(KlickhouseError::ProtocolError( "unexpected retransmission of server hello".to_string(), - )) + )); } ServerPacket::Data(block) => { if let Some((_, current)) = self.executing_query.as_ref() { diff --git a/klickhouse/src/convert/json.rs b/klickhouse/src/convert/json.rs index 46748a7..b279ff5 100644 --- a/klickhouse/src/convert/json.rs +++ b/klickhouse/src/convert/json.rs @@ -1,4 +1,4 @@ -use serde::{de::DeserializeOwned, Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de::DeserializeOwned}; use crate::{FromSql, KlickhouseError, Result, ToSql, Type, Value}; diff --git a/klickhouse/src/convert/mod.rs b/klickhouse/src/convert/mod.rs index 4079be2..6c5dc0a 100644 --- a/klickhouse/src/convert/mod.rs +++ b/klickhouse/src/convert/mod.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; -use crate::{types::Type, KlickhouseError, Result, Value}; +use crate::{KlickhouseError, Result, Value, types::Type}; mod raw_row; mod std_deserialize; diff --git a/klickhouse/src/convert/raw_row.rs b/klickhouse/src/convert/raw_row.rs index dde93fd..7aab115 100644 --- a/klickhouse/src/convert/raw_row.rs +++ b/klickhouse/src/convert/raw_row.rs @@ -42,11 +42,7 @@ pub trait RowIndex { impl RowIndex for usize { fn get<'a, I: IntoIterator>(&self, columns: I) -> Option { let count = columns.into_iter().count(); - if count >= *self { - Some(*self) - } else { - None - } + if count >= *self { Some(*self) } else { None } } } diff --git a/klickhouse/src/convert/std_deserialize.rs b/klickhouse/src/convert/std_deserialize.rs index c0f8858..3da173e 100644 --- a/klickhouse/src/convert/std_deserialize.rs +++ b/klickhouse/src/convert/std_deserialize.rs @@ -328,7 +328,7 @@ impl FromSql for Box { } macro_rules! tuple_impls { - ($($len:expr => ($($n:tt $name:ident)+))+) => { + ($($len:literal => ($($n:tt $name:ident)+))+) => { $( impl<$($name: FromSql),+> FromSql for ($($name,)+) { fn from_sql(type_: &Type, value: Value) -> Result { diff --git a/klickhouse/src/convert/std_serialize.rs b/klickhouse/src/convert/std_serialize.rs index e481871..ac435e6 100644 --- a/klickhouse/src/convert/std_serialize.rs +++ b/klickhouse/src/convert/std_serialize.rs @@ -209,7 +209,7 @@ impl ToSql for Box { } macro_rules! tuple_impls { - ($($len:expr => ($($n:tt $name:ident)+))+) => { + ($($len:literal => ($($n:tt $name:ident)+))+) => { $( impl<$($name: ToSql),+> ToSql for ($($name,)+) { fn to_sql(self, type_hint: Option<&Type>) -> Result { diff --git a/klickhouse/src/internal_client_in.rs b/klickhouse/src/internal_client_in.rs index 06e93d4..73fb833 100644 --- a/klickhouse/src/internal_client_in.rs +++ b/klickhouse/src/internal_client_in.rs @@ -1,16 +1,15 @@ use crate::Result; use crate::{ + KlickhouseError, block::Block, io::ClickhouseRead, progress::Progress, protocol::{ - self, BlockStreamProfileInfo, CompressionMethod, ServerData, ServerException, ServerHello, - ServerPacket, TableColumns, TableStatus, TablesStatusResponse, - DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO, DBMS_MIN_REVISION_WITH_SERVER_DISPLAY_NAME, - DBMS_MIN_REVISION_WITH_SERVER_TIMEZONE, DBMS_MIN_REVISION_WITH_VERSION_PATCH, - MAX_STRING_SIZE, + self, BlockStreamProfileInfo, CompressionMethod, DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO, + DBMS_MIN_REVISION_WITH_SERVER_DISPLAY_NAME, DBMS_MIN_REVISION_WITH_SERVER_TIMEZONE, + DBMS_MIN_REVISION_WITH_VERSION_PATCH, MAX_STRING_SIZE, ServerData, ServerException, + ServerHello, ServerPacket, TableColumns, TableStatus, TablesStatusResponse, }, - KlickhouseError, }; use indexmap::IndexMap; use log::trace; @@ -62,7 +61,9 @@ impl InternalClientIn { #[cfg(not(feature = "compression"))] async fn decompress_data(&mut self, _compression: CompressionMethod) -> Result { - panic!("attempted to use compression when not compiled with `compression` feature in klickhouse"); + panic!( + "attempted to use compression when not compiled with `compression` feature in klickhouse" + ); } async fn receive_data(&mut self, compression: CompressionMethod) -> Result { diff --git a/klickhouse/src/internal_client_out.rs b/klickhouse/src/internal_client_out.rs index e392c7b..e1183d0 100644 --- a/klickhouse/src/internal_client_out.rs +++ b/klickhouse/src/internal_client_out.rs @@ -1,13 +1,13 @@ use crate::{ + Result, block::Block, io::ClickhouseWrite, protocol::{ - self, CompressionMethod, ServerHello, DBMS_MIN_PROTOCOL_VERSION_WITH_DISTRIBUTED_DEPTH, + self, CompressionMethod, DBMS_MIN_PROTOCOL_VERSION_WITH_DISTRIBUTED_DEPTH, DBMS_MIN_REVISION_WITH_CLIENT_INFO, DBMS_MIN_REVISION_WITH_INTERSERVER_SECRET, DBMS_MIN_REVISION_WITH_OPENTELEMETRY, DBMS_MIN_REVISION_WITH_QUOTA_KEY_IN_CLIENT_INFO, - DBMS_MIN_REVISION_WITH_VERSION_PATCH, + DBMS_MIN_REVISION_WITH_VERSION_PATCH, ServerHello, }, - Result, }; use tokio::io::AsyncWriteExt; use uuid::Uuid; @@ -185,7 +185,9 @@ impl InternalClientOut { #[cfg(not(feature = "compression"))] async fn compress_data(&mut self, _byte: u8, _block: &Block) -> Result<()> { - panic!("attempted to use compression when not compiled with `compression` feature in klickhouse"); + panic!( + "attempted to use compression when not compiled with `compression` feature in klickhouse" + ); } pub async fn send_data( diff --git a/klickhouse/src/manager.rs b/klickhouse/src/manager.rs index 5c81f22..dd189ce 100644 --- a/klickhouse/src/manager.rs +++ b/klickhouse/src/manager.rs @@ -1,7 +1,7 @@ use std::net::SocketAddr; use tokio::net::ToSocketAddrs; -use crate::{convert::UnitValue, Client, ClientOptions, KlickhouseError}; +use crate::{Client, ClientOptions, KlickhouseError, convert::UnitValue}; #[derive(Clone)] pub struct ConnectionManager { diff --git a/klickhouse/src/migrate.rs b/klickhouse/src/migrate.rs index da58277..c347095 100644 --- a/klickhouse/src/migrate.rs +++ b/klickhouse/src/migrate.rs @@ -1,11 +1,11 @@ -use crate::{query_parser, ClickhouseLock, FromSql}; -use refinery_core::traits::r#async::{AsyncMigrate, AsyncQuery, AsyncTransaction}; +use crate::{ClickhouseLock, FromSql, query_parser}; use refinery_core::Migration; +use refinery_core::traits::r#async::{AsyncMigrate, AsyncQuery, AsyncTransaction}; use std::borrow::Cow; use std::marker::PhantomData; use std::time::{Duration, Instant}; -use time::format_description::well_known::Rfc3339; use time::OffsetDateTime; +use time::format_description::well_known::Rfc3339; use crate::{Client, KlickhouseError, Result, Row, Type, Value}; diff --git a/klickhouse/src/protocol.rs b/klickhouse/src/protocol.rs index f1bfeb6..429008e 100644 --- a/klickhouse/src/protocol.rs +++ b/klickhouse/src/protocol.rs @@ -1,7 +1,7 @@ use indexmap::IndexMap; use uuid::Uuid; -use crate::{block::Block, progress::Progress, KlickhouseError, Result}; +use crate::{KlickhouseError, Result, block::Block, progress::Progress}; pub const DBMS_MIN_REVISION_WITH_CLIENT_INFO: u64 = 54032; pub const DBMS_MIN_REVISION_WITH_SERVER_TIMEZONE: u64 = 54058; @@ -82,7 +82,7 @@ impl ServerPacketId { x => { return Err(KlickhouseError::ProtocolError(format!( "invalid packet id from server: {x}" - ))) + ))); } }) } diff --git a/klickhouse/src/query_parser.rs b/klickhouse/src/query_parser.rs index 74e1a3a..007c6e3 100644 --- a/klickhouse/src/query_parser.rs +++ b/klickhouse/src/query_parser.rs @@ -1,6 +1,6 @@ use crate::Value; -use compiler_tools::util::parse_str; use compiler_tools::TokenParse; +use compiler_tools::util::parse_str; use compiler_tools_derive::token_parse; use std::fmt::Write; diff --git a/klickhouse/src/types/deserialize/array.rs b/klickhouse/src/types/deserialize/array.rs index 3400341..84386ad 100644 --- a/klickhouse/src/types/deserialize/array.rs +++ b/klickhouse/src/types/deserialize/array.rs @@ -1,6 +1,6 @@ use tokio::io::AsyncReadExt; -use crate::{io::ClickhouseRead, values::Value, Result}; +use crate::{Result, io::ClickhouseRead, values::Value}; use super::{Deserializer, DeserializerState, Type}; diff --git a/klickhouse/src/types/deserialize/geo.rs b/klickhouse/src/types/deserialize/geo.rs index d5f150d..7c0a2ed 100644 --- a/klickhouse/src/types/deserialize/geo.rs +++ b/klickhouse/src/types/deserialize/geo.rs @@ -1,4 +1,4 @@ -use crate::{io::ClickhouseRead, values::Value, Result}; +use crate::{Result, io::ClickhouseRead, values::Value}; use super::{Deserializer, DeserializerState, Type}; diff --git a/klickhouse/src/types/deserialize/low_cardinality.rs b/klickhouse/src/types/deserialize/low_cardinality.rs index 2026766..e3986c8 100644 --- a/klickhouse/src/types/deserialize/low_cardinality.rs +++ b/klickhouse/src/types/deserialize/low_cardinality.rs @@ -1,6 +1,6 @@ use tokio::io::AsyncReadExt; -use crate::{io::ClickhouseRead, values::Value, KlickhouseError, Result}; +use crate::{KlickhouseError, Result, io::ClickhouseRead, values::Value}; use super::{Deserializer, DeserializerState, Type}; @@ -62,7 +62,7 @@ impl Deserializer for LowCardinalityDeserializer { x => { return Err(KlickhouseError::DeserializeError(format!( "LowCardinality: bad index type: {x}" - ))) + ))); } }; diff --git a/klickhouse/src/types/deserialize/map.rs b/klickhouse/src/types/deserialize/map.rs index 50976b7..e8d83a4 100644 --- a/klickhouse/src/types/deserialize/map.rs +++ b/klickhouse/src/types/deserialize/map.rs @@ -1,7 +1,7 @@ use tokio::io::AsyncReadExt; use crate::{ - io::ClickhouseRead, protocol::MAX_STRING_SIZE, values::Value, KlickhouseError, Result, + KlickhouseError, Result, io::ClickhouseRead, protocol::MAX_STRING_SIZE, values::Value, }; use super::{Deserializer, DeserializerState, Type}; diff --git a/klickhouse/src/types/deserialize/nullable.rs b/klickhouse/src/types/deserialize/nullable.rs index c73fa67..c8b4723 100644 --- a/klickhouse/src/types/deserialize/nullable.rs +++ b/klickhouse/src/types/deserialize/nullable.rs @@ -1,6 +1,6 @@ use tokio::io::AsyncReadExt; -use crate::{io::ClickhouseRead, values::Value, Result}; +use crate::{Result, io::ClickhouseRead, values::Value}; use super::{Deserializer, DeserializerState, Type}; diff --git a/klickhouse/src/types/deserialize/sized.rs b/klickhouse/src/types/deserialize/sized.rs index 3d09ce6..cc5e329 100644 --- a/klickhouse/src/types/deserialize/sized.rs +++ b/klickhouse/src/types/deserialize/sized.rs @@ -4,8 +4,8 @@ use tokio::io::AsyncReadExt; use uuid::Uuid; use crate::{ - deserialize_bf16_from_bits, i256, io::ClickhouseRead, u256, values::Value, Date, DateTime, - DynDateTime64, Result, + Date, DateTime, DynDateTime64, Result, deserialize_bf16_from_bits, i256, io::ClickhouseRead, + u256, values::Value, }; use super::{Deserializer, DeserializerState, Type}; diff --git a/klickhouse/src/types/deserialize/string.rs b/klickhouse/src/types/deserialize/string.rs index 29ea4c6..669f0b4 100644 --- a/klickhouse/src/types/deserialize/string.rs +++ b/klickhouse/src/types/deserialize/string.rs @@ -1,6 +1,6 @@ use tokio::io::AsyncReadExt; -use crate::{io::ClickhouseRead, values::Value, Result}; +use crate::{Result, io::ClickhouseRead, values::Value}; use super::{Deserializer, DeserializerState, Type}; diff --git a/klickhouse/src/types/deserialize/tuple.rs b/klickhouse/src/types/deserialize/tuple.rs index a2712ce..6ce9699 100644 --- a/klickhouse/src/types/deserialize/tuple.rs +++ b/klickhouse/src/types/deserialize/tuple.rs @@ -1,4 +1,4 @@ -use crate::{io::ClickhouseRead, values::Value, Result}; +use crate::{Result, io::ClickhouseRead, values::Value}; use super::{Deserializer, DeserializerState, Type}; diff --git a/klickhouse/src/types/mod.rs b/klickhouse/src/types/mod.rs index 5d3417a..bf40ac6 100644 --- a/klickhouse/src/types/mod.rs +++ b/klickhouse/src/types/mod.rs @@ -12,13 +12,12 @@ mod serialize; mod tests; use crate::{ - default_bf16_value, i256, + Date, DateTime, DynDateTime64, Ipv4, Ipv6, KlickhouseError, Result, default_bf16_value, i256, io::{ClickhouseRead, ClickhouseWrite}, is_bfloat16_enabled, protocol::MAX_STRING_SIZE, u256, values::Value, - Date, DateTime, DynDateTime64, Ipv4, Ipv6, KlickhouseError, Result, }; /// A raw Clickhouse type. @@ -487,7 +486,7 @@ impl FromStr for Type { _ => { return Err(KlickhouseError::TypeParseError(format!( "invalid type with arguments: '{ident}'" - ))) + ))); } }); } @@ -526,7 +525,7 @@ impl FromStr for Type { _ => { return Err(KlickhouseError::TypeParseError(format!( "invalid type name: '{ident}'" - ))) + ))); } }) } @@ -890,7 +889,10 @@ impl Type { } Type::DateTime64(precision, _) | Type::Decimal64(precision) => { if *precision == 0 || *precision > 18 { - return Err(KlickhouseError::TypeParseError(format!("precision out of bounds for Decimal64/DateTime64({}) must be in range (1..=18)", *precision))); + return Err(KlickhouseError::TypeParseError(format!( + "precision out of bounds for Decimal64/DateTime64({}) must be in range (1..=18)", + *precision + ))); } } Type::Decimal128(precision) => { @@ -931,7 +933,7 @@ impl Type { _ => { return Err(KlickhouseError::TypeParseError(format!( "illegal type '{inner:?}' in LowCardinality, not allowed" - ))) + ))); } }, Type::Array(inner) => { diff --git a/klickhouse/src/types/serialize/array.rs b/klickhouse/src/types/serialize/array.rs index 1108a41..5ea47dc 100644 --- a/klickhouse/src/types/serialize/array.rs +++ b/klickhouse/src/types/serialize/array.rs @@ -1,6 +1,6 @@ use tokio::io::AsyncWriteExt; -use crate::{io::ClickhouseWrite, values::Value, Result}; +use crate::{Result, io::ClickhouseWrite, values::Value}; use super::{Serializer, SerializerState, Type}; diff --git a/klickhouse/src/types/serialize/geo.rs b/klickhouse/src/types/serialize/geo.rs index b93b8bb..578958c 100644 --- a/klickhouse/src/types/serialize/geo.rs +++ b/klickhouse/src/types/serialize/geo.rs @@ -1,4 +1,4 @@ -use crate::{io::ClickhouseWrite, values::Value, Result}; +use crate::{Result, io::ClickhouseWrite, values::Value}; use super::{Serializer, SerializerState, Type}; diff --git a/klickhouse/src/types/serialize/low_cardinality.rs b/klickhouse/src/types/serialize/low_cardinality.rs index b5f39a9..29b49e6 100644 --- a/klickhouse/src/types/serialize/low_cardinality.rs +++ b/klickhouse/src/types/serialize/low_cardinality.rs @@ -1,7 +1,7 @@ use indexmap::IndexSet; use tokio::io::AsyncWriteExt; -use crate::{io::ClickhouseWrite, values::Value, Result}; +use crate::{Result, io::ClickhouseWrite, values::Value}; use super::{Serializer, SerializerState, Type}; diff --git a/klickhouse/src/types/serialize/map.rs b/klickhouse/src/types/serialize/map.rs index 4e1a1d3..daf792a 100644 --- a/klickhouse/src/types/serialize/map.rs +++ b/klickhouse/src/types/serialize/map.rs @@ -1,6 +1,6 @@ use tokio::io::AsyncWriteExt; -use crate::{io::ClickhouseWrite, values::Value, Result}; +use crate::{Result, io::ClickhouseWrite, values::Value}; use super::{Serializer, SerializerState, Type}; diff --git a/klickhouse/src/types/serialize/nullable.rs b/klickhouse/src/types/serialize/nullable.rs index 766e13f..b2b6e76 100644 --- a/klickhouse/src/types/serialize/nullable.rs +++ b/klickhouse/src/types/serialize/nullable.rs @@ -1,6 +1,6 @@ use tokio::io::AsyncWriteExt; -use crate::{io::ClickhouseWrite, values::Value, Result}; +use crate::{Result, io::ClickhouseWrite, values::Value}; use super::{Serializer, SerializerState, Type}; pub struct NullableSerializer; diff --git a/klickhouse/src/types/serialize/sized.rs b/klickhouse/src/types/serialize/sized.rs index 85fd23f..9a48fa5 100644 --- a/klickhouse/src/types/serialize/sized.rs +++ b/klickhouse/src/types/serialize/sized.rs @@ -1,6 +1,6 @@ use tokio::io::AsyncWriteExt; -use crate::{io::ClickhouseWrite, serialize_bf16_to_bits, values::Value, Result}; +use crate::{Result, io::ClickhouseWrite, serialize_bf16_to_bits, values::Value}; use super::{Serializer, SerializerState, Type}; diff --git a/klickhouse/src/types/serialize/string.rs b/klickhouse/src/types/serialize/string.rs index 6a3e7c1..8d35890 100644 --- a/klickhouse/src/types/serialize/string.rs +++ b/klickhouse/src/types/serialize/string.rs @@ -1,6 +1,6 @@ use tokio::io::AsyncWriteExt; -use crate::{io::ClickhouseWrite, values::Value, Result}; +use crate::{Result, io::ClickhouseWrite, values::Value}; use super::{Serializer, SerializerState, Type}; diff --git a/klickhouse/src/types/serialize/tuple.rs b/klickhouse/src/types/serialize/tuple.rs index d966b99..c0eea48 100644 --- a/klickhouse/src/types/serialize/tuple.rs +++ b/klickhouse/src/types/serialize/tuple.rs @@ -1,4 +1,4 @@ -use crate::{io::ClickhouseWrite, values::Value, Result}; +use crate::{Result, io::ClickhouseWrite, values::Value}; use super::{Serializer, SerializerState, Type}; diff --git a/klickhouse/src/types/tests.rs b/klickhouse/src/types/tests.rs index 14693d6..13aa22a 100644 --- a/klickhouse/src/types/tests.rs +++ b/klickhouse/src/types/tests.rs @@ -2,11 +2,10 @@ use std::io::Cursor; use crate::Result; use crate::{ - i256, + Date, DateTime, DynDateTime64, i256, types::{DeserializerState, SerializerState}, u256, values::{self, Value}, - Date, DateTime, DynDateTime64, }; #[cfg(feature = "bfloat16")] use half::bf16; diff --git a/klickhouse/src/values/bfloat16.rs b/klickhouse/src/values/bfloat16.rs index fc21d5b..be0bc93 100644 --- a/klickhouse/src/values/bfloat16.rs +++ b/klickhouse/src/values/bfloat16.rs @@ -78,7 +78,9 @@ pub fn deserialize_bf16_from_bits(bits: u16) -> Value { /// Error stub for deserialization when feature is disabled #[cfg(not(feature = "bfloat16"))] pub fn deserialize_bf16_from_bits(_bits: u16) -> Value { - panic!("BFloat16 support is disabled. Enable the 'bfloat16' feature to deserialize BFloat16 values.") + panic!( + "BFloat16 support is disabled. Enable the 'bfloat16' feature to deserialize BFloat16 values." + ) } /// Serializes BFloat16 to bits when feature is enabled diff --git a/klickhouse/src/values/bytes.rs b/klickhouse/src/values/bytes.rs index d9ddd21..47e5979 100644 --- a/klickhouse/src/values/bytes.rs +++ b/klickhouse/src/values/bytes.rs @@ -1,6 +1,6 @@ use std::ops::{Deref, DerefMut}; -use crate::{unexpected_type, FromSql, Result, ToSql, Type, Value}; +use crate::{FromSql, Result, ToSql, Type, Value, unexpected_type}; /// Wrapper over Vec to allow more efficient serialization/deserialization of raw bytes /// The corresponding Clickhouse type here is String or FixedString, not Array(UInt8). diff --git a/klickhouse/src/values/clickhouse_uuid.rs b/klickhouse/src/values/clickhouse_uuid.rs index 440851e..2ca434d 100644 --- a/klickhouse/src/values/clickhouse_uuid.rs +++ b/klickhouse/src/values/clickhouse_uuid.rs @@ -1,10 +1,10 @@ use crate::{ - convert::{unexpected_type, FromSql}, - types::Type, Result, Uuid, + convert::{FromSql, unexpected_type}, + types::Type, }; -use crate::{convert::ToSql, Value}; +use crate::{Value, convert::ToSql}; impl ToSql for Uuid { fn to_sql(self, _type_hint: Option<&Type>) -> Result { diff --git a/klickhouse/src/values/date.rs b/klickhouse/src/values/date.rs index a1ff46b..9efad0b 100644 --- a/klickhouse/src/values/date.rs +++ b/klickhouse/src/values/date.rs @@ -4,9 +4,9 @@ use chrono::{Duration, FixedOffset, NaiveDate, ParseError, TimeZone, Utc}; use chrono_tz::{Tz, UTC}; use crate::{ - convert::{unexpected_type, FromSql, ToSql}, - types::Type, KlickhouseError, Result, Value, + convert::{FromSql, ToSql, unexpected_type}, + types::Type, }; /// Wrapper type for Clickhouse `Date` type. diff --git a/klickhouse/src/values/decimal.rs b/klickhouse/src/values/decimal.rs index b286e86..b96f464 100644 --- a/klickhouse/src/values/decimal.rs +++ b/klickhouse/src/values/decimal.rs @@ -1,6 +1,6 @@ use rust_decimal::Decimal; -use crate::{unexpected_type, FromSql, KlickhouseError, Result, ToSql, Type, Value}; +use crate::{FromSql, KlickhouseError, Result, ToSql, Type, Value, unexpected_type}; impl FromSql for Decimal { fn from_sql(type_: &Type, value: Value) -> Result { diff --git a/klickhouse/src/values/fixed_point.rs b/klickhouse/src/values/fixed_point.rs index 0f90819..97914bb 100644 --- a/klickhouse/src/values/fixed_point.rs +++ b/klickhouse/src/values/fixed_point.rs @@ -1,8 +1,8 @@ use crate::{ - convert::{unexpected_type, FromSql, ToSql}, + Result, Value, + convert::{FromSql, ToSql, unexpected_type}, i256, types::Type, - Result, Value, }; /// Wrapper type for Clickhouse `FixedPoint32` type. diff --git a/klickhouse/src/values/int256.rs b/klickhouse/src/values/int256.rs index fad2d91..334aa1e 100644 --- a/klickhouse/src/values/int256.rs +++ b/klickhouse/src/values/int256.rs @@ -1,9 +1,9 @@ use std::fmt; use crate::{ - convert::{unexpected_type, FromSql, ToSql}, - types::Type, Result, Value, + convert::{FromSql, ToSql, unexpected_type}, + types::Type, }; /// Wrapper type for Clickhouse `Int256` type. diff --git a/klickhouse/src/values/mod.rs b/klickhouse/src/values/mod.rs index 5aedf4d..efc9d10 100644 --- a/klickhouse/src/values/mod.rs +++ b/klickhouse/src/values/mod.rs @@ -4,9 +4,9 @@ use chrono::{NaiveDate, SecondsFormat}; use chrono_tz::Tz; use crate::{ - convert::{unexpected_type, FromSql, ToSql}, - types::Type, Result, + convert::{FromSql, ToSql, unexpected_type}, + types::Type, }; mod bfloat16; diff --git a/klickhouse/src/values/tests.rs b/klickhouse/src/values/tests.rs index ac91952..db41f5b 100644 --- a/klickhouse/src/values/tests.rs +++ b/klickhouse/src/values/tests.rs @@ -5,11 +5,12 @@ use indexmap::IndexMap; use uuid::Uuid; use crate::{ + Date, DateTime, DateTime64, FixedPoint32, FixedPoint64, FixedPoint128, FixedPoint256, + MultiPolygon, Point, Polygon, Ring, convert::{FromSql, ToSql}, i256, types::Type, - u256, Date, DateTime, DateTime64, FixedPoint128, FixedPoint256, FixedPoint32, FixedPoint64, - MultiPolygon, Point, Polygon, Ring, + u256, }; use super::Value; diff --git a/klickhouse/tests/test.rs b/klickhouse/tests/test.rs index 907e088..6fbaf4a 100644 --- a/klickhouse/tests/test.rs +++ b/klickhouse/tests/test.rs @@ -4,8 +4,8 @@ use std::net::{Ipv4Addr, Ipv6Addr}; use half::bf16; use indexmap::IndexMap; use klickhouse::{ - i256, u256, Date, DateTime, DateTime64, FixedPoint128, FixedPoint256, FixedPoint32, - FixedPoint64, Ipv4, Ipv6, Uuid, + Date, DateTime, DateTime64, FixedPoint32, FixedPoint64, FixedPoint128, FixedPoint256, Ipv4, + Ipv6, Uuid, i256, u256, }; #[derive(klickhouse::Row, Debug, Default, PartialEq, Clone)] diff --git a/klickhouse/tests/test_flatten.rs b/klickhouse/tests/test_flatten.rs index 097fad7..8086a2b 100644 --- a/klickhouse/tests/test_flatten.rs +++ b/klickhouse/tests/test_flatten.rs @@ -20,11 +20,13 @@ async fn test_client() { .filter_level(log::LevelFilter::Info) .try_init(); - assert!(TestRow::column_names() - .unwrap() - .into_iter() - .zip(["field", "a", "b"]) - .all(|(x, y)| x == y)); + assert!( + TestRow::column_names() + .unwrap() + .into_iter() + .zip(["field", "a", "b"]) + .all(|(x, y)| x == y) + ); let client = super::get_client().await; diff --git a/klickhouse/tests/test_lock.rs b/klickhouse/tests/test_lock.rs index fb15e52..cfe8f53 100644 --- a/klickhouse/tests/test_lock.rs +++ b/klickhouse/tests/test_lock.rs @@ -15,9 +15,11 @@ async fn test_client() { println!("lock1 locked"); let lock2 = ClickhouseLock::new(client2.clone(), "test"); - assert!(tokio::time::timeout(Duration::from_secs(1), lock2.lock()) - .await - .is_err()); + assert!( + tokio::time::timeout(Duration::from_secs(1), lock2.lock()) + .await + .is_err() + ); println!("lock1 unlocking"); tokio::time::sleep(Duration::from_secs(1)).await; diff --git a/klickhouse_derive/Cargo.toml b/klickhouse_derive/Cargo.toml index 1556c1e..f44565b 100644 --- a/klickhouse_derive/Cargo.toml +++ b/klickhouse_derive/Cargo.toml @@ -2,12 +2,12 @@ name = "klickhouse_derive" version = "0.13.0" authors = ["Protryon "] -edition = "2021" +edition = "2024" license = "MIT OR Apache-2.0" repository = "https://github.com/Protryon/klickhouse" description = "proc-macro crate for klickhouse" keywords = [ "clickhouse", "database", "tokio", "sql" ] -rust-version = "1.75.0" +rust-version = "1.85.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/klickhouse_derive/src/ast.rs b/klickhouse_derive/src/ast.rs index 65e0e20..c8f9116 100644 --- a/klickhouse_derive/src/ast.rs +++ b/klickhouse_derive/src/ast.rs @@ -1,8 +1,8 @@ use crate::{attr, check}; // use crate::check; use crate::ctxt::Ctxt; -use syn::punctuated::Punctuated; use syn::Token; +use syn::punctuated::Punctuated; /// A source data structure annotated with `#[derive(Serialize)]` and/or `#[derive(Deserialize)]`, /// parsed into an internal representation. diff --git a/klickhouse_derive/src/receiver.rs b/klickhouse_derive/src/receiver.rs index f1baa1d..8f94162 100644 --- a/klickhouse_derive/src/receiver.rs +++ b/klickhouse_derive/src/receiver.rs @@ -3,8 +3,8 @@ use proc_macro2::Span; use quote::ToTokens; use std::mem; use syn::{ - parse_quote, Data, DeriveInput, Expr, ExprPath, GenericArgument, GenericParam, Generics, Macro, - Path, PathArguments, QSelf, ReturnType, Type, TypeParamBound, TypePath, WherePredicate, + Data, DeriveInput, Expr, ExprPath, GenericArgument, GenericParam, Generics, Macro, Path, + PathArguments, QSelf, ReturnType, Type, TypeParamBound, TypePath, WherePredicate, parse_quote, }; pub fn replace_receiver(input: &mut DeriveInput) {