From a873ec470944ca94130ed6f749f8591ae26883ab Mon Sep 17 00:00:00 2001 From: Chojan Shang Date: Wed, 17 Aug 2022 10:20:23 +0800 Subject: [PATCH] *: prepare for 0.2.0 (#28) * chore: apply clippy suggestions * docs: update examples * chore: apply clippy suggestion * chore: bump version to v0.2.0 --- clickhouse/Cargo.toml | 4 ++-- clickhouse/README.md | 30 +++--------------------------- clickhouse/src/types/column/mod.rs | 2 +- clickhouse/src/types/options.rs | 3 +++ clickhouse/src/types/value_ref.rs | 2 +- components/micromarshal/Cargo.toml | 2 +- components/micromarshal/README.md | 4 ++++ mysql/README.md | 12 +++++++----- mysql/src/packet_reader.rs | 2 +- mysql/src/value/encode.rs | 4 ++-- 10 files changed, 25 insertions(+), 40 deletions(-) diff --git a/clickhouse/Cargo.toml b/clickhouse/Cargo.toml index 667292e..202cc93 100644 --- a/clickhouse/Cargo.toml +++ b/clickhouse/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "opensrv-clickhouse" -version = "0.1.0" +version = "0.2.0" authors = ["Databend Authors "] edition = "2021" license = "Apache-2.0" @@ -26,7 +26,7 @@ chrono-tz = "0.6.1" combine = "4.6.3" hostname = "0.3.1" lz4 = "1.23.2" -micromarshal = "0.1.0" +micromarshal = { version = "0.2.0" , path = "../components/micromarshal"} naive-cityhash = "0.2.0" once_cell = "1.9.0" thiserror = "1.0.30" diff --git a/clickhouse/README.md b/clickhouse/README.md index 7ac75c1..f2e5891 100644 --- a/clickhouse/README.md +++ b/clickhouse/README.md @@ -9,6 +9,7 @@ See the full example [here](./examples/simple.rs) ```rust struct Session { last_progress_send: Instant, + metadata: ClickHouseMetadata, } #[async_trait::async_trait] @@ -72,33 +73,8 @@ impl opensrv_clickhouse::ClickHouseSession for Session { Ok(()) } - fn dbms_name(&self) -> &str { - "ClickHouse-X" - } - - fn dbms_version_major(&self) -> u64 { - 2021 - } - - fn dbms_version_minor(&self) -> u64 { - 5 - } - - // the MIN_SERVER_REVISION for suggestions is 54406 - fn dbms_tcp_protocol_version(&self) -> u64 { - 54405 - } - - fn timezone(&self) -> &str { - "UTC" - } - - fn server_display_name(&self) -> &str { - "ClickHouse-X" - } - - fn dbms_version_patch(&self) -> u64 { - 0 + fn metadata(&self) -> &ClickHouseMetadata { + &self.metadata } fn get_progress(&self) -> Progress { diff --git a/clickhouse/src/types/column/mod.rs b/clickhouse/src/types/column/mod.rs index a0ad0a5..df66739 100644 --- a/clickhouse/src/types/column/mod.rs +++ b/clickhouse/src/types/column/mod.rs @@ -488,7 +488,7 @@ pub fn new_column( } } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq)] pub enum Either where L: fmt::Debug + PartialEq + Clone, diff --git a/clickhouse/src/types/options.rs b/clickhouse/src/types/options.rs index c493710..2942b1b 100644 --- a/clickhouse/src/types/options.rs +++ b/clickhouse/src/types/options.rs @@ -161,6 +161,9 @@ impl convert::From for native_tls::Certificate { } /// Clickhouse connection options. +// the trait `std::cmp::Eq` is not implemented for `types::options::Certificate` +// so we can't use `derive(Eq)` in tls feature. +#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq)] pub struct Options { /// Address of clickhouse server (defaults to `127.0.0.1:9000`). diff --git a/clickhouse/src/types/value_ref.rs b/clickhouse/src/types/value_ref.rs index c6acdc6..5ee40f7 100644 --- a/clickhouse/src/types/value_ref.rs +++ b/clickhouse/src/types/value_ref.rs @@ -370,7 +370,7 @@ impl<'a> From<&'a Value> for ValueRef<'a> { let value_ref: ValueRef<'a> = From::from(v); ref_vec.push(value_ref) } - ValueRef::Array(*t, Arc::new(ref_vec)) + ValueRef::Array(t, Arc::new(ref_vec)) } Value::Decimal(v) => ValueRef::Decimal(v.clone()), Value::Enum8(values, v) => ValueRef::Enum8(values.to_vec(), *v), diff --git a/components/micromarshal/Cargo.toml b/components/micromarshal/Cargo.toml index f682dbd..aa89059 100644 --- a/components/micromarshal/Cargo.toml +++ b/components/micromarshal/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "micromarshal" -version = "0.1.0" +version = "0.2.0" authors = ["Databend Authors "] edition = "2021" license = "Apache-2.0" diff --git a/components/micromarshal/README.md b/components/micromarshal/README.md index 7d908b2..64f03c6 100644 --- a/components/micromarshal/README.md +++ b/components/micromarshal/README.md @@ -6,6 +6,10 @@ Submit [issues](https://github.com/datafuselabs/opensrv/issues/new/choose) for bug report or asking questions in [discussion](https://github.com/datafuselabs/opensrv/discussions/new?category=q-a). +## Tips + +As the functionality of this crate is largely stable, its version will mostly just change as other crates change. + ## Credits This project is extracted from the Databend's common-io module. Now released as a separate crate. diff --git a/mysql/README.md b/mysql/README.md index ead2102..c3cd984 100644 --- a/mysql/README.md +++ b/mysql/README.md @@ -18,6 +18,7 @@ all commands with a "no results" reply: ```rust use std::io; +use tokio::io::AsyncWrite; use opensrv_mysql::*; use tokio::net::TcpListener; @@ -25,7 +26,7 @@ use tokio::net::TcpListener; struct Backend; #[async_trait::async_trait] -impl AsyncMysqlShim for Backend { +impl AsyncMysqlShim for Backend { type Error = io::Error; async fn on_prepare<'a>( @@ -33,7 +34,7 @@ impl AsyncMysqlShim for Backend { _: &'a str, info: StatementMetaWriter<'a, W>, ) -> io::Result<()> { - info.reply(42, &[], &[]) + info.reply(42, &[], &[]).await } async fn on_execute<'a>( @@ -42,7 +43,7 @@ impl AsyncMysqlShim for Backend { _: opensrv_mysql::ParamParser<'a>, results: QueryResultWriter<'a, W>, ) -> io::Result<()> { - results.completed(OkResponse::default()) + results.completed(OkResponse::default()).await } async fn on_close(&mut self, _: u32) {} @@ -53,7 +54,7 @@ impl AsyncMysqlShim for Backend { results: QueryResultWriter<'a, W>, ) -> io::Result<()> { println!("execute sql {:?}", sql); - results.start(&[])?.finish() + results.start(&[]).await?.finish().await } } @@ -63,7 +64,8 @@ async fn main() -> Result<(), Box> { loop { let (stream, _) = listener.accept().await?; - tokio::spawn(async move { AsyncMysqlIntermediary::run_on(Backend, stream).await }); + let (r, w) = stream.into_split(); + tokio::spawn(async move { AsyncMysqlIntermediary::run_on(Backend, r, w).await }); } } ``` diff --git a/mysql/src/packet_reader.rs b/mysql/src/packet_reader.rs index da24859..4f1089a 100644 --- a/mysql/src/packet_reader.rs +++ b/mysql/src/packet_reader.rs @@ -191,7 +191,7 @@ impl<'a> AsRef<[u8]> for Packet<'a> { if self.1.is_empty() { self.0 } else { - &*self.1 + &self.1 } } } diff --git a/mysql/src/value/encode.rs b/mysql/src/value/encode.rs index c827dd4..8c45d75 100644 --- a/mysql/src/value/encode.rs +++ b/mysql/src/value/encode.rs @@ -409,10 +409,10 @@ impl ToMysqlValue for [u8] { impl ToMysqlValue for Vec { fn to_mysql_text(&self, w: &mut W) -> io::Result<()> { - (&self[..]).to_mysql_text(w) + (self[..]).to_mysql_text(w) } fn to_mysql_bin(&self, w: &mut W, c: &Column) -> io::Result<()> { - (&self[..]).to_mysql_bin(w, c) + (self[..]).to_mysql_bin(w, c) } }